64 lines
2.6 KiB
Go
Raw Normal View History

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-08-07 17:39:10 +00:00
"git.akyoto.dev/cli/q/src/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
}{
2024-08-03 21:05:09 +00:00
{"EmptySwitch.q", errors.EmptySwitch},
2024-07-03 09:59:36 +00:00
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
{"ExpectedFunctionName.q", errors.ExpectedFunctionName},
2024-08-11 12:00:51 +00:00
{"ExpectedFunctionName2.q", errors.ExpectedFunctionName},
2024-07-03 09:59:36 +00:00
{"ExpectedFunctionParameters.q", errors.ExpectedFunctionParameters},
2024-07-30 14:36:33 +00:00
{"ExpectedIfBeforeElse.q", errors.ExpectedIfBeforeElse},
{"ExpectedIfBeforeElse2.q", errors.ExpectedIfBeforeElse},
2024-07-03 09:59:36 +00:00
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},
2024-07-05 15:11:30 +00:00
{"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "+"}},
2024-07-03 09:59:36 +00:00
{"InvalidExpression.q", errors.InvalidExpression},
{"InvalidCharacter.q", &errors.InvalidCharacter{Character: "@"}},
{"InvalidCharacter2.q", &errors.InvalidCharacter{Character: "@"}},
{"InvalidCharacter3.q", &errors.InvalidCharacter{Character: "@"}},
2024-07-21 12:35:06 +00:00
{"InvalidCharacter4.q", &errors.InvalidCharacter{Character: "+++"}},
2024-07-03 09:59:36 +00:00
{"MissingBlockEnd.q", errors.MissingBlockEnd},
2024-08-11 12:00:51 +00:00
{"MissingBlockEnd2.q", errors.MissingBlockEnd},
2024-07-03 09:59:36 +00:00
{"MissingBlockStart.q", errors.MissingBlockStart},
{"MissingGroupEnd.q", errors.MissingGroupEnd},
{"MissingGroupStart.q", errors.MissingGroupStart},
{"MissingMainFunction.q", errors.MissingMainFunction},
2024-07-05 15:11:30 +00:00
{"MissingOperand.q", errors.MissingOperand},
{"MissingOperand2.q", errors.MissingOperand},
2024-07-03 09:59:36 +00:00
{"VariableAlreadyExists.q", &errors.VariableAlreadyExists{Name: "x"}},
2024-08-08 10:55:25 +00:00
{"TypeMismatch.q", &errors.TypeMismatch{Expected: "Pointer", Encountered: "Int64", ParameterName: "p"}},
2024-07-07 15:13:22 +00:00
{"UnknownFunction.q", &errors.UnknownFunction{Name: "unknown"}},
2024-07-18 19:10:27 +00:00
{"UnknownFunction2.q", &errors.UnknownFunction{Name: "f"}},
2024-07-03 09:59:36 +00:00
{"UnknownIdentifier.q", &errors.UnknownIdentifier{Name: "x"}},
{"UnknownIdentifier2.q", &errors.UnknownIdentifier{Name: "x"}},
2024-07-18 19:10:27 +00:00
{"UnknownIdentifier3.q", &errors.UnknownIdentifier{Name: "x"}},
2024-07-31 09:55:21 +00:00
{"UnknownPackage.q", &errors.UnknownPackage{Name: "sys"}},
{"UnusedImport.q", &errors.UnusedImport{Package: "sys"}},
2024-07-03 09:59:36 +00:00
{"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())
})
}
}