Added more tests
This commit is contained in:
parent
d771708693
commit
cc66b02bf8
@ -61,7 +61,7 @@ func toASTNode(tokens token.List) (Node, error) {
|
||||
switch {
|
||||
case IsVariableDefinition(expr):
|
||||
if len(expr.Children) < 2 {
|
||||
return nil, errors.New(errors.MissingAssignValue, nil, expr.Token.End())
|
||||
return nil, errors.New(errors.MissingOperand, nil, expr.Token.End())
|
||||
}
|
||||
|
||||
name := expr.Children[0].Token
|
||||
@ -70,7 +70,7 @@ func toASTNode(tokens token.List) (Node, error) {
|
||||
|
||||
case IsAssignment(expr):
|
||||
if len(expr.Children) < 2 {
|
||||
return nil, errors.New(errors.MissingAssignValue, nil, expr.Token.End())
|
||||
return nil, errors.New(errors.MissingOperand, nil, expr.Token.End())
|
||||
}
|
||||
|
||||
name := expr.Children[0].Token
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"git.akyoto.dev/cli/q/src/build/asm"
|
||||
"git.akyoto.dev/cli/q/src/build/ast"
|
||||
"git.akyoto.dev/cli/q/src/build/cpu"
|
||||
"git.akyoto.dev/cli/q/src/build/errors"
|
||||
"git.akyoto.dev/cli/q/src/build/expression"
|
||||
)
|
||||
|
||||
@ -23,6 +24,10 @@ func (f *Function) ExpressionToRegister(node *expression.Expression, register cp
|
||||
return err
|
||||
}
|
||||
|
||||
if len(node.Children) < 2 {
|
||||
return errors.New(errors.MissingOperand, f.File, node.Token.End())
|
||||
}
|
||||
|
||||
left := node.Children[0]
|
||||
right := node.Children[1]
|
||||
final := register
|
||||
|
@ -3,7 +3,7 @@ package errors
|
||||
var (
|
||||
InvalidStatement = &Base{"Invalid statement"}
|
||||
InvalidExpression = &Base{"Invalid expression"}
|
||||
MissingAssignValue = &Base{"Missing assignment value"}
|
||||
MissingOperand = &Base{"Missing operand"}
|
||||
MissingMainFunction = &Base{"Missing main function"}
|
||||
NotImplemented = &Base{"Not implemented"}
|
||||
)
|
||||
|
3
tests/errors/InvalidInstructionExpression.q
Normal file
3
tests/errors/InvalidInstructionExpression.q
Normal file
@ -0,0 +1,3 @@
|
||||
main() {
|
||||
2+3
|
||||
}
|
3
tests/errors/MissingOperand2.q
Normal file
3
tests/errors/MissingOperand2.q
Normal file
@ -0,0 +1,3 @@
|
||||
main() {
|
||||
syscall(2+)
|
||||
}
|
@ -19,17 +19,19 @@ var errs = []struct {
|
||||
{"ExpectedFunctionParameters.q", errors.ExpectedFunctionParameters},
|
||||
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
|
||||
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},
|
||||
{"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "+"}},
|
||||
{"InvalidExpression.q", errors.InvalidExpression},
|
||||
{"InvalidOperator.q", &errors.InvalidOperator{Operator: "+++"}},
|
||||
{"InvalidCharacter.q", &errors.InvalidCharacter{Character: "@"}},
|
||||
{"InvalidCharacter2.q", &errors.InvalidCharacter{Character: "@"}},
|
||||
{"InvalidCharacter3.q", &errors.InvalidCharacter{Character: "@"}},
|
||||
{"MissingAssignValue.q", errors.MissingAssignValue},
|
||||
{"MissingBlockEnd.q", errors.MissingBlockEnd},
|
||||
{"MissingBlockStart.q", errors.MissingBlockStart},
|
||||
{"MissingGroupEnd.q", errors.MissingGroupEnd},
|
||||
{"MissingGroupStart.q", errors.MissingGroupStart},
|
||||
{"MissingMainFunction.q", errors.MissingMainFunction},
|
||||
{"MissingOperand.q", errors.MissingOperand},
|
||||
{"MissingOperand2.q", errors.MissingOperand},
|
||||
{"VariableAlreadyExists.q", &errors.VariableAlreadyExists{Name: "x"}},
|
||||
{"UnknownIdentifier.q", &errors.UnknownIdentifier{Name: "x"}},
|
||||
{"UnknownIdentifier2.q", &errors.UnknownIdentifier{Name: "x"}},
|
||||
|
Loading…
Reference in New Issue
Block a user