-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathLexTest.php
72 lines (51 loc) · 2.32 KB
/
LexTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
use PHPUnit\Framework\TestCase;
final class LexTest extends TestCase{
private function lex_test($str, $tokens){
$obj = new iamcal\SQLParser();
$this->assertEquals($obj->lex($str), $tokens);
}
public function test_simple_word_tokens(){
$this->lex_test('hello world', array('hello', 'world'));
}
public function testWhitespace(){
$this->lex_test("foo bar", array("foo", "bar"));
$this->lex_test(" foo bar ", array("foo", "bar"));
$this->lex_test("\n\nfoo\tbar\n", array("foo", "bar"));
# with comments too
$this->lex_test("hello \nworld-- foo\nyeah", array('hello', 'world', 'yeah'));
}
public function testComments(){
$this->lex_test("foo -- bar", array("foo"));
$this->lex_test("foo --bar", array("foo"));
$this->lex_test("foo -- bar\n", array("foo"));
$this->lex_test("foo -- bar \n", array("foo"));
$this->lex_test("foo -- bar \n ", array("foo"));
$this->lex_test("foo/"."* hello *"."/ bar", array("foo", "bar"));
$this->lex_test("foo/"."*hello*"."/ bar", array("foo", "bar"));
$this->lex_test("foo/"."* hello \n world *"."/ bar", array("foo", "bar"));
$this->lex_test("foo/"."*hello \n world*"."/ bar", array("foo", "bar"));
$this->lex_test("foo/"."* hello", array("foo"));
$this->lex_test("foo/"."* hello *", array("foo"));
$this->lex_test("foo/"."* hello \n world", array("foo"));
}
public function testBacktickFields(){
$this->lex_test("hello `world` foo", array("hello", "`world`", "foo"));
$this->lex_test("hello `world` foo", array("hello", "`world`", "foo"));
# the token rules allow _anything_ inside backticks o_O
$this->lex_test("hello `world \n test` foo", array("hello", "`world \n test`", "foo"));
$this->lex_test("hello `foo bar\n baz", array("hello"));
}
public function testNumericLiterals(){
# normal cases
$this->lex_test("1 12 12.3 12.34", array("1", "12", "12.3", "12.34"));
# weird cases
$this->lex_test("12. 1. .3 .34", array("12.", "1.", ".3", ".34"));
}
public function testStrings(){
$this->lex_test("foo 'bar' baz", array("foo", "'bar'", "baz"));
$this->lex_test("foo 'bar \\' baz' qux", array("foo", "'bar \\' baz'", "qux"));
$this->lex_test("foo \"bar\" baz", array("foo", "\"bar\"", "baz"));
$this->lex_test("foo \"bar \\\" baz\" qux", array("foo", "\"bar \\\" baz\"", "qux"));
}
}