58 lines
2.2 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-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},
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},
{"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-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-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())
})
}
}