Added more tests

This commit is contained in:
Eduard Urbach 2025-02-07 21:25:29 +01:00
parent 5fc9cc4dff
commit cba26d8154
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
5 changed files with 6 additions and 9 deletions

View File

@ -7,6 +7,7 @@ var (
ExpectedFunctionParameters = &Base{"Expected function parameters"}
ExpectedFunctionDefinition = &Base{"Expected function definition"}
ExpectedIfBeforeElse = &Base{"Expected an 'if' block before 'else'"}
ExpectedPackageName = &Base{"Expected package name"}
ExpectedStructName = &Base{"Expected struct name"}
InvalidNumber = &Base{"Invalid number"}
InvalidExpression = &Base{"Invalid expression"}

View File

@ -18,9 +18,8 @@ func Scan(files []string) (<-chan *fs.File, <-chan *core.Function, <-chan types.
errors: make(chan error),
}
scanner.queueDirectory(filepath.Join(config.Library, "mem"), "mem")
go func() {
scanner.queueDirectory(filepath.Join(config.Library, "mem"), "mem")
scanner.queue(files...)
scanner.group.Wait()
close(scanner.files)

View File

@ -4,6 +4,7 @@ import (
"path/filepath"
"git.akyoto.dev/cli/q/src/config"
"git.akyoto.dev/cli/q/src/errors"
"git.akyoto.dev/cli/q/src/fs"
"git.akyoto.dev/cli/q/src/token"
)
@ -13,7 +14,7 @@ func (s *Scanner) scanImport(file *fs.File, tokens token.List, i int) (int, erro
i++
if tokens[i].Kind != token.Identifier {
panic("expected package name")
return i, errors.New(errors.ExpectedPackageName, file, tokens[i].Position)
}
packageName := tokens[i].Text(file.Bytes)
@ -31,11 +32,5 @@ func (s *Scanner) scanImport(file *fs.File, tokens token.List, i int) (int, erro
}
s.queueDirectory(fullPath, packageName)
i++
if tokens[i].Kind != token.NewLine && tokens[i].Kind != token.EOF {
panic("expected newline or eof")
}
return i, nil
}

View File

@ -0,0 +1 @@
import

View File

@ -20,6 +20,7 @@ var errs = []struct {
{"ExpectedIfBeforeElse.q", errors.ExpectedIfBeforeElse},
{"ExpectedIfBeforeElse2.q", errors.ExpectedIfBeforeElse},
{"ExpectedStructName.q", errors.ExpectedStructName},
{"ExpectedPackageName.q", errors.ExpectedPackageName},
{"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "+"}},
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},