| 1 |
// |
| 2 |
// Copyright (c) 2016-2022 The Aurora Authors. All rights reserved. |
| 3 |
// This program is free software. It comes without any warranty, |
| 4 |
// to the extent permitted by applicable law. You can redistribute |
| 5 |
// it and/or modify it under the terms of the Unlicense. See LICENSE |
| 6 |
// file for more details or see below. |
| 7 |
// |
| 8 |
|
| 9 |
// |
| 10 |
// This is free and unencumbered software released into the public domain. |
| 11 |
// |
| 12 |
// Anyone is free to copy, modify, publish, use, compile, sell, or |
| 13 |
// distribute this software, either in source code form or as a compiled |
| 14 |
// binary, for any purpose, commercial or non-commercial, and by any |
| 15 |
// means. |
| 16 |
// |
| 17 |
// In jurisdictions that recognize copyright laws, the author or authors |
| 18 |
// of this software dedicate any and all copyright interest in the |
| 19 |
// software to the public domain. We make this dedication for the benefit |
| 20 |
// of the public at large and to the detriment of our heirs and |
| 21 |
// successors. We intend this dedication to be an overt act of |
| 22 |
// relinquishment in perpetuity of all present and future rights to this |
| 23 |
// software under copyright law. |
| 24 |
// |
| 25 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 28 |
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 29 |
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 30 |
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 31 |
// OTHER DEALINGS IN THE SOFTWARE. |
| 32 |
// |
| 33 |
// For more information, please refer to <http://unlicense.org/> |
| 34 |
// |
| 35 |
|
| 36 |
package aurora |
| 37 |
|
| 38 |
import ( |
| 39 |
"fmt" |
| 40 |
"testing" |
| 41 |
|
| 42 |
"github.com/stretchr/testify/assert" |
| 43 |
) |
| 44 |
|
| 45 |
func TestValue_String(t *testing.T) { |
| 46 |
var au *Aurora |
| 47 |
// colorized |
| 48 |
au = New() |
| 49 |
assert.Equal(t, "x", au.Clear("x").String()) |
| 50 |
assert.Equal(t, "\033[30;41mx\033[0m", au.Black("x").BgRed().String()) |
| 51 |
// clear |
| 52 |
au = New(WithColors(false)) |
| 53 |
assert.Equal(t, "x", au.Black("x").BgRed().String()) |
| 54 |
// colorized hyperlink |
| 55 |
au = New() |
| 56 |
assert.Equal(t, `]8;;http://example.com`+ |
| 57 |
`\[31mx[0m]8;;\`, |
| 58 |
au.Red("x").Hyperlink("http://example.com").String()) |
| 59 |
// clear hyperlink |
| 60 |
assert.Equal(t, `]8;;http://example.com\x]8;;\`, |
| 61 |
au.Clear("x").Hyperlink("http://example.com").String()) |
| 62 |
} |
| 63 |
|
| 64 |
func TestValue_Color(t *testing.T) { |
| 65 |
// colorized |
| 66 |
assert.Equal(t, RedFg, New().Red("x").Color()) |
| 67 |
// clear, also red |
| 68 |
assert.Equal(t, RedFg, New().Red("x").Color()) |
| 69 |
} |
| 70 |
|
| 71 |
func TestValue_Value(t *testing.T) { |
| 72 |
// colorized |
| 73 |
assert.Equal(t, "x", New().Clear("x").Value()) |
| 74 |
// clear |
| 75 |
assert.Equal(t, "x", New(WithColors(false)).Black("x").BgRed().Value()) |
| 76 |
} |
| 77 |
|
| 78 |
func TestValue_Reset(t *testing.T) { |
| 79 |
// colorized |
| 80 |
var au = New() |
| 81 |
assert.Equal(t, Value{ |
| 82 |
cc: au.cc, |
| 83 |
value: "x", |
| 84 |
}, au.Red("x").BgBlack().Reset()) |
| 85 |
// clear |
| 86 |
au = New(WithColors(false)) |
| 87 |
assert.Equal(t, Value{ |
| 88 |
cc: au.cc, |
| 89 |
value: "x", |
| 90 |
}, au.Red("x").BgBlack().Reset()) |
| 91 |
// a hyperlink |
| 92 |
au = New() |
| 93 |
assert.Equal(t, |
| 94 |
Value{ |
| 95 |
cc: au.cc, |
| 96 |
value: "x", |
| 97 |
}, au.Red("x"). |
| 98 |
BgBlack(). |
| 99 |
Hyperlink("http://example.com/path", HyperlinkID("10")). |
| 100 |
Reset()) |
| 101 |
} |
| 102 |
|
| 103 |
func TestValue_Clear(t *testing.T) { |
| 104 |
// colorized |
| 105 |
var au = New() |
| 106 |
assert.Equal(t, Value{ |
| 107 |
cc: au.cc, |
| 108 |
value: "x", |
| 109 |
}, au.Red("x").BgBlack().Clear()) |
| 110 |
// clear |
| 111 |
au = New(WithColors(false)) |
| 112 |
assert.Equal(t, Value{ |
| 113 |
cc: au.cc, |
| 114 |
value: "x", |
| 115 |
}, au.Red("x").BgBlack().Clear()) |
| 116 |
// a hyperlink |
| 117 |
au = New() |
| 118 |
assert.EqualValues(t, |
| 119 |
Value{ |
| 120 |
cc: au.cc, |
| 121 |
value: "x", |
| 122 |
hyperlink: &hyperlink{ |
| 123 |
target: "http://example.com/path", |
| 124 |
params: []HyperlinkParam{{ |
| 125 |
Key: HyperlinkIDKey, |
| 126 |
Value: "10", |
| 127 |
}}, |
| 128 |
}, |
| 129 |
}, au.Red("x"). |
| 130 |
BgBlack(). |
| 131 |
Hyperlink("http://example.com/path", HyperlinkID("10")). |
| 132 |
Clear()) |
| 133 |
} |
| 134 |
|
| 135 |
func TestValue_Format(t *testing.T) { |
| 136 |
// colorized |
| 137 |
var au = New() |
| 138 |
assert.Equal(t, "\033[31;44m"+fmt.Sprintf("%+1.3g", 3.14)+"\033[0m", |
| 139 |
fmt.Sprintf("%+1.3g", au.Red(3.14).BgBlue())) |
| 140 |
const utf8Verb = "%+1.3世" // verb that fit more then 1 byte |
| 141 |
assert.Equal(t, "\033[31;44m"+"%!世(float64=+3.14)"+"\033[0m", |
| 142 |
fmt.Sprintf(utf8Verb, au.Red(3.14).BgBlue())) //nolint |
| 143 |
// clear |
| 144 |
au = New(WithColors(false)) |
| 145 |
assert.Equal(t, fmt.Sprintf("%+1.3g", 3.14), |
| 146 |
fmt.Sprintf("%+1.3g", au.Red(3.14).BgBlue())) |
| 147 |
assert.Equal(t, "%!世(float64=+3.14)", |
| 148 |
fmt.Sprintf(utf8Verb, au.Red(3.14).BgBlue())) //nolint |
| 149 |
} |
| 150 |
|
| 151 |
func TestValue_colors(t *testing.T) { |
| 152 |
var test = func(name string, v Value, clr Color) { |
| 153 |
t.Helper() |
| 154 |
assert.Equal(t, clr, v.Color()) |
| 155 |
} |
| 156 |
// colorized |
| 157 |
var au = New() |
| 158 |
test("Reset", au.Reset("x"), 0) |
| 159 |
test("Clear", au.Clear("x"), 0) |
| 160 |
test("Bold", au.Bold("x"), BoldFm) |
| 161 |
test("Faint", au.Faint("x"), FaintFm) |
| 162 |
test("DoublyUnderline", au.DoublyUnderline("x"), DoublyUnderlineFm) |
| 163 |
test("Fraktur & au.Yellow", Yellow(Fraktur("x")), FrakturFm|YellowFg) |
| 164 |
test("Italic", au.Italic("x"), ItalicFm) |
| 165 |
test("Underline", au.Underline("x"), UnderlineFm) |
| 166 |
test("SlowBlink", au.SlowBlink("x"), SlowBlinkFm) |
| 167 |
test("RapidBlink", au.RapidBlink("x"), RapidBlinkFm) |
| 168 |
test("Blink", au.Blink("x"), BlinkFm) |
| 169 |
test("Reverse", au.Reverse("x"), ReverseFm) |
| 170 |
test("Inverse", au.Inverse("x"), InverseFm) |
| 171 |
test("Conceal", au.Conceal("x"), ConcealFm) |
| 172 |
test("Hidden", au.Hidden("x"), HiddenFm) |
| 173 |
test("CrossedOut", au.CrossedOut("x"), CrossedOutFm) |
| 174 |
test("StrikeThrough", au.StrikeThrough("x"), StrikeThroughFm) |
| 175 |
test("Framed", au.Framed("x"), FramedFm) |
| 176 |
test("Encircled", au.Encircled("x"), EncircledFm) |
| 177 |
test("Overlined", au.Overlined("x"), OverlinedFm) |
| 178 |
test("Black", au.Black("x"), BlackFg) |
| 179 |
test("Red", au.Red("x"), RedFg) |
| 180 |
test("Green", au.Green("x"), GreenFg) |
| 181 |
test("Yellow", au.Yellow("x"), YellowFg) |
| 182 |
test("Blue", au.Blue("x"), BlueFg) |
| 183 |
test("Magenta", au.Magenta("x"), MagentaFg) |
| 184 |
test("Cyan", au.Cyan("x"), CyanFg) |
| 185 |
test("White", au.White("x"), WhiteFg) |
| 186 |
test("BrightBlack", au.BrightBlack("x"), BrightFg|BlackFg) |
| 187 |
test("BrightRed", au.BrightRed("x"), BrightFg|RedFg) |
| 188 |
test("BrightGreen", au.BrightGreen("x"), BrightFg|GreenFg) |
| 189 |
test("BrightYellow", au.BrightYellow("x"), BrightFg|YellowFg) |
| 190 |
test("BrightBlue", au.BrightBlue("x"), BrightFg|BlueFg) |
| 191 |
test("BrightMagenta", au.BrightMagenta("x"), BrightFg|MagentaFg) |
| 192 |
test("BrightCyan", au.BrightCyan("x"), BrightFg|CyanFg) |
| 193 |
test("BrightWhite", au.BrightWhite("x"), BrightFg|WhiteFg) |
| 194 |
test("Index", au.Index(178, "x"), (Color(178)<<shiftFg)|flagFg) |
| 195 |
test("Gray", au.Gray(14, "x"), (Color(14+232)<<shiftFg)|flagFg) |
| 196 |
test("BgBlack", au.BgBlack("x"), BlackBg) |
| 197 |
test("BgRed", au.BgRed("x"), RedBg) |
| 198 |
test("BgGreen", au.BgGreen("x"), GreenBg) |
| 199 |
test("BgYellow", au.BgYellow("x"), YellowBg) |
| 200 |
test("BgBlue", au.BgBlue("x"), BlueBg) |
| 201 |
test("BgMagenta", au.BgMagenta("x"), MagentaBg) |
| 202 |
test("BgCyan", au.BgCyan("x"), CyanBg) |
| 203 |
test("BgWhite", au.BgWhite("x"), WhiteBg) |
| 204 |
test("BgBrightBlack", au.BgBrightBlack("x"), BrightBg|BlackBg) |
| 205 |
test("BgBrightRed", au.BgBrightRed("x"), BrightBg|RedBg) |
| 206 |
test("BgBrightGreen", au.BgBrightGreen("x"), BrightBg|GreenBg) |
| 207 |
test("BgBrightYellow", au.BgBrightYellow("x"), BrightBg|YellowBg) |
| 208 |
test("BgBrightBlue", au.BgBrightBlue("x"), BrightBg|BlueBg) |
| 209 |
test("BgBrightMagenta", au.BgBrightMagenta("x"), BrightBg|MagentaBg) |
| 210 |
test("BgBrightCyan", au.BgBrightCyan("x"), BrightBg|CyanBg) |
| 211 |
test("BgBrightWhite", au.BgBrightWhite("x"), BrightBg|WhiteBg) |
| 212 |
test("BgIndex", au.BgIndex(187, "x"), Color(187)<<shiftBg|flagBg) |
| 213 |
test("BgGray", au.BgGray(15, "x"), Color(232+15)<<shiftBg|flagBg) |
| 214 |
test("Colorize", au.Colorize("x", RedFg|BlueBg|BrightBg|BoldFm), |
| 215 |
RedFg|BlueBg|BrightBg|BoldFm) |
| 216 |
// clear |
| 217 |
au = New(WithColors(false)) |
| 218 |
test("Reset", au.Clear("x").Reset(), 0) |
| 219 |
test("Clear", au.Bold("x").Clear(), 0) |
| 220 |
test("Bold", au.Clear("x").Bold(), 0) |
| 221 |
test("Faint", au.Clear("x").Faint(), 0) |
| 222 |
test("DoublyUnderline", au.Clear("x").DoublyUnderline(), 0) |
| 223 |
test("Fraktur & Yellow", au.Clear("x").Fraktur(), 0) |
| 224 |
test("Italic", au.Clear("x").Italic(), 0) |
| 225 |
test("Underline", au.Clear("x").Underline(), 0) |
| 226 |
test("SlowBlink", au.Clear("x").SlowBlink(), 0) |
| 227 |
test("RapidBlink", au.Clear("x").RapidBlink(), 0) |
| 228 |
test("Blink", au.Clear("x").Blink(), 0) |
| 229 |
test("Reverse", au.Clear("x").Reverse(), 0) |
| 230 |
test("Inverse", au.Clear("x").Inverse(), 0) |
| 231 |
test("Conceal", au.Clear("x").Conceal(), 0) |
| 232 |
test("Hidden", au.Clear("x").Hidden(), 0) |
| 233 |
test("CrossedOut", au.Clear("x").CrossedOut(), 0) |
| 234 |
test("StrikeThrough", au.Clear("x").StrikeThrough(), 0) |
| 235 |
test("Framed", au.Clear("x").Framed(), 0) |
| 236 |
test("Encircled", au.Clear("x").Encircled(), 0) |
| 237 |
test("Overlined", au.Clear("x").Overlined(), 0) |
| 238 |
test("Black", au.Clear("x").Black(), 0) |
| 239 |
test("Red", au.Clear("x").Red(), 0) |
| 240 |
test("Green", au.Clear("x").Green(), 0) |
| 241 |
test("Yellow", au.Clear("x").Yellow(), 0) |
| 242 |
test("Blue", au.Clear("x").Blue(), 0) |
| 243 |
test("Magenta", au.Clear("x").Magenta(), 0) |
| 244 |
test("Cyan", au.Clear("x").Cyan(), 0) |
| 245 |
test("White", au.Clear("x").White(), 0) |
| 246 |
test("BrightBlack", au.Clear("x").BrightBlack(), 0) |
| 247 |
test("BrightRed", au.Clear("x").BrightRed(), 0) |
| 248 |
test("BrightGreen", au.Clear("x").BrightGreen(), 0) |
| 249 |
test("BrightYellow", au.Clear("x").BrightYellow(), 0) |
| 250 |
test("BrightBlue", au.Clear("x").BrightBlue(), 0) |
| 251 |
test("BrightMagenta", au.Clear("x").BrightMagenta(), 0) |
| 252 |
test("BrightCyan", au.Clear("x").BrightCyan(), 0) |
| 253 |
test("BrightWhite", au.Clear("x").BrightWhite(), 0) |
| 254 |
test("Index", au.Clear("x").Index(178), 0) |
| 255 |
test("Gray", au.Clear("x").Gray(14), 0) |
| 256 |
test("BgBlack", au.Clear("x").BgBlack(), 0) |
| 257 |
test("BgRed", au.Clear("x").BgRed(), 0) |
| 258 |
test("BgGreen", au.Clear("x").BgGreen(), 0) |
| 259 |
test("BgYellow", au.Clear("x").BgYellow(), 0) |
| 260 |
test("BgBlue", au.Clear("x").BgBlue(), 0) |
| 261 |
test("BgMagenta", au.Clear("x").BgMagenta(), 0) |
| 262 |
test("BgCyan", au.Clear("x").BgCyan(), 0) |
| 263 |
test("BgWhite", au.Clear("x").BgWhite(), 0) |
| 264 |
test("BgBrightBlack", au.Clear("x").BgBrightBlack(), 0) |
| 265 |
test("BgBrightRed", au.Clear("x").BgBrightRed(), 0) |
| 266 |
test("BgBrightGreen", au.Clear("x").BgBrightGreen(), 0) |
| 267 |
test("BgBrightYellow", au.Clear("x").BgBrightYellow(), 0) |
| 268 |
test("BgBrightBlue", au.Clear("x").BgBrightBlue(), 0) |
| 269 |
test("BgBrightMagenta", au.Clear("x").BgBrightMagenta(), 0) |
| 270 |
test("BgBrightCyan", au.Clear("x").BgBrightCyan(), 0) |
| 271 |
test("BgBrightWhite", au.Clear("x").BgBrightWhite(), 0) |
| 272 |
test("BgIndex", au.Clear("x").BgIndex(187), 0) |
| 273 |
test("BgGray", au.Clear("x").BgGray(15), 0) |
| 274 |
test("Colorize", au.Clear("x").Colorize(RedFg|BlueBg|BrightBg|BoldFm), 0) |
| 275 |
// change |
| 276 |
au = New() |
| 277 |
test("Reset", au.Bold("x").Reset(), 0) |
| 278 |
test("Clear", au.Bold("x").Clear(), 0) |
| 279 |
test("Bold", au.Faint("x").Bold(), BoldFm) |
| 280 |
test("Faint", au.Bold("x").Faint(), FaintFm) |
| 281 |
test("DoublyUnderline", au.Reset("x").DoublyUnderline(), DoublyUnderlineFm) |
| 282 |
test("Fraktur & Yellow", au.Reset("x").Yellow().Fraktur(), FrakturFm|YellowFg) |
| 283 |
test("Italic", au.Reset("x").Italic(), ItalicFm) |
| 284 |
test("Underline", au.Reset("x").Underline(), UnderlineFm) |
| 285 |
test("SlowBlink", au.RapidBlink("x").SlowBlink(), SlowBlinkFm) |
| 286 |
test("RapidBlink", au.SlowBlink("x").RapidBlink(), RapidBlinkFm) |
| 287 |
test("Blink", au.Reset("x").Blink(), BlinkFm) |
| 288 |
test("Reverse", au.Reset("x").Reverse(), ReverseFm) |
| 289 |
test("Inverse", au.Reset("x").Inverse(), InverseFm) |
| 290 |
test("Conceal", au.Reset("x").Conceal(), ConcealFm) |
| 291 |
test("Hidden", au.Reset("x").Hidden(), HiddenFm) |
| 292 |
test("CrossedOut", au.Reset("x").CrossedOut(), CrossedOutFm) |
| 293 |
test("StrikeThrough", au.Reset("x").StrikeThrough(), StrikeThroughFm) |
| 294 |
test("Framed", au.Reset("x").Framed(), FramedFm) |
| 295 |
test("Encircled", au.Reset("x").Encircled(), EncircledFm) |
| 296 |
test("Overlined", au.Reset("x").Overlined(), OverlinedFm) |
| 297 |
test("Black", au.Reset("x").Black(), BlackFg) |
| 298 |
test("Red", au.Reset("x").Red(), RedFg) |
| 299 |
test("Green", au.Reset("x").Green(), GreenFg) |
| 300 |
test("Yellow", au.Reset("x").Yellow(), YellowFg) |
| 301 |
test("Blue", au.Reset("x").Blue(), BlueFg) |
| 302 |
test("Magenta", au.Reset("x").Magenta(), MagentaFg) |
| 303 |
test("Cyan", au.Reset("x").Cyan(), CyanFg) |
| 304 |
test("White", au.Reset("x").White(), WhiteFg) |
| 305 |
test("BrightBlack", au.Reset("x").BrightBlack(), BrightFg|BlackFg) |
| 306 |
test("BrightRed", au.Reset("x").BrightRed(), BrightFg|RedFg) |
| 307 |
test("BrightGreen", au.Reset("x").BrightGreen(), BrightFg|GreenFg) |
| 308 |
test("BrightYellow", au.Reset("x").BrightYellow(), BrightFg|YellowFg) |
| 309 |
test("BrightBlue", au.Reset("x").BrightBlue(), BrightFg|BlueFg) |
| 310 |
test("BrightMagenta", au.Reset("x").BrightMagenta(), BrightFg|MagentaFg) |
| 311 |
test("BrightCyan", au.Reset("x").BrightCyan(), BrightFg|CyanFg) |
| 312 |
test("BrightWhite", au.Reset("x").BrightWhite(), BrightFg|WhiteFg) |
| 313 |
test("Index", au.Reset("x").Index(178), (Color(178)<<shiftFg)|flagFg) |
| 314 |
test("Gray", au.Reset("x").Gray(14), (Color(14+232)<<shiftFg)|flagFg) |
| 315 |
test("BgBlack", au.Reset("x").BgBlack(), BlackBg) |
| 316 |
test("BgRed", au.Reset("x").BgRed(), RedBg) |
| 317 |
test("BgGreen", au.Reset("x").BgGreen(), GreenBg) |
| 318 |
test("BgYellow", au.Reset("x").BgYellow(), YellowBg) |
| 319 |
test("BgBlue", au.Reset("x").BgBlue(), BlueBg) |
| 320 |
test("BgMagenta", au.Reset("x").BgMagenta(), MagentaBg) |
| 321 |
test("BgCyan", au.Reset("x").BgCyan(), CyanBg) |
| 322 |
test("BgWhite", au.Reset("x").BgWhite(), WhiteBg) |
| 323 |
test("BgBrightBlack", au.Reset("x").BgBrightBlack(), BrightBg|BlackBg) |
| 324 |
test("BgBrightRed", au.Reset("x").BgBrightRed(), BrightBg|RedBg) |
| 325 |
test("BgBrightGreen", au.Reset("x").BgBrightGreen(), BrightBg|GreenBg) |
| 326 |
test("BgBrightYellow", au.Reset("x").BgBrightYellow(), BrightBg|YellowBg) |
| 327 |
test("BgBrightBlue", au.Reset("x").BgBrightBlue(), BrightBg|BlueBg) |
| 328 |
test("BgBrightMagenta", au.Reset("x").BgBrightMagenta(), BrightBg|MagentaBg) |
| 329 |
test("BgBrightCyan", au.Reset("x").BgBrightCyan(), BrightBg|CyanBg) |
| 330 |
test("BgBrightWhite", au.Reset("x").BgBrightWhite(), BrightBg|WhiteBg) |
| 331 |
test("BgIndex", au.Reset("x").BgIndex(187), Color(187)<<shiftBg|flagBg) |
| 332 |
test("BgGray", au.Reset("x").BgGray(15), Color(232+15)<<shiftBg|flagBg) |
| 333 |
test("Colorize", au.Reset("x").Colorize(RedFg|BlueBg|BrightBg|BoldFm), |
| 334 |
RedFg|BlueBg|BrightBg|BoldFm) |
| 335 |
// overflow |
| 336 |
test("Gray", au.Reset("x").Gray(151), Color(232+23)<<shiftFg|flagFg) |
| 337 |
test("BgGray", au.Reset("x").BgGray(115), Color(232+23)<<shiftBg|flagBg) |
| 338 |
} |
| 339 |
|
| 340 |
func TestValue_hyperlinks(t *testing.T) { |
| 341 |
const target = "http://example.com/path?query=value" |
| 342 |
var ( |
| 343 |
au = New() |
| 344 |
params = []HyperlinkParam{ |
| 345 |
{ |
| 346 |
Key: HyperlinkIDKey, |
| 347 |
Value: "10", |
| 348 |
}, |
| 349 |
{ |
| 350 |
Key: "another", |
| 351 |
Value: "custom", |
| 352 |
}, |
| 353 |
} |
| 354 |
val Value |
| 355 |
want string |
| 356 |
) |
| 357 |
val = au.Red("x").Hyperlink(target, HyperlinkID("10"), |
| 358 |
HyperlinkParam{"another", "custom"}) |
| 359 |
assert.Equal(t, target, val.HyperlinkTarget()) |
| 360 |
assert.EqualValues(t, params, val.HyperlinkParams()) |
| 361 |
want = `]8;id=10:another=custom;http://example.com/path?` + |
| 362 |
`query=value\[31mx[0m]8;;\` |
| 363 |
assert.Equal(t, want, val.String()) |
| 364 |
|
| 365 |
// wrap a hyperlink |
| 366 |
au = New(WithHyperlinks(false)) |
| 367 |
want = `[31mhttp://example.com[0m` |
| 368 |
val = au.Red("x").Hyperlink("http://example.com") |
| 369 |
assert.Equal(t, want, val.String()) |
| 370 |
assert.Equal(t, "http://example.com", val.HyperlinkTarget()) |
| 371 |
assert.Equal(t, "http://example.com", val.Value()) |
| 372 |
|
| 373 |
// no target, no parameters |
| 374 |
val = au.Clear("x") |
| 375 |
assert.Equal(t, "", val.HyperlinkTarget()) |
| 376 |
assert.Nil(t, val.HyperlinkParams()) |
| 377 |
} |