2024-07-03 09:39:24 +00:00
|
|
|
package tests_test
|
2024-06-13 10:13:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.akyoto.dev/cli/q/src/build"
|
2024-07-03 09:39:24 +00:00
|
|
|
"git.akyoto.dev/cli/q/src/build/errors"
|
2024-06-13 10:13:32 +00:00
|
|
|
"git.akyoto.dev/go/assert"
|
|
|
|
)
|
|
|
|
|
2024-07-03 09:59:36 +00:00
|
|
|
var errs = []struct {
|
|
|
|
File string
|
|
|
|
ExpectedError error
|
|
|
|
}{
|
|
|
|
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
|
|
|
|
{"ExpectedFunctionName.q", errors.ExpectedFunctionName},
|
|
|
|
{"ExpectedFunctionParameters.q", errors.ExpectedFunctionParameters},
|
|
|
|
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
|
|
|
|
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},
|
|
|
|
{"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},
|
|
|
|
{"VariableAlreadyExists.q", &errors.VariableAlreadyExists{Name: "x"}},
|
|
|
|
{"UnknownIdentifier.q", &errors.UnknownIdentifier{Name: "x"}},
|
|
|
|
{"UnknownIdentifier2.q", &errors.UnknownIdentifier{Name: "x"}},
|
|
|
|
{"UnusedVariable.q", &errors.UnusedVariable{Name: "x"}},
|
|
|
|
}
|
2024-06-13 10:13:32 +00:00
|
|
|
|
2024-07-03 09:59:36 +00:00
|
|
|
func TestErrors(t *testing.T) {
|
|
|
|
for _, test := range errs {
|
2024-06-13 10:13:32 +00:00
|
|
|
name := strings.TrimSuffix(test.File, ".q")
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2024-07-03 09:39:24 +00:00
|
|
|
b := build.New(filepath.Join("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())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|