@@ -14,8 +14,9 @@ const msg = "test case %d failed"
14
14
var testCasesUnquote = []struct {
15
15
quoted string
16
16
unquoted string
17
- // isn't empty only for cases where quote(unqote(s)) != s
18
- // e.g when we loose the informaiton wich original escape sequence was used
17
+ // If this is non-empty it means that quoteing back unqoted string does not
18
+ // produce same result bit-wise.
19
+ // This happens when we lose the information about original escape sequence (octal, hex)
19
20
// Golang unquote() defaults to hex format, so it's used as canonical one.
20
21
canonicalQuoted string
21
22
}{
@@ -31,7 +32,6 @@ func TestUnquoteSingle(t *testing.T) {
31
32
for i , test := range testCasesUnquote {
32
33
s , err := unquoteSingle (test .quoted )
33
34
require .NoError (t , err , msg , i )
34
-
35
35
require .Equal (t , test .unquoted , s , msg , i )
36
36
}
37
37
}
@@ -51,15 +51,14 @@ func TestUnquoteSingleAndQuoteBack(t *testing.T) {
51
51
}
52
52
53
53
func assertEquals (t * testing.T , quoted , actual string , i int ) {
54
- success := assert .Equal (t , quoted , actual , msg , i )
55
- if ! success {
54
+ if ! assert .Equal (t , quoted , actual , msg , i ) {
56
55
printDebug (t , quoted , actual )
57
56
t .FailNow ()
58
57
}
59
58
}
60
59
61
60
func printDebug (t * testing.T , quoted , actual string ) {
62
- t .Logf ("\t exepcted : len=%d" , len (quoted ))
61
+ t .Logf ("\t expected : len=%d" , len (quoted ))
63
62
for _ , c := range quoted {
64
63
t .Logf ("%x - %#U" , c , c )
65
64
}
@@ -78,6 +77,8 @@ func BenchmarkReplacingNullEscape_Iterative(b *testing.B) {
78
77
}
79
78
}
80
79
80
+ // replaceEscapedMaybeIter is alternative implementation of replaceEscapedMaybe
81
+ // It is only used in benchmark tests for performance comparison.
81
82
func replaceEscapedMaybeIter (s string , old , new rune ) string {
82
83
var runeTmp [utf8 .UTFMax ]byte
83
84
n := utf8 .EncodeRune (runeTmp [:], new )
@@ -124,7 +125,8 @@ func BenchmarkReplacingNullEscape_Regexp(b *testing.B) {
124
125
125
126
var re = regexp .MustCompile (`\\0([^0-9]|$)` )
126
127
127
- // replaceEscapedMaybeRegexp is very simple, but slower alternative to normalizer.replaceEscapedMaybe
128
+ // replaceEscapedMaybeRegexp is alternative implementation of replaceEscapedMaybe
129
+ // It is only used in benchmark tests for performance comparison.
128
130
func replaceEscapedMaybeRegexp (s string ) string {
129
131
return re .ReplaceAllString (s , "\x00 $1" )
130
132
}
0 commit comments