@@ -3,10 +3,15 @@ package goada
33import (
44 "fmt"
55 "net/url"
6- "strings"
76 "testing"
87)
98
9+ func compareString (t * testing.T , expected , actual , message string ) {
10+ if expected != actual {
11+ t .Errorf ("Expected %s, but got %s. %s" , expected , actual , message )
12+ }
13+ }
14+
1015func TestBadUrl (t * testing.T ) {
1116 url , err := New ("some bad url" )
1217 if err == nil {
@@ -24,12 +29,8 @@ func TestGoodUrl(t *testing.T) {
2429 }
2530 fmt .Println (url .Href ())
2631
27- if strings .Compare (url .Href (), "https://www.google.com/" ) != 0 {
28- t .Error ("Expected normalized url" )
29- }
30- if strings .Compare (url .Protocol (), "https:" ) != 0 {
31- t .Error ("Expected https protocol" )
32- }
32+ compareString (t , "https://www.google.com/" , url .Href (), "Expected normalized url" )
33+ compareString (t , "https:" , url .Protocol (), "Expected https protocol" )
3334}
3435
3536func TestGoodUrlSet (t * testing.T ) {
@@ -39,26 +40,16 @@ func TestGoodUrlSet(t *testing.T) {
3940 }
4041 fmt .Println (url .Href ())
4142
42- if strings .Compare (url .Href (), "https://www.google.com/" ) != 0 {
43- t .Error ("Expected normalized url" )
44- }
45- if strings .Compare (url .Protocol (), "https:" ) != 0 {
46- t .Error ("Expected https protocol" )
47- }
43+ compareString (t , "https://www.google.com/" , url .Href (), "Expected normalized url" )
44+ compareString (t , "https:" , url .Protocol (), "Expected https protocol" )
4845 url .SetProtocol ("http:" )
49- if strings .Compare (url .Protocol (), "http:" ) != 0 {
50- t .Error ("Expected http protocol" )
51- }
46+ compareString (t , "http:" , url .Protocol (), "Expected http protocol" )
5247 url .SetHash ("goada" )
5348 fmt .Println (url .Hash ())
5449
55- if strings .Compare (url .Hash (), "#goada" ) != 0 {
56- t .Error ("Expected goada hash" )
57- }
50+ compareString (t , "#goada" , url .Hash (), "Expected goada hash" )
5851 fmt .Println (url .Href ())
59- if strings .Compare (url .Href (), "http://www.google.com/#goada" ) != 0 {
60- t .Error ("Expected normalized url" )
61- }
52+ compareString (t , "http://www.google.com/#goada" , url .Href (), "Expected normalized url" )
6253}
6354
6455// go test -bench Benchmark -run -
@@ -78,9 +69,7 @@ func TestStandard(t *testing.T) {
7869 t .Error ("Expected no error" )
7970 }
8071 fmt .Println (url .Href ())
81- if strings .Compare (url .Href (), "https://www.xn--googl-fsa.com/path2/" ) != 0 {
82- t .Error ("Expected normalized url" )
83- }
72+ compareString (t , "https://www.xn--googl-fsa.com/path2/" , url .Href (), "Expected normalized url" )
8473 url .Free ()
8574}
8675
@@ -96,7 +85,5 @@ func TestStandardGP(t *testing.T) {
9685 t .Error ("Go url should hot fail" )
9786 }
9887 fmt .Println (url .String ())
99- if strings .Compare (url .String (), "https://www.GOogl%C3%A9.com/./path/../path2/" ) != 0 {
100- t .Error ("Expected invalid normalized url" )
101- }
88+ compareString (t , "https://www.GOogl%C3%A9.com/./path/../path2/" , url .String (), "Expected invalid normalized url" )
10289}
0 commit comments