@@ -271,6 +271,34 @@ func TestExpanding(t *testing.T) {
271
271
272
272
}
273
273
274
+ func TestVariableStringValueSeparator (t * testing.T ) {
275
+ input := "TEST_URLS=\" stratum+tcp://stratum.antpool.com:3333\n stratum+tcp://stratum.antpool.com:443\" "
276
+ want := map [string ]string {
277
+ "TEST_URLS" : "stratum+tcp://stratum.antpool.com:3333\n stratum+tcp://stratum.antpool.com:443" ,
278
+ }
279
+ got , err := Parse (strings .NewReader (input ))
280
+ if err != nil {
281
+ t .Error (err )
282
+ }
283
+
284
+ if len (got ) != len (want ) {
285
+ t .Fatalf (
286
+ "unexpected value:\n want:\n \t %#v\n \n got:\n \t %#v" , want , got )
287
+ }
288
+
289
+ for k , wantVal := range want {
290
+ gotVal , ok := got [k ]
291
+ if ! ok {
292
+ t .Fatalf ("key %q doesn't present in result" , k )
293
+ }
294
+ if wantVal != gotVal {
295
+ t .Fatalf (
296
+ "mismatch in %q value:\n want:\n \t %s\n \n got:\n \t %s" , k ,
297
+ wantVal , gotVal )
298
+ }
299
+ }
300
+ }
301
+
274
302
func TestActualEnvVarsAreLeftAlone (t * testing.T ) {
275
303
os .Clearenv ()
276
304
os .Setenv ("OPTION_A" , "actualenv" )
@@ -377,33 +405,38 @@ func TestParsing(t *testing.T) {
377
405
}
378
406
379
407
func TestLinesToIgnore (t * testing.T ) {
380
- // it 'ignores empty lines' do
381
- // expect(env("\n \t \nfoo=bar\n \nfizz=buzz")).to eql('foo' => 'bar', 'fizz' => 'buzz')
382
- if ! isIgnoredLine ("\n " ) {
383
- t .Error ("Line with nothing but line break wasn't ignored" )
384
- }
385
-
386
- if ! isIgnoredLine ("\r \n " ) {
387
- t .Error ("Line with nothing but windows-style line break wasn't ignored" )
388
- }
389
-
390
- if ! isIgnoredLine ("\t \t " ) {
391
- t .Error ("Line full of whitespace wasn't ignored" )
392
- }
393
-
394
- // it 'ignores comment lines' do
395
- // expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql('foo' => 'bar')
396
- if ! isIgnoredLine ("# comment" ) {
397
- t .Error ("Comment wasn't ignored" )
398
- }
399
-
400
- if ! isIgnoredLine ("\t #comment" ) {
401
- t .Error ("Indented comment wasn't ignored" )
408
+ cases := map [string ]struct {
409
+ input string
410
+ want string
411
+ }{
412
+ "Line with nothing but line break" : {
413
+ input : "\n " ,
414
+ },
415
+ "Line with nothing but windows-style line break" : {
416
+ input : "\r \n " ,
417
+ },
418
+ "Line full of whitespace" : {
419
+ input : "\t \t " ,
420
+ },
421
+ "Comment" : {
422
+ input : "# Comment" ,
423
+ },
424
+ "Indented comment" : {
425
+ input : "\t # comment" ,
426
+ },
427
+ "non-ignored value" : {
428
+ input : `export OPTION_B='\n'` ,
429
+ want : `export OPTION_B='\n'` ,
430
+ },
402
431
}
403
432
404
- // make sure we're not getting false positives
405
- if isIgnoredLine (`export OPTION_B='\n'` ) {
406
- t .Error ("ignoring a perfectly valid line to parse" )
433
+ for n , c := range cases {
434
+ t .Run (n , func (t * testing.T ) {
435
+ got := string (getStatementStart ([]byte (c .input )))
436
+ if got != c .want {
437
+ t .Errorf ("Expected:\t %q\n Got:\t %q" , c .want , got )
438
+ }
439
+ })
407
440
}
408
441
}
409
442
0 commit comments