Skip to content

Commit

Permalink
lexer: expect EOL before EOF in all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zegl committed Jan 12, 2020
1 parent 54e8fc9 commit 02a7205
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions compiler/lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func TestLexerSimpleAdd(t *testing.T) {
{Type: IDENTIFIER, Val: "aa", Line: 1},
{Type: OPERATOR, Val: "+", Line: 1},
{Type: IDENTIFIER, Val: "b", Line: 1},
{Type: EOF, Val: ""},
{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand All @@ -33,7 +34,8 @@ func TestLexerSimpleAddWithNewlines(t *testing.T) {
{Type: OPERATOR, Val: "+", Line: 2},
{Type: IDENTIFIER, Val: "b", Line: 2},

{Type: EOF, Val: ""},
{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand All @@ -46,7 +48,9 @@ func TestLexerSimpleAddNumber(t *testing.T) {
{Type: IDENTIFIER, Val: "aa", Line: 1},
{Type: OPERATOR, Val: "+", Line: 1},
{Type: NUMBER, Val: "14", Line: 1},
{Type: EOF, Val: ""},

{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand All @@ -60,7 +64,9 @@ func TestLexerSimpleCall(t *testing.T) {
{Type: OPERATOR, Val: "(", Line: 1},
{Type: IDENTIFIER, Val: "bar", Line: 1},
{Type: OPERATOR, Val: ")", Line: 1},
{Type: EOF, Val: ""},

{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand All @@ -74,7 +80,9 @@ func TestLexerSimpleCallWithString(t *testing.T) {
{Type: OPERATOR, Val: "(", Line: 1},
{Type: STRING, Val: "bar", Line: 1},
{Type: OPERATOR, Val: ")", Line: 1},
{Type: EOF, Val: ""},

{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand All @@ -85,7 +93,8 @@ func TestString(t *testing.T) {

expected := []Item{
{Type: STRING, Val: "bar", Line: 1},
{Type: EOF, Val: ""},
{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand All @@ -96,7 +105,8 @@ func TestEscapedString(t *testing.T) {

expected := []Item{
{Type: STRING, Val: "bar\"", Line: 1},
{Type: EOF, Val: ""},
{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand All @@ -112,7 +122,8 @@ func TestLexerSimpleCallWithTwoStrings(t *testing.T) {
{Type: OPERATOR, Val: ",", Line: 1},
{Type: STRING, Val: "baz", Line: 1},
{Type: OPERATOR, Val: ")", Line: 1},
{Type: EOF, Val: ""},
{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand All @@ -128,7 +139,8 @@ func TestLexerSimpleCallWithStringNum(t *testing.T) {
{Type: OPERATOR, Val: ",", Line: 1},
{Type: NUMBER, Val: "123", Line: 1},
{Type: OPERATOR, Val: ")", Line: 1},
{Type: EOF, Val: ""},
{Type: EOL},
{Type: EOF},
}

assert.Equal(t, expected, r)
Expand Down

0 comments on commit 02a7205

Please sign in to comment.