test lists of strings pl0x

master
Jordan Orelli 9 years ago
parent ca6e986b0f
commit 7817994f07

@ -8,11 +8,13 @@ import (
func TestFillList(t *testing.T) { func TestFillList(t *testing.T) {
doc, err := ReadString(` doc, err := ReadString(`
# yay for lists # yay for lists
@cool_names: [larry; curly; moe]
servers: [ servers: [
{hostname: dev.example.com; label: dev} {hostname: dev.example.com; label: dev}
{hostname: prod.example.com; label: prod} {hostname: prod.example.com; label: prod}
] ]
numbers: [1 1 2 3 5 8 13] numbers: [1 1 2 3 5 8 13]
names: @cool_names
`) `)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -25,6 +27,7 @@ func TestFillList(t *testing.T) {
var config struct { var config struct {
Servers []server `name: servers` Servers []server `name: servers`
Numbers []int `name: numbers` Numbers []int `name: numbers`
Names []string `name: names`
} }
if err := doc.Fill(&config); err != nil { if err := doc.Fill(&config); err != nil {
t.Error(err) t.Error(err)
@ -40,4 +43,7 @@ func TestFillList(t *testing.T) {
if !reflect.DeepEqual(config.Numbers, []int{1, 1, 2, 3, 5, 8, 13}) { if !reflect.DeepEqual(config.Numbers, []int{1, 1, 2, 3, 5, 8, 13}) {
t.Errorf("bad numbers: %v", config.Numbers) t.Errorf("bad numbers: %v", config.Numbers)
} }
if !reflect.DeepEqual(config.Names, []string{"larry", "curly", "moe"}) {
t.Errorf("bad names: %v", config.Names)
}
} }

Loading…
Cancel
Save