1
- // Copyright (c) 2017 Uber Technologies, Inc.
1
+ // Copyright (c) 2019 Uber Technologies, Inc.
2
2
//
3
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
// of this software and associated documentation files (the "Software"), to deal
@@ -47,12 +47,12 @@ const expected = `This is a test$. $ This is a $test.
47
47
$$$$
48
48
${parti`
49
49
50
- const ends_in_dollar = `There is a dollar at the end$`
51
- const ends_in_ddollar = `There is a dollar at the end$$`
52
- const many_dollars_orig = `$$$$$$$`
53
- const many_dollars_expect = `$$$$`
54
- const ends_in_var = `There is a test at the end: $t3sT`
55
- const ends_in_var_expect = `There is a test at the end: test`
50
+ const endsInDollar = `There is a dollar at the end$`
51
+ const endsInDoubleDollar = `There is a dollar at the end$$`
52
+ const manyDollarsOrig = `$$$$$$$`
53
+ const manyDollarsExpect = `$$$$`
54
+ const endsInVar = `There is a test at the end: $t3sT`
55
+ const endsInVarExpect = `There is a test at the end: test`
56
56
57
57
type oneByteReader struct {
58
58
r io.Reader
@@ -89,7 +89,7 @@ func (e *bufReader) Read(buf []byte) (int, error) {
89
89
func TestExpander (t * testing.T ) {
90
90
r := bytes .NewReader ([]byte (orig ))
91
91
92
- expand_func := func (s string ) (string , error ) {
92
+ expandFunc := func (s string ) (string , error ) {
93
93
switch s {
94
94
case "t3sT" :
95
95
return "test" , nil
@@ -101,7 +101,7 @@ func TestExpander(t *testing.T) {
101
101
}
102
102
103
103
// Parse whole string
104
- tr := transform .NewReader (r , & expandTransformer {expand : expand_func })
104
+ tr := transform .NewReader (r , & expandTransformer {expand : expandFunc })
105
105
actual , err := ioutil .ReadAll (tr )
106
106
require .NoError (t , err )
107
107
assert .Exactly (t , expected , string (actual ))
@@ -111,15 +111,15 @@ func TestExpander(t *testing.T) {
111
111
112
112
// Partial parse
113
113
var partial [11 ]byte
114
- tr = transform .NewReader (r , & expandTransformer {expand : expand_func })
114
+ tr = transform .NewReader (r , & expandTransformer {expand : expandFunc })
115
115
n , err := tr .Read (partial [:])
116
116
require .NoError (t , err )
117
117
assert .Exactly (t , n , len (partial ))
118
118
assert .Exactly (t , expected [:n ], string (partial [:]))
119
119
120
120
// Empty string
121
121
r = bytes .NewReader ([]byte {})
122
- tr = transform .NewReader (r , & expandTransformer {expand : expand_func })
122
+ tr = transform .NewReader (r , & expandTransformer {expand : expandFunc })
123
123
actual , err = ioutil .ReadAll (tr )
124
124
require .NoError (t , err )
125
125
assert .Exactly (t , "" , string (actual ))
@@ -129,7 +129,7 @@ func TestExpanderOneByteAtATime(t *testing.T) {
129
129
r := bytes .NewReader ([]byte (orig ))
130
130
rr := & oneByteReader {r : r }
131
131
132
- expand_func := func (s string ) (string , error ) {
132
+ expandFunc := func (s string ) (string , error ) {
133
133
switch s {
134
134
case "t3sT" :
135
135
return "test" , nil
@@ -140,7 +140,7 @@ func TestExpanderOneByteAtATime(t *testing.T) {
140
140
return "NOMATCH" , errors .New ("No Match" )
141
141
}
142
142
143
- tr := transform .NewReader (rr , & expandTransformer {expand : expand_func })
143
+ tr := transform .NewReader (rr , & expandTransformer {expand : expandFunc })
144
144
actual , err := ioutil .ReadAll (tr )
145
145
require .NoError (t , err )
146
146
assert .Exactly (t , expected , string (actual ))
@@ -149,7 +149,7 @@ func TestExpanderOneByteAtATime(t *testing.T) {
149
149
func TestExpanderFailingTransform (t * testing.T ) {
150
150
r := bytes .NewReader ([]byte (orig ))
151
151
152
- expand_func := func (s string ) (string , error ) {
152
+ expandFunc := func (s string ) (string , error ) {
153
153
switch s {
154
154
case "t3sT" :
155
155
return "test" , nil
@@ -159,7 +159,7 @@ func TestExpanderFailingTransform(t *testing.T) {
159
159
return "NOMATCH" , errors .New ("No Match" )
160
160
}
161
161
162
- tr := transform .NewReader (r , & expandTransformer {expand : expand_func })
162
+ tr := transform .NewReader (r , & expandTransformer {expand : expandFunc })
163
163
_ , err := ioutil .ReadAll (tr )
164
164
require .Error (t , err )
165
165
}
@@ -169,13 +169,13 @@ func TestExpanderMisc(t *testing.T) {
169
169
orig string
170
170
expect string
171
171
}{
172
- {ends_in_dollar , ends_in_dollar },
173
- {ends_in_ddollar , ends_in_dollar },
174
- {ends_in_var , ends_in_var_expect },
175
- {many_dollars_orig , many_dollars_expect },
172
+ {endsInDollar , endsInDollar },
173
+ {endsInDoubleDollar , endsInDollar },
174
+ {endsInVar , endsInVarExpect },
175
+ {manyDollarsOrig , manyDollarsExpect },
176
176
}
177
177
178
- expand_func := func (s string ) (string , error ) {
178
+ expandFunc := func (s string ) (string , error ) {
179
179
switch s {
180
180
case "t3sT" :
181
181
return "test" , nil
@@ -191,7 +191,7 @@ func TestExpanderMisc(t *testing.T) {
191
191
func (t * testing.T ) {
192
192
tr := transform .NewReader (
193
193
bytes .NewReader ([]byte (tst .orig )),
194
- & expandTransformer {expand : expand_func },
194
+ & expandTransformer {expand : expandFunc },
195
195
)
196
196
actual , err := ioutil .ReadAll (tr )
197
197
require .NoError (t , err )
@@ -213,7 +213,7 @@ func TestExpanderLongSrc(t *testing.T) {
213
213
{"$a${" , a + "${" },
214
214
}
215
215
216
- expand_func := func (s string ) (string , error ) {
216
+ expandFunc := func (s string ) (string , error ) {
217
217
switch s {
218
218
case "a" :
219
219
return a , nil
@@ -228,7 +228,7 @@ func TestExpanderLongSrc(t *testing.T) {
228
228
func (t * testing.T ) {
229
229
tr := transform .NewReader (
230
230
& bufReader {buf : []byte (tst .orig )},
231
- & expandTransformer {expand : expand_func },
231
+ & expandTransformer {expand : expandFunc },
232
232
)
233
233
actual , err := ioutil .ReadAll (tr )
234
234
require .NoError (t , err )
@@ -253,7 +253,7 @@ func TestTransformLimit(t *testing.T) {
253
253
{"$" + a , transform .ErrShortSrc },
254
254
}
255
255
256
- expand_func := func (s string ) (string , error ) {
256
+ expandFunc := func (s string ) (string , error ) {
257
257
switch s {
258
258
case "a" :
259
259
return a + "aa" , nil
@@ -270,7 +270,7 @@ func TestTransformLimit(t *testing.T) {
270
270
func (t * testing.T ) {
271
271
tr := transform .NewReader (
272
272
bytes .NewReader ([]byte (tst .orig )),
273
- & expandTransformer {expand : expand_func },
273
+ & expandTransformer {expand : expandFunc },
274
274
)
275
275
_ , err := ioutil .ReadAll (tr )
276
276
require .EqualError (t , err , tst .err .Error ())
0 commit comments