Add whitespace tests. (#210)

This commit is contained in:
Chris Jones 2023-04-19 18:52:14 -06:00 committed by GitHub
parent 3fc4292b58
commit 193c9aba29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 61 additions and 0 deletions

View File

@ -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)
}
})
}
}