A lot of changes. Main ones are:
- fraction type renamed as FractionType and moved from operator-fraction.go to fraction-type.go - ListType moved from operator-list.go to list-type.go - all test file were renamed adding the "t_" prefix - defined a test template in file t_temple_test.go - new test file t_relational_test.go where relational tests are collected - lists can now compared as set using operators <, <=, >, and >= (IMPORTANT: here = menas same content, not same list)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||
// All rights reserved.
|
||||
|
||||
// t_ast_test.go
|
||||
package expr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAstString(t *testing.T) {
|
||||
tree := NewAst()
|
||||
if gotResult := tree.String(); gotResult != "(nil)" {
|
||||
t.Errorf(`result: got %q, want "(nil)"`, gotResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddTokensGood(t *testing.T) {
|
||||
tk1 := NewValueToken(0, 0, SymInteger, "100", 100)
|
||||
tk2 := NewToken(0, 0, SymPlus, "+")
|
||||
tk3 := NewValueToken(0, 0, SymInteger, "50", 500)
|
||||
|
||||
tree := NewAst()
|
||||
if gotErr := tree.addTokens(tk1, tk2, tk3); gotErr != nil {
|
||||
t.Errorf("err: got <%v>, want <nil>", gotErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddTokensBad(t *testing.T) {
|
||||
tk0 := NewValueToken(0, 0, SymInteger, "200", 200)
|
||||
tk1 := NewValueToken(0, 0, SymInteger, "100", 100)
|
||||
tk2 := NewToken(0, 0, SymPlus, "+")
|
||||
tk3 := NewValueToken(0, 0, SymInteger, "50", 500)
|
||||
|
||||
wantErr := errors.New(`[0:0] two adjacent operators: "200" and "100"`)
|
||||
|
||||
tree := NewAst()
|
||||
if gotErr := tree.addTokens(tk0, tk1, tk2, tk3); gotErr != nil && gotErr.Error() != wantErr.Error() {
|
||||
t.Errorf("err: got <%v>, want <nil>", gotErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddUnknownTokens(t *testing.T) {
|
||||
tk0 := NewToken(0, 0, SymPercent, "%")
|
||||
|
||||
wantErr := errors.New(`unexpected token "%"`)
|
||||
|
||||
tree := NewAst()
|
||||
if gotErr := tree.addToken(tk0); gotErr != nil && gotErr.Error() != wantErr.Error() {
|
||||
t.Errorf("err: got <%v>, want <%v>", gotErr, wantErr)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user