Skip to content

Commit 193c9ab

Browse files
authored
Add whitespace tests. (#210)
1 parent 3fc4292 commit 193c9ab

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

godotenv_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,64 @@ func TestTrailingNewlines(t *testing.T) {
573573
})
574574
}
575575
}
576+
577+
func TestWhitespace(t *testing.T) {
578+
cases := map[string]struct {
579+
input string
580+
key string
581+
value string
582+
}{
583+
"Leading whitespace": {
584+
input: " A=a\n",
585+
key: "A",
586+
value: "a",
587+
},
588+
"Leading tab": {
589+
input: "\tA=a\n",
590+
key: "A",
591+
value: "a",
592+
},
593+
"Leading mixed whitespace": {
594+
input: " \t \t\n\t \t A=a\n",
595+
key: "A",
596+
value: "a",
597+
},
598+
"Leading whitespace before export": {
599+
input: " \t\t export A=a\n",
600+
key: "A",
601+
value: "a",
602+
},
603+
"Trailing whitespace": {
604+
input: "A=a \t \t\n",
605+
key: "A",
606+
value: "a",
607+
},
608+
"Trailing whitespace with export": {
609+
input: "export A=a\t \t \n",
610+
key: "A",
611+
value: "a",
612+
},
613+
"No EOL": {
614+
input: "A=a",
615+
key: "A",
616+
value: "a",
617+
},
618+
"Trailing whitespace with no EOL": {
619+
input: "A=a ",
620+
key: "A",
621+
value: "a",
622+
},
623+
}
624+
625+
for n, c := range cases {
626+
t.Run(n, func(t *testing.T) {
627+
result, err := Unmarshal(c.input)
628+
if err != nil {
629+
t.Errorf("Input: %q Unexpected error:\t%q", c.input, err)
630+
}
631+
if result[c.key] != c.value {
632+
t.Errorf("Input %q Expected:\t %q/%q\nGot:\t %q", c.input, c.key, c.value, result)
633+
}
634+
})
635+
}
636+
}

0 commit comments

Comments
 (0)