64 lines
2.6 KiB
Go
Raw Normal View History

2024-07-03 11:39:24 +02:00
package tests_test
2024-06-13 12:13:32 +02:00
import (
"path/filepath"
"strings"
"testing"
"git.akyoto.dev/cli/q/src/build"
2024-08-07 19:39:10 +02:00
"git.akyoto.dev/cli/q/src/errors"
2024-06-13 12:13:32 +02:00
"git.akyoto.dev/go/assert"
)
2024-07-03 11:59:36 +02:00
var errs = []struct {
File string
ExpectedError error
}{
2024-08-03 23:05:09 +02:00
{"EmptySwitch.q", errors.EmptySwitch},
2024-07-03 11:59:36 +02:00
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
{"ExpectedFunctionName.q", errors.ExpectedFunctionName},
2024-08-11 14:00:51 +02:00
{"ExpectedFunctionName2.q", errors.ExpectedFunctionName},
2024-07-03 11:59:36 +02:00
{"ExpectedFunctionParameters.q", errors.ExpectedFunctionParameters},
2024-07-30 16:36:33 +02:00
{"ExpectedIfBeforeElse.q", errors.ExpectedIfBeforeElse},
{"ExpectedIfBeforeElse2.q", errors.ExpectedIfBeforeElse},
2024-07-03 11:59:36 +02:00
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},
2024-07-05 17:11:30 +02:00
{"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "+"}},
2024-07-03 11:59:36 +02:00
{"InvalidExpression.q", errors.InvalidExpression},
{"InvalidCharacter.q", &errors.InvalidCharacter{Character: "@"}},
{"InvalidCharacter2.q", &errors.InvalidCharacter{Character: "@"}},
{"InvalidCharacter3.q", &errors.InvalidCharacter{Character: "@"}},
2024-07-21 14:35:06 +02:00
{"InvalidCharacter4.q", &errors.InvalidCharacter{Character: "+++"}},
2024-07-03 11:59:36 +02:00
{"MissingBlockEnd.q", errors.MissingBlockEnd},
2024-08-11 14:00:51 +02:00
{"MissingBlockEnd2.q", errors.MissingBlockEnd},
2024-07-03 11:59:36 +02:00
{"MissingBlockStart.q", errors.MissingBlockStart},
{"MissingGroupEnd.q", errors.MissingGroupEnd},
{"MissingGroupStart.q", errors.MissingGroupStart},
{"MissingMainFunction.q", errors.MissingMainFunction},
2024-07-05 17:11:30 +02:00
{"MissingOperand.q", errors.MissingOperand},
{"MissingOperand2.q", errors.MissingOperand},
2024-07-03 11:59:36 +02:00
{"VariableAlreadyExists.q", &errors.VariableAlreadyExists{Name: "x"}},
2024-08-08 12:55:25 +02:00
{"TypeMismatch.q", &errors.TypeMismatch{Expected: "Pointer", Encountered: "Int64", ParameterName: "p"}},
2024-07-07 17:13:22 +02:00
{"UnknownFunction.q", &errors.UnknownFunction{Name: "unknown"}},
2024-07-18 21:10:27 +02:00
{"UnknownFunction2.q", &errors.UnknownFunction{Name: "f"}},
2024-07-03 11:59:36 +02:00
{"UnknownIdentifier.q", &errors.UnknownIdentifier{Name: "x"}},
{"UnknownIdentifier2.q", &errors.UnknownIdentifier{Name: "x"}},
2024-07-18 21:10:27 +02:00
{"UnknownIdentifier3.q", &errors.UnknownIdentifier{Name: "x"}},
2024-07-31 11:55:21 +02:00
{"UnknownPackage.q", &errors.UnknownPackage{Name: "sys"}},
{"UnusedImport.q", &errors.UnusedImport{Package: "sys"}},
2024-07-03 11:59:36 +02:00
{"UnusedVariable.q", &errors.UnusedVariable{Name: "x"}},
}
2024-06-13 12:13:32 +02:00
2024-07-03 11:59:36 +02:00
func TestErrors(t *testing.T) {
for _, test := range errs {
2024-06-13 12:13:32 +02:00
name := strings.TrimSuffix(test.File, ".q")
t.Run(name, func(t *testing.T) {
2024-07-03 11:39:24 +02:00
b := build.New(filepath.Join("errors", test.File))
2024-06-13 12:13:32 +02:00
_, err := b.Run()
assert.NotNil(t, err)
assert.Contains(t, err.Error(), test.ExpectedError.Error())
})
}
}