Added more tests
This commit is contained in:
parent
5fc9cc4dff
commit
cba26d8154
@ -7,6 +7,7 @@ var (
|
|||||||
ExpectedFunctionParameters = &Base{"Expected function parameters"}
|
ExpectedFunctionParameters = &Base{"Expected function parameters"}
|
||||||
ExpectedFunctionDefinition = &Base{"Expected function definition"}
|
ExpectedFunctionDefinition = &Base{"Expected function definition"}
|
||||||
ExpectedIfBeforeElse = &Base{"Expected an 'if' block before 'else'"}
|
ExpectedIfBeforeElse = &Base{"Expected an 'if' block before 'else'"}
|
||||||
|
ExpectedPackageName = &Base{"Expected package name"}
|
||||||
ExpectedStructName = &Base{"Expected struct name"}
|
ExpectedStructName = &Base{"Expected struct name"}
|
||||||
InvalidNumber = &Base{"Invalid number"}
|
InvalidNumber = &Base{"Invalid number"}
|
||||||
InvalidExpression = &Base{"Invalid expression"}
|
InvalidExpression = &Base{"Invalid expression"}
|
||||||
|
@ -18,9 +18,8 @@ func Scan(files []string) (<-chan *fs.File, <-chan *core.Function, <-chan types.
|
|||||||
errors: make(chan error),
|
errors: make(chan error),
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner.queueDirectory(filepath.Join(config.Library, "mem"), "mem")
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
scanner.queueDirectory(filepath.Join(config.Library, "mem"), "mem")
|
||||||
scanner.queue(files...)
|
scanner.queue(files...)
|
||||||
scanner.group.Wait()
|
scanner.group.Wait()
|
||||||
close(scanner.files)
|
close(scanner.files)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.akyoto.dev/cli/q/src/config"
|
"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/fs"
|
||||||
"git.akyoto.dev/cli/q/src/token"
|
"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++
|
i++
|
||||||
|
|
||||||
if tokens[i].Kind != token.Identifier {
|
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)
|
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)
|
s.queueDirectory(fullPath, packageName)
|
||||||
i++
|
|
||||||
|
|
||||||
if tokens[i].Kind != token.NewLine && tokens[i].Kind != token.EOF {
|
|
||||||
panic("expected newline or eof")
|
|
||||||
}
|
|
||||||
|
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
1
tests/errors/ExpectedPackageName.q
Normal file
1
tests/errors/ExpectedPackageName.q
Normal file
@ -0,0 +1 @@
|
|||||||
|
import
|
@ -20,6 +20,7 @@ var errs = []struct {
|
|||||||
{"ExpectedIfBeforeElse.q", errors.ExpectedIfBeforeElse},
|
{"ExpectedIfBeforeElse.q", errors.ExpectedIfBeforeElse},
|
||||||
{"ExpectedIfBeforeElse2.q", errors.ExpectedIfBeforeElse},
|
{"ExpectedIfBeforeElse2.q", errors.ExpectedIfBeforeElse},
|
||||||
{"ExpectedStructName.q", errors.ExpectedStructName},
|
{"ExpectedStructName.q", errors.ExpectedStructName},
|
||||||
|
{"ExpectedPackageName.q", errors.ExpectedPackageName},
|
||||||
{"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "+"}},
|
{"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "+"}},
|
||||||
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
|
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
|
||||||
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},
|
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user