Skip to content

Commit 1134321

Browse files
committed
more lexer tests
1 parent 2595b26 commit 1134321

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

tests/LexTest.php

+49-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,56 @@ public function test_simple_word_tokens(){
1414
$this->lex_test('hello world', array('hello', 'world'));
1515
}
1616

17-
public function test_strip_comments_whitespace(){
17+
public function testWhitespace(){
1818

19+
$this->lex_test("foo bar", array("foo", "bar"));
20+
$this->lex_test(" foo bar ", array("foo", "bar"));
21+
$this->lex_test("\n\nfoo\tbar\n", array("foo", "bar"));
22+
23+
# with comments too
1924
$this->lex_test("hello \nworld-- foo\nyeah", array('hello', 'world', 'yeah'));
2025
}
26+
27+
public function testComments(){
28+
$this->lex_test("foo -- bar", array("foo"));
29+
$this->lex_test("foo --bar", array("foo"));
30+
$this->lex_test("foo -- bar\n", array("foo"));
31+
$this->lex_test("foo -- bar \n", array("foo"));
32+
$this->lex_test("foo -- bar \n ", array("foo"));
33+
34+
35+
$this->lex_test("foo/"."* hello *"."/ bar", array("foo", "bar"));
36+
$this->lex_test("foo/"."*hello*"."/ bar", array("foo", "bar"));
37+
$this->lex_test("foo/"."* hello \n world *"."/ bar", array("foo", "bar"));
38+
$this->lex_test("foo/"."*hello \n world*"."/ bar", array("foo", "bar"));
39+
}
40+
41+
public function testBacktickFields(){
42+
43+
$this->lex_test("hello `world` foo", array("hello", "`world`", "foo"));
44+
$this->lex_test("hello `world` foo", array("hello", "`world`", "foo"));
45+
46+
# the token rules allow _anything_ inside backticks o_O
47+
$this->lex_test("hello `world \n test` foo", array("hello", "`world \n test`", "foo"));
48+
49+
$this->lex_test("hello `foo bar\n baz", array("hello"));
50+
}
51+
52+
public function testNumericLiterals(){
53+
54+
# normal cases
55+
$this->lex_test("1 12 12.3 12.34", array("1", "12", "12.3", "12.34"));
56+
57+
# weird cases
58+
$this->lex_test("12. 1. .3 .34", array("12.", "1.", ".3", ".34"));
59+
}
60+
61+
public function testStrings(){
62+
63+
$this->lex_test("foo 'bar' baz", array("foo", "'bar'", "baz"));
64+
$this->lex_test("foo 'bar \\' baz' qux", array("foo", "'bar \\' baz'", "qux"));
65+
66+
$this->lex_test("foo \"bar\" baz", array("foo", "\"bar\"", "baz"));
67+
$this->lex_test("foo \"bar \\\" baz\" qux", array("foo", "\"bar \\\" baz\"", "qux"));
68+
}
2169
}

0 commit comments

Comments
 (0)