Added more tests
This commit is contained in:
parent
4776b4c14c
commit
864c9c7b43
@ -18,6 +18,9 @@ func TestErrors(t *testing.T) {
|
|||||||
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
|
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
|
||||||
{"ExpectedFunctionName.q", errors.ExpectedFunctionName},
|
{"ExpectedFunctionName.q", errors.ExpectedFunctionName},
|
||||||
{"ExpectedFunctionParameters.q", errors.ExpectedFunctionParameters},
|
{"ExpectedFunctionParameters.q", errors.ExpectedFunctionParameters},
|
||||||
|
{"InvalidInstruction-Identifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
|
||||||
|
{"InvalidInstruction-Number.q", &errors.InvalidInstruction{Instruction: "123"}},
|
||||||
|
{"MissingAssignValue.q", errors.MissingAssignValue},
|
||||||
{"MissingBlockEnd.q", errors.MissingBlockEnd},
|
{"MissingBlockEnd.q", errors.MissingBlockEnd},
|
||||||
{"MissingBlockStart.q", errors.MissingBlockStart},
|
{"MissingBlockStart.q", errors.MissingBlockStart},
|
||||||
{"MissingGroupEnd.q", errors.MissingGroupEnd},
|
{"MissingGroupEnd.q", errors.MissingGroupEnd},
|
||||||
|
@ -113,17 +113,17 @@ func (f *Function) CompileInstruction(line token.List) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if line[0].Kind == token.Identifier {
|
|
||||||
if len(line) < 2 {
|
if len(line) < 2 {
|
||||||
return fmt.Errorf("error to be implemented")
|
return errors.New(&errors.InvalidInstruction{Instruction: line[0].Text()}, f.File, line[0].Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if line[0].Kind == token.Identifier {
|
||||||
if line[1].Kind == token.Define {
|
if line[1].Kind == token.Define {
|
||||||
name := line[0].Text()
|
name := line[0].Text()
|
||||||
value := line[2:]
|
value := line[2:]
|
||||||
|
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
return errors.New(errors.MissingAssignmentValue, f.File, line[1].After())
|
return errors.New(errors.MissingAssignValue, f.File, line[1].After())
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Verbose {
|
if config.Verbose {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package errors
|
package errors
|
||||||
|
|
||||||
var (
|
var (
|
||||||
MissingAssignmentValue = &Base{"Missing assignment value"}
|
InvalidStatement = &Base{"Invalid statement"}
|
||||||
|
MissingAssignValue = &Base{"Missing assignment value"}
|
||||||
)
|
)
|
||||||
|
13
src/errors/InvalidInstruction.go
Normal file
13
src/errors/InvalidInstruction.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package errors
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// InvalidInstruction error is created when an instruction is not valid.
|
||||||
|
type InvalidInstruction struct {
|
||||||
|
Instruction string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error generates the string representation.
|
||||||
|
func (err *InvalidInstruction) Error() string {
|
||||||
|
return fmt.Sprintf("Invalid instruction '%s'", err.Instruction)
|
||||||
|
}
|
3
tests/errors/InvalidInstruction-Identifier.q
Normal file
3
tests/errors/InvalidInstruction-Identifier.q
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
main() {
|
||||||
|
abc
|
||||||
|
}
|
3
tests/errors/InvalidInstruction-Number.q
Normal file
3
tests/errors/InvalidInstruction-Number.q
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
main() {
|
||||||
|
123
|
||||||
|
}
|
3
tests/errors/MissingAssignValue.q
Normal file
3
tests/errors/MissingAssignValue.q
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
main() {
|
||||||
|
a :=
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user