diff --git a/godotenv_test.go b/godotenv_test.go index edb5781..c6d7e54 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -573,3 +573,64 @@ func TestTrailingNewlines(t *testing.T) { }) } } + +func TestWhitespace(t *testing.T) { + cases := map[string]struct { + input string + key string + value string + }{ + "Leading whitespace": { + input: " A=a\n", + key: "A", + value: "a", + }, + "Leading tab": { + input: "\tA=a\n", + key: "A", + value: "a", + }, + "Leading mixed whitespace": { + input: " \t \t\n\t \t A=a\n", + key: "A", + value: "a", + }, + "Leading whitespace before export": { + input: " \t\t export A=a\n", + key: "A", + value: "a", + }, + "Trailing whitespace": { + input: "A=a \t \t\n", + key: "A", + value: "a", + }, + "Trailing whitespace with export": { + input: "export A=a\t \t \n", + key: "A", + value: "a", + }, + "No EOL": { + input: "A=a", + key: "A", + value: "a", + }, + "Trailing whitespace with no EOL": { + input: "A=a ", + key: "A", + value: "a", + }, + } + + for n, c := range cases { + t.Run(n, func(t *testing.T) { + result, err := Unmarshal(c.input) + if err != nil { + t.Errorf("Input: %q Unexpected error:\t%q", c.input, err) + } + if result[c.key] != c.value { + t.Errorf("Input %q Expected:\t %q/%q\nGot:\t %q", c.input, c.key, c.value, result) + } + }) + } +}