MMQLEngine/mmql/engine/parsers/amount_test.go

51 lines
1.2 KiB
Go

package parsers
import (
// "fmt"
"strings"
"testing"
engine "github.com/tgckpg/mmqlengine/mmql/engine"
stmtd "github.com/tgckpg/mmqlengine/mmql/statements"
)
type _p struct {
amount float64
unit string
}
func TestAmountStatement( t *testing.T ) {
lexer := engine.Lexer{}
supportedStmts := map[string] func( *engine.Lexer ) ( stmtd.IStatement, error ) {
"AMOUNT": AmountStatement,
}
lexer.SupportedStmts = &supportedStmts
read_oks := map[string] _p {
"1 SHARES OF QQQ": _p{ 1, "SHARES" },
"1 QQQ": _p{ 1, "QQQ" },
"1 UNIT OF QQQ": _p{ 1, "UNIT" },
}
readAmount := engine.LexerExpect{
Statements: true,
Keywords: false,
Brackets: false,
Quotes: false,
Key: "AMOUNT",
}
for k := range read_oks {
lexer.SetReader( strings.NewReader( k ) )
stmt, err := lexer.ReadStatement( &readAmount )
if err != nil {
t.Error( err )
}
aStmt := any( stmt ).( stmtd.AmountStatement )
p, _ := read_oks[ k ]
if aStmt.Unit() != p.unit {
t.Errorf( "Expected \"%s\", got \"%s\" instead", p.unit, aStmt.Unit() )
}
}
}