58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package parsers
|
|
|
|
import (
|
|
// "fmt"
|
|
"testing"
|
|
engine "github.com/tgckpg/mmqlengine/mmql/engine"
|
|
stmtd "github.com/tgckpg/mmqlengine/mmql/statements"
|
|
)
|
|
|
|
func TestBuyStatement( t *testing.T ) {
|
|
lexer := engine.Lexer{}
|
|
supportedStmts := map[string] func( *engine.Lexer ) ( stmtd.IStatement, error ) {
|
|
"BUY": BuyStatement,
|
|
"AMOUNT": AmountStatement,
|
|
"FINANCIAL_INSTRUMENT": FinancialInstrumentStatement,
|
|
}
|
|
lexer.SupportedStmts = &supportedStmts
|
|
|
|
var stmt stmtd.OrderStatement
|
|
_stmt, err := lexer.Parse( "BUY 1 SHARES OF QQQ FOR 10 USD FROM \"MyBrokerAccount\"" )
|
|
if err != nil {
|
|
t.Error( err )
|
|
} else {
|
|
stmt = any( _stmt ).( stmtd.OrderStatement )
|
|
if stmt.Amount().Unit() != "SHARES" {
|
|
t.Errorf( "Expected 1 SHARES Amount, got \"%s\" Amount", stmt.Amount().Unit() )
|
|
}
|
|
}
|
|
|
|
_stmt, err = lexer.Parse( "BUY 1 QQQ FOR MARKET_PRICE() FROM \"MyBrokerAccount\"" )
|
|
if err != nil {
|
|
t.Error( err )
|
|
} else {
|
|
stmt = any( _stmt ).( stmtd.OrderStatement )
|
|
if stmt.Amount().Unit() != "UNITS" {
|
|
t.Errorf( "Expected 1 UNITS Amount, got \"%s\" Amount", stmt.Amount().Unit() )
|
|
}
|
|
}
|
|
|
|
_, err = lexer.Parse( "BUY 1 QQQ FOR 10 USD FROM \"MyBrokerAccount\"" )
|
|
if err != nil {
|
|
t.Error( err )
|
|
}
|
|
|
|
_, err = lexer.Parse( `
|
|
BUY 1 SHARES OF BTC_ETF
|
|
FOR 10 USD
|
|
FROM "MyBrokerAccount"
|
|
WITH LIMIT OF PURCHASING_POWER( "MyBrokerAccount", "QQQ" )
|
|
FOR EVERY
|
|
1 BTC OF USD_BTC SOLD
|
|
FROM "CoinBase"
|
|
` )
|
|
if err != nil {
|
|
t.Error( err )
|
|
}
|
|
}
|