Added more tests

This commit is contained in:
Eduard Urbach 2024-06-15 20:25:37 +02:00
parent 4776b4c14c
commit 864c9c7b43
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
7 changed files with 32 additions and 6 deletions

View File

@ -18,6 +18,9 @@ func TestErrors(t *testing.T) {
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
{"ExpectedFunctionName.q", errors.ExpectedFunctionName},
{"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},
{"MissingBlockStart.q", errors.MissingBlockStart},
{"MissingGroupEnd.q", errors.MissingGroupEnd},

View File

@ -113,17 +113,17 @@ func (f *Function) CompileInstruction(line token.List) error {
return nil
}
if line[0].Kind == token.Identifier {
if len(line) < 2 {
return fmt.Errorf("error to be implemented")
}
if len(line) < 2 {
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 {
name := line[0].Text()
value := line[2:]
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 {

View File

@ -1,5 +1,6 @@
package errors
var (
MissingAssignmentValue = &Base{"Missing assignment value"}
InvalidStatement = &Base{"Invalid statement"}
MissingAssignValue = &Base{"Missing assignment value"}
)

View 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)
}

View File

@ -0,0 +1,3 @@
main() {
abc
}

View File

@ -0,0 +1,3 @@
main() {
123
}

View File

@ -0,0 +1,3 @@
main() {
a :=
}