ginger/parse/parse_test.go

61 lines
1.1 KiB
Go
Raw Normal View History

2014-10-07 00:55:15 +00:00
package parse
import (
"bytes"
2014-10-15 00:39:20 +00:00
"bufio"
2014-10-07 00:55:15 +00:00
. "testing"
"github.com/mediocregopher/ginger/types"
)
func TestReadString(t *T) {
m := map[string]types.Str{
`"hey there"`: "hey there",
`"hey\nthere"`: "hey\nthere",
`"hey there ⌘"`: "hey there ⌘",
`"hey\nthere \u2318"`: "hey\nthere ⌘",
}
for input, output := range m {
buf := bytes.NewBufferString(input)
buf.ReadByte()
2014-10-15 00:39:20 +00:00
buf2 := bufio.NewReader(buf)
2014-10-07 00:55:15 +00:00
2014-10-15 00:39:20 +00:00
parseOut, err := ReadString(buf2)
2014-10-07 00:55:15 +00:00
if err != nil {
t.Fatal(err)
}
if output != parseOut {
t.Fatalf("`%s` != `%s`", output, parseOut)
}
}
}
2014-10-15 00:13:10 +00:00
func TestParseBareElement(t *T) {
m := map[string]types.Elem{
`1`: types.Int(1),
`12`: types.Int(12),
`-1`: types.Int(-1),
`-12`: types.Int(-12),
`1.0`: types.Float(1.0),
`12.5`: types.Float(12.5),
`-12.5`: types.Float(-12.5),
`-`: types.Str(":-"),
`bare`: types.Str(":bare"),
`:not-bare`: types.Str(":not-bare"),
}
for input, output := range m {
el, err := ParseBareElement(input)
if err != nil {
t.Fatal(err)
}
if output != el {
t.Fatalf("`%s` != `%s`", output, el)
}
}
}