2024-06-14 08:36:01 +00:00
|
|
|
package main_test
|
2024-06-13 10:13:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.akyoto.dev/cli/q/src/build"
|
|
|
|
"git.akyoto.dev/cli/q/src/errors"
|
|
|
|
"git.akyoto.dev/go/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrors(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
File string
|
|
|
|
ExpectedError error
|
|
|
|
}{
|
|
|
|
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
|
2024-06-14 08:36:01 +00:00
|
|
|
{"ExpectedFunctionName.q", errors.ExpectedFunctionName},
|
2024-06-14 07:23:21 +00:00
|
|
|
{"ExpectedFunctionParameters.q", errors.ExpectedFunctionParameters},
|
2024-06-21 20:16:42 +00:00
|
|
|
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
|
|
|
|
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},
|
2024-06-22 11:20:11 +00:00
|
|
|
{"InvalidExpression.q", errors.InvalidExpression},
|
2024-06-26 21:24:11 +00:00
|
|
|
{"InvalidOperator.q", &errors.InvalidOperator{Operator: "+++"}},
|
2024-06-15 18:25:37 +00:00
|
|
|
{"MissingAssignValue.q", errors.MissingAssignValue},
|
2024-06-14 07:23:21 +00:00
|
|
|
{"MissingBlockEnd.q", errors.MissingBlockEnd},
|
|
|
|
{"MissingBlockStart.q", errors.MissingBlockStart},
|
|
|
|
{"MissingGroupEnd.q", errors.MissingGroupEnd},
|
|
|
|
{"MissingGroupStart.q", errors.MissingGroupStart},
|
2024-06-27 15:36:45 +00:00
|
|
|
{"MissingMainFunction.q", errors.MissingMainFunction},
|
2024-06-26 21:24:11 +00:00
|
|
|
{"VariableAlreadyExists.q", &errors.VariableAlreadyExists{Name: "x"}},
|
2024-06-22 11:20:11 +00:00
|
|
|
{"UnknownIdentifier.q", &errors.UnknownIdentifier{Name: "x"}},
|
2024-06-22 18:18:13 +00:00
|
|
|
{"UnknownIdentifier2.q", &errors.UnknownIdentifier{Name: "x"}},
|
2024-06-13 10:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
name := strings.TrimSuffix(test.File, ".q")
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2024-06-14 08:36:01 +00:00
|
|
|
b := build.New(filepath.Join("tests", "errors", test.File))
|
2024-06-13 10:13:32 +00:00
|
|
|
_, err := b.Run()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Contains(t, err.Error(), test.ExpectedError.Error())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|