Skip to content

Commit

Permalink
Add tests to cover the regression reported in #204
Browse files Browse the repository at this point in the history
  • Loading branch information
joho committed Feb 5, 2023
1 parent b311b26 commit 9490fb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion fixtures/plain.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ OPTION_C= 3
OPTION_D =4
OPTION_E = 5
OPTION_F =
OPTION_G=
OPTION_G=
OPTION_H=1 2
7 changes: 6 additions & 1 deletion godotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestReadPlainEnv(t *testing.T) {
"OPTION_E": "5",
"OPTION_F": "",
"OPTION_G": "",
"OPTION_H": "1 2",
}

envMap, err := Read(envFileName)
Expand Down Expand Up @@ -153,6 +154,7 @@ func TestLoadPlainEnv(t *testing.T) {
"OPTION_C": "3",
"OPTION_D": "4",
"OPTION_E": "5",
"OPTION_H": "1 2",
}

loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets)
Expand Down Expand Up @@ -369,6 +371,9 @@ func TestParsing(t *testing.T) {
// expect(env('foo=bar ')).to eql('foo' => 'bar') # not 'bar '
parseAndCompare(t, "FOO=bar ", "FOO", "bar")

// unquoted internal whitespace is preserved
parseAndCompare(t, `KEY=value value`, "KEY", "value value")

// it 'ignores inline comments' do
// expect(env("foo=bar # this is foo")).to eql('foo' => 'bar')
parseAndCompare(t, "FOO=bar # this is foo", "FOO", "bar")
Expand All @@ -394,7 +399,7 @@ func TestParsing(t *testing.T) {
parseAndCompare(t, `KEY="`, "KEY", "\"")
parseAndCompare(t, `KEY="value`, "KEY", "\"value")

// leading whitespace should be ignored
// unquoted whitespace around keys should be ignored
parseAndCompare(t, " KEY =value", "KEY", "value")
parseAndCompare(t, " KEY=value", "KEY", "value")
parseAndCompare(t, "\tKEY=value", "KEY", "value")
Expand Down

0 comments on commit 9490fb6

Please sign in to comment.