forgot to implement EOF

FossilOrigin-Name: 50d7151680c89f48391b656b1a7d91d5beb885126e9aff05c68a78f15ddf405d
private
alpha 2 years ago
parent a4163b0e49
commit bdba0d03ff

@ -125,6 +125,7 @@ module Lox
end
end
state.add_token(:EOF, text: "")
state.tokens
end

@ -57,7 +57,7 @@ class TestScanner < Minitest::Test
>= GREATER_EQUAL
> GREATER
/ SLASH].each_slice(2).to_h.transform_values(&:to_sym).each do |str, token_type|
assert_equal [token_type.to_sym], @scanner.scan(str).map(&:type)
assert_equal token_type.to_sym, @scanner.scan(str)[0].type
end
end
@ -67,7 +67,7 @@ class TestScanner < Minitest::Test
.
SRC
assert_equal %i[LEFT_PAREN RIGHT_PAREN DOT], tokens.map(&:type)
assert_equal %i[LEFT_PAREN RIGHT_PAREN DOT EOF], tokens.map(&:type)
end
def test_line_numbers
@ -76,20 +76,33 @@ class TestScanner < Minitest::Test
)
SRC
assert_equal [1, 2], tokens.map(&:line)
assert_equal [1, 2, 3], tokens.map(&:line)
end
def test_strings
assert_equal [Lox::Token.new(:STRING, '""', "", 1)], @scanner.scan('""')
assert_equal [], @scanner.scan('"') # TODO test the error once it's exposed
assert_equal [Lox::Token.new(:STRING, '"foo"', "foo", 1)], @scanner.scan('"foo"')
assert_equal [Lox::Token.new(:STRING, "\"foo\nbar\"", "foo\nbar", 2)], @scanner.scan("\"foo\nbar\"")
assert_equal [
Lox::Token.new(:STRING, '""', "", 1),
Lox::Token.new(:EOF, "", nil, 1),
], @scanner.scan('""')
assert_equal [Lox::Token.new(:EOF, "", nil, 1)], @scanner.scan('"') # TODO test the error once it's exposed
assert_equal [
Lox::Token.new(:STRING, '"foo"', "foo", 1),
Lox::Token.new(:EOF, "", nil, 1),
], @scanner.scan('"foo"')
assert_equal [
Lox::Token.new(:STRING, "\"foo\nbar\"", "foo\nbar", 2),
Lox::Token.new(:EOF, "", nil, 2),
], @scanner.scan("\"foo\nbar\"")
end
def test_numbers
assert_equal [
Lox::Token.new(:NUMBER, "123", 123.0, 1),
Lox::Token.new(:NUMBER, "123.4", 123.4, 1),
Lox::Token.new(:EOF, "", nil, 1),
], @scanner.scan("123 123.4")
end
@ -97,6 +110,7 @@ class TestScanner < Minitest::Test
assert_equal [
Lox::Token.new(:OR, "or", nil, 1),
Lox::Token.new(:IDENTIFIER, "orchid", nil, 1),
Lox::Token.new(:EOF, "", nil, 1),
], @scanner.scan("or orchid")
end
@ -111,8 +125,9 @@ class TestScanner < Minitest::Test
assert_equal [
Lox::Token.new(:IDENTIFIER, "foo", nil, 1),
Lox::Token.new(:IDENTIFIER, "bar", nil, 4),
Lox::Token.new(:EOF, "", nil, 5),
], tokens
assert_equal [], @scanner.scan("/*")
assert_equal [Lox::Token.new(:EOF, "", nil, 1)], @scanner.scan("/*")
end
end

Loading…
Cancel
Save