@@ 18-24 (lines=7) @@ | ||
15 | * @package Vlaswinkel\Lua\Tests |
|
16 | */ |
|
17 | class LuaTokenStreamTest extends \PHPUnit_Framework_TestCase { |
|
18 | public function testDoubleQuotedString() { |
|
19 | $obj = new TokenStream(new InputStream('"foo"')); |
|
20 | ||
21 | $token = $obj->next(); |
|
22 | $this->assertEquals(Token::TYPE_STRING, $token->getType()); |
|
23 | $this->assertEquals("foo", $token->getValue()); |
|
24 | } |
|
25 | ||
26 | public function testSingleQuotedString() { |
|
27 | $obj = new TokenStream(new InputStream("'foo'")); |
|
@@ 26-32 (lines=7) @@ | ||
23 | $this->assertEquals("foo", $token->getValue()); |
|
24 | } |
|
25 | ||
26 | public function testSingleQuotedString() { |
|
27 | $obj = new TokenStream(new InputStream("'foo'")); |
|
28 | ||
29 | $token = $obj->next(); |
|
30 | $this->assertEquals(Token::TYPE_STRING, $token->getType()); |
|
31 | $this->assertEquals("foo", $token->getValue()); |
|
32 | } |
|
33 | ||
34 | public function testNestedString() { |
|
35 | $obj = new TokenStream(new InputStream("[=[ Like this ]=]")); |
|
@@ 34-40 (lines=7) @@ | ||
31 | $this->assertEquals("foo", $token->getValue()); |
|
32 | } |
|
33 | ||
34 | public function testNestedString() { |
|
35 | $obj = new TokenStream(new InputStream("[=[ Like this ]=]")); |
|
36 | ||
37 | $token = $obj->next(); |
|
38 | $this->assertEquals(Token::TYPE_STRING, $token->getType()); |
|
39 | $this->assertEquals(' Like this ', $token->getValue()); |
|
40 | } |
|
41 | ||
42 | public function testEscapedString() { |
|
43 | $obj = new TokenStream(new InputStream('" test \n\r\t\v\\\\\""')); |
|
@@ 42-48 (lines=7) @@ | ||
39 | $this->assertEquals(' Like this ', $token->getValue()); |
|
40 | } |
|
41 | ||
42 | public function testEscapedString() { |
|
43 | $obj = new TokenStream(new InputStream('" test \n\r\t\v\\\\\""')); |
|
44 | ||
45 | $token = $obj->next(); |
|
46 | $this->assertEquals(Token::TYPE_STRING, $token->getType()); |
|
47 | $this->assertEquals(" test \n\r\t\v\\\"", $token->getValue()); |
|
48 | } |
|
49 | ||
50 | public function testOtherNestedString() { |
|
51 | $obj = new TokenStream(new InputStream('[=[one [[two]] one]=]')); |
|
@@ 50-56 (lines=7) @@ | ||
47 | $this->assertEquals(" test \n\r\t\v\\\"", $token->getValue()); |
|
48 | } |
|
49 | ||
50 | public function testOtherNestedString() { |
|
51 | $obj = new TokenStream(new InputStream('[=[one [[two]] one]=]')); |
|
52 | ||
53 | $token = $obj->next(); |
|
54 | $this->assertEquals(Token::TYPE_STRING, $token->getType()); |
|
55 | $this->assertEquals('one [[two]] one', $token->getValue()); |
|
56 | } |
|
57 | ||
58 | public function testNestedNestedString() { |
|
59 | $obj = new TokenStream(new InputStream('[=[one [==[two]==] one]=]')); |
|
@@ 58-64 (lines=7) @@ | ||
55 | $this->assertEquals('one [[two]] one', $token->getValue()); |
|
56 | } |
|
57 | ||
58 | public function testNestedNestedString() { |
|
59 | $obj = new TokenStream(new InputStream('[=[one [==[two]==] one]=]')); |
|
60 | ||
61 | $token = $obj->next(); |
|
62 | $this->assertEquals(Token::TYPE_STRING, $token->getType()); |
|
63 | $this->assertEquals('one [==[two]==] one', $token->getValue()); |
|
64 | } |
|
65 | ||
66 | public function testComplexNestedString() { |
|
67 | $obj = new TokenStream(new InputStream('[===[one [ [==[ one]===]')); |
|
@@ 66-72 (lines=7) @@ | ||
63 | $this->assertEquals('one [==[two]==] one', $token->getValue()); |
|
64 | } |
|
65 | ||
66 | public function testComplexNestedString() { |
|
67 | $obj = new TokenStream(new InputStream('[===[one [ [==[ one]===]')); |
|
68 | ||
69 | $token = $obj->next(); |
|
70 | $this->assertEquals(Token::TYPE_STRING, $token->getType()); |
|
71 | $this->assertEquals('one [ [==[ one', $token->getValue()); |
|
72 | } |
|
73 | ||
74 | public function testNumberInt() { |
|
75 | $obj = new TokenStream(new InputStream("1337")); |
|
@@ 74-80 (lines=7) @@ | ||
71 | $this->assertEquals('one [ [==[ one', $token->getValue()); |
|
72 | } |
|
73 | ||
74 | public function testNumberInt() { |
|
75 | $obj = new TokenStream(new InputStream("1337")); |
|
76 | ||
77 | $token = $obj->next(); |
|
78 | $this->assertEquals(Token::TYPE_NUMBER, $token->getType()); |
|
79 | $this->assertEquals(1337, $token->getValue()); |
|
80 | } |
|
81 | ||
82 | public function testNumberFloat() { |
|
83 | $obj = new TokenStream(new InputStream("13.37")); |
|
@@ 82-88 (lines=7) @@ | ||
79 | $this->assertEquals(1337, $token->getValue()); |
|
80 | } |
|
81 | ||
82 | public function testNumberFloat() { |
|
83 | $obj = new TokenStream(new InputStream("13.37")); |
|
84 | ||
85 | $token = $obj->next(); |
|
86 | $this->assertEquals(Token::TYPE_NUMBER, $token->getType()); |
|
87 | $this->assertEquals(13.37, $token->getValue()); |
|
88 | } |
|
89 | ||
90 | public function testPunctuation() { |
|
91 | foreach ([',', '{', '}', '=', '[', ']'] as $punc) { |
|
@@ 100-106 (lines=7) @@ | ||
97 | } |
|
98 | } |
|
99 | ||
100 | public function testIdentifier() { |
|
101 | $obj = new TokenStream(new InputStream("foo")); |
|
102 | ||
103 | $token = $obj->next(); |
|
104 | $this->assertEquals(Token::TYPE_IDENTIFIER, $token->getType()); |
|
105 | $this->assertEquals('foo', $token->getValue()); |
|
106 | } |
|
107 | ||
108 | public function testKeyword() { |
|
109 | foreach (Lua::$luaKeywords as $keyword) { |