-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtermlink_test.go
67 lines (51 loc) · 2.24 KB
/
termlink_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package termlink_test
import (
"testing"
"github.com/savioxavier/termlink"
"github.com/stretchr/testify/assert"
)
func testAll(input, expectedHyperlink, expectedNoHyperlink string) func(t *testing.T) {
return func(t *testing.T) {
if termlink.SupportsHyperlinks() {
assert.Equal(t, input, expectedHyperlink)
} else {
assert.Equal(t, input, expectedNoHyperlink)
}
}
}
func TestBasicLink(t *testing.T) {
input := termlink.Link("Hello", "https://google.com")
expectedHyperlink := "\x1b]8;;https://google.com\aHello\x1b]8;;\a\x1b[m"
expectedNoHyperlink := "Hello (https://google.com)\u001b[m"
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
}
func TestColorLink(t *testing.T) {
input := termlink.ColorLink("Hello", "https://google.com", "red")
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[31mHello\x1b]8;;\a\x1b[m"
expectedNoHyperlink := "\x1b[31mHello (https://google.com)\x1b[m"
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
}
func TestBoldLink(t *testing.T) {
input := termlink.ColorLink("Hello", "https://google.com", "bold")
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[1mHello\x1b]8;;\a\x1b[m"
expectedNoHyperlink := "\x1b[1mHello (https://google.com)\x1b[m"
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
}
func TestItalicsLink(t *testing.T) {
input := termlink.ColorLink("Hello", "https://google.com", "italic")
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[3mHello\x1b]8;;\a\x1b[m"
expectedNoHyperlink := "\x1b[3mHello (https://google.com)\x1b[m"
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
}
func TestItalicsBoldLink(t *testing.T) {
input := termlink.ColorLink("Hello", "https://google.com", "bold italic")
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[1;3mHello\x1b]8;;\a\x1b[m"
expectedNoHyperlink := "\x1b[1;3mHello (https://google.com)\x1b[m"
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
}
func TestColorItalicsBoldLink(t *testing.T) {
input := termlink.ColorLink("Hello", "https://google.com", "red bold italic")
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[31;1;3mHello\x1b]8;;\a\x1b[m"
expectedNoHyperlink := "\x1b[31;1;3mHello (https://google.com)\x1b[m"
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
}