40 lines
1.5 KiB
Go
40 lines
1.5 KiB
Go
package ast_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.makaay.nl/mauricem/go-toml/ast"
|
|
)
|
|
|
|
func Test_StringFormatting(t *testing.T) {
|
|
testAST(t, func() (error, *ast.Document) {
|
|
tableData := make(ast.Table)
|
|
tableData["x"] = ast.NewValue(ast.TypeBoolean, true)
|
|
tableData["y"] = ast.NewValue(ast.TypeInteger, 42)
|
|
dateTime, _ := time.Parse(time.RFC3339Nano, "2003-11-01T01:02:03.999999999+10:00")
|
|
doc := ast.NewDocument()
|
|
doc.SetKeyValuePair(ast.NewKey("a"), ast.NewValue(ast.TypeInteger, 1))
|
|
doc.SetKeyValuePair(ast.NewKey("b"), ast.NewValue(ast.TypeFloat, 2.3))
|
|
doc.SetKeyValuePair(ast.NewKey("c"), ast.NewValue(ast.TypeBoolean, true))
|
|
doc.SetKeyValuePair(ast.NewKey("d"), ast.NewValue(ast.TypeString, "foo"))
|
|
doc.SetKeyValuePair(ast.NewKey("e"), ast.NewValue(ast.TypeArray, ast.NewValue(ast.TypeInteger, 1), ast.NewValue(ast.TypeInteger, 2)))
|
|
doc.SetKeyValuePair(ast.NewKey("f"), ast.NewValue(ast.TypeTable, tableData))
|
|
doc.SetKeyValuePair(ast.NewKey("g"), ast.NewValue(ast.TypeOffsetDateTime, dateTime))
|
|
doc.SetKeyValuePair(ast.NewKey("h"), ast.NewValue(ast.TypeLocalDateTime, dateTime))
|
|
doc.SetKeyValuePair(ast.NewKey("i"), ast.NewValue(ast.TypeLocalDate, dateTime))
|
|
doc.SetKeyValuePair(ast.NewKey("j"), ast.NewValue(ast.TypeLocalTime, dateTime))
|
|
return nil, doc
|
|
}, "",
|
|
`{"a": 1, `+
|
|
`"b": 2.3, `+
|
|
`"c": true, `+
|
|
`"d": "foo", `+
|
|
`"e": [1, 2], `+
|
|
`"f": {"x": true, "y": 42}, `+
|
|
`"g": 2003-11-01T01:02:03.999999999+10:00, `+
|
|
`"h": 2003-11-01 01:02:03.999999999, `+
|
|
`"i": 2003-11-01, `+
|
|
`"j": 01:02:03.999999999}`)
|
|
}
|