Skip to content

Commit 75edd9c

Browse files
authored
Merge pull request #2 from savioxavier/testing
2 parents 117ae6a + 9882835 commit 75edd9c

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ require (
88
)
99

1010
require (
11+
github.com/davecgh/go-spew v1.1.0 // indirect
1112
github.com/mattn/go-colorable v0.1.9 // indirect
1213
github.com/mattn/go-isatty v0.0.14 // indirect
14+
github.com/pmezard/go-difflib v1.0.0 // indirect
15+
github.com/stretchr/testify v1.7.1 // indirect
1316
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
1417
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
18+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
1519
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
24
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
35
github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ=
@@ -7,6 +9,11 @@ github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
79
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
810
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
911
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
12+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
13+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
14+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15+
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
16+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1017
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1118
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1219
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -15,3 +22,6 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK
1522
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1623
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
1724
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
25+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
26+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
27+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

termlink_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package termlink_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/fatih/color"
7+
"github.com/savioxavier/termlink"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func testAll(input, expectedHyperlink, expectedNoHyperlink string) func(t *testing.T) {
12+
return func(t *testing.T) {
13+
if termlink.SupportsHyperlinks() {
14+
assert.Equal(t, input, expectedHyperlink)
15+
} else {
16+
assert.Equal(t, input, expectedNoHyperlink)
17+
}
18+
}
19+
}
20+
21+
func TestBasicLink(t *testing.T) {
22+
input := termlink.Link("Hello", "https://google.com")
23+
expectedHyperlink := "\x1b]8;;https://google.com\aHello\x1b]8;;\a\x1b[m"
24+
expectedNoHyperlink := "Hello (\u200Bhttps://google.com)\u001b[m"
25+
26+
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
27+
}
28+
29+
func TestColorLink(t *testing.T) {
30+
input := termlink.ColorLink("Hello", "https://google.com", "red")
31+
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[31mHello\x1b]8;;\a\x1b[m"
32+
expectedNoHyperlink := "\x1b[31mHello (\u200bhttps://google.com)\x1b[m"
33+
34+
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
35+
}
36+
37+
func TestColorsPackageLink(t *testing.T) {
38+
input := color.New(color.FgCyan).SprintFunc()(termlink.Link("Hello", "https://google.com"))
39+
expectedHyperlink := "\x1b[36m\x1b]8;;https://google.com\aHello\x1b]8;;\a\x1b[m\x1b[0m"
40+
expectedNoHyperlink := "\x1b[36mHello (\u200bhttps://google.com)\x1b[m\x1b[0m"
41+
42+
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
43+
}
44+
45+
func TestBoldLink(t *testing.T) {
46+
input := termlink.ColorLink("Hello", "https://google.com", "bold")
47+
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[1mHello\x1b]8;;\a\x1b[m"
48+
expectedNoHyperlink := "\x1b[1mHello (\u200bhttps://google.com)\x1b[m"
49+
50+
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
51+
}
52+
53+
func TestItalicsLink(t *testing.T) {
54+
input := termlink.ColorLink("Hello", "https://google.com", "italic")
55+
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[3mHello\x1b]8;;\a\x1b[m"
56+
expectedNoHyperlink := "\x1b[3mHello (\u200bhttps://google.com)\x1b[m"
57+
58+
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
59+
60+
}
61+
62+
func TestItalicsBoldLink(t *testing.T) {
63+
input := termlink.ColorLink("Hello", "https://google.com", "bold italic")
64+
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[1;3mHello\x1b]8;;\a\x1b[m"
65+
expectedNoHyperlink := "\x1b[1;3mHello (\u200bhttps://google.com)\x1b[m"
66+
67+
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
68+
}
69+
70+
func TestColorItalicsBoldLink(t *testing.T) {
71+
input := termlink.ColorLink("Hello", "https://google.com", "red bold italic")
72+
expectedHyperlink := "\x1b]8;;https://google.com\a\x1b[31;1;3mHello\x1b]8;;\a\x1b[m"
73+
expectedNoHyperlink := "\x1b[31;1;3mHello (\u200bhttps://google.com)\x1b[m"
74+
75+
testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
76+
}

0 commit comments

Comments
 (0)