go-toml/keyvaluepair_test.go

47 lines
1.7 KiB
Go

package parser_test
import (
"testing"
)
func TestKeyWithoutAssignment(t *testing.T) {
err := "unexpected end of file (expected a value assignment)"
runStatesTs(t, []statesT{
{"bare with whitespace", " a ", "[a]", "unexpected character ' ' (expected a value assignment)"},
{"bare lower", "abcdefghijklmnopqrstuvwxyz", "[abcdefghijklmnopqrstuvwxyz]", err},
{"bare upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]", err},
{"bare numbers", "0123456789", "[0123456789]", err},
{"bare underscore", "_", "[_]", err},
{"bare dash", "-", "[-]", err},
{"bare big mix", "-hey_good_Lookin123-", "[-hey_good_Lookin123-]", err},
})
}
func TestDottedKey(t *testing.T) {
runStatesTs(t, []statesT{
{"bare dotted", "a._.c", "[a].[_].[c]", "unexpected end of file (expected a value assignment)"},
{"bare dotted with whitespace", " a .\t\t b\t ", "[a].[b]", `unexpected character '\t' (expected a value assignment)`},
})
}
func TestKeyWithAssignmentButNoValue(t *testing.T) {
err := "unexpected end of file (expected a value)"
runStatesTs(t, []statesT{
{"bare", "a=", "[a]=", err},
{"double equal sign", "a==", "[a]=", "unexpected character '=' (expected a value)"},
{"bare dotted", "a.b=", "[a].[b]=", err},
{"bare dotted with whitespace", " a .\tb\t = ", "[a].[b]=", err},
})
}
func TestKeyWithValue(t *testing.T) {
runStatesTs(t, []statesT{
{"with string value",
" -key- = \"value\" # nice\r\n",
"[-key-]=STR(value)#(nice)", ""},
{"multiple string values",
"key = \"value1\"\nbare_key = \"value2\"\n# More coming up!\nbare-key = \"value3\"\n1234 = \"value4\"\n",
"[key]=STR(value1)[bare_key]=STR(value2)#(More coming up!)[bare-key]=STR(value3)[1234]=STR(value4)", ""},
})
}