aboutsummaryrefslogtreecommitdiff
path: root/spec/lexer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lexer_test.go')
-rw-r--r--spec/lexer_test.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/spec/lexer_test.go b/spec/lexer_test.go
index c3540f6..43b192f 100644
--- a/spec/lexer_test.go
+++ b/spec/lexer_test.go
@@ -40,11 +40,11 @@ func TestLexer_Run(t *testing.T) {
}{
{
caption: "the lexer can recognize all kinds of tokens",
- src: `id"terminal"'.*+?|()[\':|;#()$1...#%`,
+ src: `id"terminal"'string':|;#()$1...#%`,
tokens: []*token{
idTok("id"),
termPatTok("terminal"),
- strTok(`.*+?|()[\`),
+ strTok(`string`),
symTok(tokenKindColon),
symTok(tokenKindOr),
symTok(tokenKindSemicolon),
@@ -66,7 +66,7 @@ func TestLexer_Run(t *testing.T) {
},
},
{
- caption: "the lexer can recognize character sequences and escape sequences in terminal",
+ caption: "the lexer can recognize character sequences and escape sequences in a terminal",
src: `"abc\"\\"`,
tokens: []*token{
termPatTok(`abc"\\`),
@@ -74,14 +74,22 @@ func TestLexer_Run(t *testing.T) {
},
},
{
+ caption: "the lexer can recognize character sequences and escape sequences in a string literal",
+ src: `'.*+?|()[\'\\'`,
+ tokens: []*token{
+ strTok(`.*+?|()['\`),
+ newEOFToken(),
+ },
+ },
+ {
caption: "a pattern must include at least one character",
src: `""`,
err: synErrEmptyPattern,
},
{
- caption: "a literal pattern must include at least one character",
+ caption: "a string must include at least one character",
src: `''`,
- err: synErrEmptyPattern,
+ err: synErrEmptyString,
},
{
caption: "the lexer can recognize newlines and combine consecutive newlines into one",
@@ -126,11 +134,21 @@ bar // This is the fourth comment.
err: synErrUnclosedTerminal,
},
{
- caption: "an incompleted terminal is not a valid token",
+ caption: "an incompleted terminal in a pattern is not a valid token",
src: `"\`,
err: synErrIncompletedEscSeq,
},
{
+ caption: "an unclosed string is not a valid token",
+ src: `'abc`,
+ err: synErrUnclosedString,
+ },
+ {
+ caption: "an incompleted terminal in a string is not a valid token",
+ src: `'\`,
+ err: synErrIncompletedEscSeq,
+ },
+ {
caption: "a position must be greater than or equal to 1",
src: `$0`,
err: synErrZeroPos,