package jlp
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
type TestCase struct {
|
|
in string
|
|
out Node
|
|
}
|
|
|
|
var TestCases = []TestCase{
|
|
{
|
|
in: `
|
|
(
|
|
(main {1 "abc" 'a' '世'})
|
|
[sub (2 ><xyz 6.0) true])
|
|
`,
|
|
out: Node{Type: List, Paren: '(', List: []Node{
|
|
{Type: List, Paren: '(', List: []Node{
|
|
{Type: Ident, Ident: "main"},
|
|
{Type: List, Paren: '{', List: []Node{
|
|
{Type: Int, Int: 1},
|
|
{Type: String, String: "abc"},
|
|
{Type: Rune, Rune: 'a'},
|
|
{Type: Rune, Rune: '世'}}}}},
|
|
{Type: List, Paren: '[', List: []Node{
|
|
{Type: Ident, Ident: "sub"},
|
|
{Type: List, Paren: '(', List: []Node{
|
|
{Type: Int, Int: 2},
|
|
{Type: Ident, Ident: "><xyz"},
|
|
{Type: Float, Float: 6.0}}},
|
|
{Type: Bool, Bool: true}}}}},
|
|
},
|
|
}
|
|
|
|
func TestParse(t *testing.T) {
|
|
for _, tc := range TestCases {
|
|
node, err := Parse(tc.in)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !reflect.DeepEqual(node, tc.out) {
|
|
t.Fatalf("\n%v!=\n%v", node, tc.out)
|
|
}
|
|
}
|
|
}
|