package read import ( "github.com/stretchr/testify/assert" "mal-go/list" "mal-go/symbol" "testing" ) func TestReadInt(t *testing.T) { input := "2" sym, err, end_pos := readInt(input, 0, "user") assert.Equal(t, 2, sym, "should read ") assert.Equal(t, nil, err, "should read without error") assert.Equal(t, len(input), end_pos, "should read the whole string") } func TestReadSymbol(t *testing.T) { input := "foo" sym, err, end_pos := readSymbol(input, 0, "user") assert.Equal(t, sym, symbol.Intern("user", "foo"), "should read user/foo symbol") assert.Equal(t, err, nil, "should read without error") assert.Equal(t, end_pos, len(input), "should read the whole string") } func TestReadSymbolWithNamespace(t *testing.T) { input := "foo/bar" sym, err, end_pos := readSymbol(input, 0, "user") assert.Equal(t, sym, symbol.Intern("foo", "bar"), "should read user/foo symbol") assert.Equal(t, err, nil, "should read without error") assert.Equal(t, end_pos, len(input), "should read the whole string") } func TestReadListElem(t *testing.T) { input := "(1223)" f, err, pos := readForm(input, 1, "user") assert.Equal(t, f, 1223, "should num list") assert.Equal(t, err, nil, "should read without error") assert.Equal(t, pos, len(input)-1, "should read the whole number") assert.Equal(t, rune(input[pos]), ')', "should end pointing to ending list char") } func TestReadList(t *testing.T) { input := "(1 2 3)" l, err, pos := readList(input, 0, "user") assert.Equal(t, list.New().Conj(3).Conj(2).Conj(1), l, "should read list") assert.Equal(t, nil, err, "should read without error") assert.Equal(t, len(input), pos, "should read the whole string") }