Additional formatting

This commit is contained in:
eanderton
2014-07-07 21:08:57 -04:00
parent 7b208738bc
commit c9ea292f59
+41 -42
View File
@@ -14,10 +14,10 @@ func assertTree(t *testing.T, tree *TomlTree, err error, ref map[string]interfac
for k, v := range ref { for k, v := range ref {
node := tree.Get(k) node := tree.Get(k)
switch cast_node := node.(type) { switch cast_node := node.(type) {
case []*TomlTree: case []*TomlTree:
for idx, item := range cast_node { for idx, item := range cast_node {
assertTree(t, item, err, v.([]map[string]interface{})[idx]) assertTree(t, item, err, v.([]map[string]interface{})[idx])
} }
case *TomlTree: case *TomlTree:
assertTree(t, cast_node, err, v.(map[string]interface{})) assertTree(t, cast_node, err, v.(map[string]interface{}))
default: default:
@@ -158,7 +158,6 @@ func TestNestedEmptyArrays(t *testing.T) {
}) })
} }
func TestArrayMixedTypes(t *testing.T) { func TestArrayMixedTypes(t *testing.T) {
_, err := Load("a = [42, 16.0]") _, err := Load("a = [42, 16.0]")
if err.Error() != "mixed types in array" { if err.Error() != "mixed types in array" {
@@ -291,50 +290,50 @@ func TestParseFile(t *testing.T) {
func TestParseKeyGroupArray(t *testing.T) { func TestParseKeyGroupArray(t *testing.T) {
tree, err := Load("[[foo.bar]] a = 42\n[[foo.bar]] a = 69") tree, err := Load("[[foo.bar]] a = 42\n[[foo.bar]] a = 69")
assertTree(t, tree, err, map[string]interface{}{ assertTree(t, tree, err, map[string]interface{}{
"foo": map[string]interface{} { "foo": map[string]interface{}{
"bar": []map[string]interface{} { "bar": []map[string]interface{}{
{ "a": int64(42), }, {"a": int64(42)},
{ "a": int64(69), }, {"a": int64(69)},
}, },
}, },
}) })
} }
func TestToTomlValue(t *testing.T) { func TestToTomlValue(t *testing.T) {
for idx, item := range []struct{ for idx, item := range []struct {
Value interface{} Value interface{}
Expect string Expect string
}{ }{
{ int64(12345), "12345", }, {int64(12345), "12345"},
{ float64(123.45), "123.45", }, {float64(123.45), "123.45"},
{ bool(true), "true", }, {bool(true), "true"},
{ "hello world", "\"hello world\"", }, {"hello world", "\"hello world\""},
{ "\b\t\n\f\r\"\\", "\"\\b\\t\\n\\f\\r\\\"\\\\\"", }, {"\b\t\n\f\r\"\\", "\"\\b\\t\\n\\f\\r\\\"\\\\\""},
{ "\x05", "\"\\u0005\"", }, {"\x05", "\"\\u0005\""},
{ time.Date(1979, time.May, 27, 7, 32, 0, 0, time.UTC), {time.Date(1979, time.May, 27, 7, 32, 0, 0, time.UTC),
"1979-05-27T07:32:00Z", }, "1979-05-27T07:32:00Z"},
{ []interface{}{"gamma", "delta"}, {[]interface{}{"gamma", "delta"},
"[\n \"gamma\",\n \"delta\",\n]", }, "[\n \"gamma\",\n \"delta\",\n]"},
}{ } {
result := toTomlValue(item.Value, 0) result := toTomlValue(item.Value, 0)
if result != item.Expect { if result != item.Expect {
t.Errorf("Test %d - got '%s', expected '%s'", idx, result, item.Expect) t.Errorf("Test %d - got '%s', expected '%s'", idx, result, item.Expect)
} }
} }
} }
func TestToString(t *testing.T) { func TestToString(t *testing.T) {
tree := &TomlTree{ tree := &TomlTree{
"foo": &TomlTree{ "foo": &TomlTree{
"bar": []*TomlTree { "bar": []*TomlTree{
{ "a": int64(42), }, {"a": int64(42)},
{ "a": int64(69), }, {"a": int64(69)},
}, },
}, },
} }
result := tree.ToString() result := tree.ToString()
expected := "\n[foo]\n\n[[foo.bar]]\na = 42\n\n[[foo.bar]]\na = 69\n" expected := "\n[foo]\n\n[[foo.bar]]\na = 42\n\n[[foo.bar]]\na = 69\n"
if result != expected { if result != expected {
t.Errorf("Expected got '%s', expected '%s'", result, expected) t.Errorf("Expected got '%s', expected '%s'", result, expected)
} }
} }