You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
10 years ago
|
package moon
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
10 years ago
|
type person struct {
|
||
|
Name string
|
||
|
Age int
|
||
|
}
|
||
|
|
||
10 years ago
|
var valueTests = []struct {
|
||
|
in interface{}
|
||
|
out string
|
||
|
}{
|
||
|
{nil, "null"},
|
||
|
{true, "true"},
|
||
|
{false, "false"},
|
||
|
{0, "0"},
|
||
|
{1, "1"},
|
||
|
{12345, "12345"},
|
||
|
{.1, "0.1"},
|
||
10 years ago
|
{1.0, "1"}, // god dammit
|
||
|
{1.0e9, "1e+09"},
|
||
10 years ago
|
{"a string", `"a string"`},
|
||
|
{`it's got "quotes"`, `"it's got \"quotes\""`},
|
||
10 years ago
|
{person{"jordan", 28}, `{Name: "jordan" Age: 28}`},
|
||
10 years ago
|
{[]int{1, 2, 3}, `[1 2 3]`},
|
||
10 years ago
|
{[]float32{1.0, 2.2, 3.3}, `[1 2.2 3.3]`},
|
||
|
{[]float64{1.0, 2.2, 3.3}, `[1 2.2 3.3]`},
|
||
10 years ago
|
{[]string{"one", "two", "three"}, `["one" "two" "three"]`},
|
||
10 years ago
|
// {
|
||
|
// map[string]int{"one": 1, "two": 2, "three": 3},
|
||
|
// `{one: 1 two: 2 three: 3}`,
|
||
|
// },
|
||
|
// {
|
||
|
// map[string]interface{}{
|
||
|
// "one": 1,
|
||
|
// "two": 2.0,
|
||
|
// "pi": 3.14,
|
||
|
// },
|
||
|
// `{one: 1 two: 2 pi: 3.14}`,
|
||
|
// },
|
||
10 years ago
|
}
|
||
|
|
||
|
func TestWriteValues(t *testing.T) {
|
||
|
for _, test := range valueTests {
|
||
|
out, err := Encode(test.in)
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
continue
|
||
|
}
|
||
|
if string(out) != test.out {
|
||
|
t.Errorf("expected '%s', saw '%s'", test.out, string(out))
|
||
|
}
|
||
|
}
|
||
|
}
|