include the Lox namespace in the tests

FossilOrigin-Name: b0ce55428125806e15bcb0299cdedd7436726ee392495c6fe85c2ca181cb0b67
private
alpha 2 years ago
parent bdba0d03ff
commit 5033f48af8

@ -1,4 +1,5 @@
require "lox" require "lox"
include Lox
require "open3" require "open3"
@ -22,8 +23,8 @@ class TestRunner < Minitest::Test
end end
def test_returns_tokens def test_returns_tokens
scanner = Mocktail.of(Lox::Scanner) scanner = Mocktail.of(Scanner)
runner = Lox::Runner.new(scanner:) runner = Runner.new(scanner:)
stubs { scanner.scan("src") }.with { %w[ some tokens ] } stubs { scanner.scan("src") }.with { %w[ some tokens ] }
tokens = runner.run("src") tokens = runner.run("src")
@ -34,7 +35,7 @@ end
class TestScanner < Minitest::Test class TestScanner < Minitest::Test
def setup def setup
@scanner = Lox::Scanner.new @scanner = Scanner.new
end end
def test_basic_tokens def test_basic_tokens
@ -81,36 +82,36 @@ class TestScanner < Minitest::Test
def test_strings def test_strings
assert_equal [ assert_equal [
Lox::Token.new(:STRING, '""', "", 1), Token.new(:STRING, '""', "", 1),
Lox::Token.new(:EOF, "", nil, 1), Token.new(:EOF, "", nil, 1),
], @scanner.scan('""') ], @scanner.scan('""')
assert_equal [Lox::Token.new(:EOF, "", nil, 1)], @scanner.scan('"') # TODO test the error once it's exposed assert_equal [Token.new(:EOF, "", nil, 1)], @scanner.scan('"') # TODO test the error once it's exposed
assert_equal [ assert_equal [
Lox::Token.new(:STRING, '"foo"', "foo", 1), Token.new(:STRING, '"foo"', "foo", 1),
Lox::Token.new(:EOF, "", nil, 1), Token.new(:EOF, "", nil, 1),
], @scanner.scan('"foo"') ], @scanner.scan('"foo"')
assert_equal [ assert_equal [
Lox::Token.new(:STRING, "\"foo\nbar\"", "foo\nbar", 2), Token.new(:STRING, "\"foo\nbar\"", "foo\nbar", 2),
Lox::Token.new(:EOF, "", nil, 2), Token.new(:EOF, "", nil, 2),
], @scanner.scan("\"foo\nbar\"") ], @scanner.scan("\"foo\nbar\"")
end end
def test_numbers def test_numbers
assert_equal [ assert_equal [
Lox::Token.new(:NUMBER, "123", 123.0, 1), Token.new(:NUMBER, "123", 123.0, 1),
Lox::Token.new(:NUMBER, "123.4", 123.4, 1), Token.new(:NUMBER, "123.4", 123.4, 1),
Lox::Token.new(:EOF, "", nil, 1), Token.new(:EOF, "", nil, 1),
], @scanner.scan("123 123.4") ], @scanner.scan("123 123.4")
end end
def test_identifiers def test_identifiers
assert_equal [ assert_equal [
Lox::Token.new(:OR, "or", nil, 1), Token.new(:OR, "or", nil, 1),
Lox::Token.new(:IDENTIFIER, "orchid", nil, 1), Token.new(:IDENTIFIER, "orchid", nil, 1),
Lox::Token.new(:EOF, "", nil, 1), Token.new(:EOF, "", nil, 1),
], @scanner.scan("or orchid") ], @scanner.scan("or orchid")
end end
@ -123,11 +124,11 @@ class TestScanner < Minitest::Test
SRC SRC
assert_equal [ assert_equal [
Lox::Token.new(:IDENTIFIER, "foo", nil, 1), Token.new(:IDENTIFIER, "foo", nil, 1),
Lox::Token.new(:IDENTIFIER, "bar", nil, 4), Token.new(:IDENTIFIER, "bar", nil, 4),
Lox::Token.new(:EOF, "", nil, 5), Token.new(:EOF, "", nil, 5),
], tokens ], tokens
assert_equal [Lox::Token.new(:EOF, "", nil, 1)], @scanner.scan("/*") assert_equal [Token.new(:EOF, "", nil, 1)], @scanner.scan("/*")
end end
end end

Loading…
Cancel
Save