1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Vlaswinkel\Lua\Tests; |
4
|
|
|
|
5
|
|
|
use Vlaswinkel\Lua\InputStream; |
6
|
|
|
use Vlaswinkel\Lua\LuaToPhpConverter; |
7
|
|
|
use Vlaswinkel\Lua\Parser; |
8
|
|
|
use Vlaswinkel\Lua\TokenStream; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class LuaToPhpConverterTest |
12
|
|
|
* |
13
|
|
|
* @author Koen Vlaswinkel <[email protected]> |
14
|
|
|
* @package Vlaswinkel\Lua\Tests |
15
|
|
|
*/ |
16
|
|
|
class LuaToPhpConverterTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
public function testString() { |
18
|
|
|
$parser = new Parser(new TokenStream(new InputStream('"foo"'))); |
19
|
|
|
|
20
|
|
|
$node = $parser->parse(); |
21
|
|
|
|
22
|
|
|
$this->assertEquals("foo", LuaToPhpConverter::convertToPhpValue($node)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testNumber() { |
26
|
|
|
$parser = new Parser(new TokenStream(new InputStream('1337'))); |
27
|
|
|
|
28
|
|
|
$node = $parser->parse(); |
29
|
|
|
|
30
|
|
|
$this->assertEquals(1337, LuaToPhpConverter::convertToPhpValue($node)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testNil() { |
34
|
|
|
$parser = new Parser(new TokenStream(new InputStream('nil'))); |
35
|
|
|
|
36
|
|
|
$node = $parser->parse(); |
37
|
|
|
|
38
|
|
|
$this->assertEquals(null, LuaToPhpConverter::convertToPhpValue($node)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function testSimpleTable() { |
42
|
|
|
$parser = new Parser(new TokenStream(new InputStream('{ foo = "bar" }'))); |
43
|
|
|
|
44
|
|
|
$node = $parser->parse(); |
45
|
|
|
|
46
|
|
|
$result = LuaToPhpConverter::convertToPhpValue($node); |
47
|
|
|
|
48
|
|
|
$this->assertEquals( |
49
|
|
|
[ |
50
|
|
|
'foo' => 'bar', |
51
|
|
|
], |
52
|
|
|
$result |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function testNestedTable() { |
57
|
|
|
$parser = new Parser(new TokenStream(new InputStream('{ foo = { "bar" = { 1337 } } }'))); |
58
|
|
|
|
59
|
|
|
$node = $parser->parse(); |
60
|
|
|
|
61
|
|
|
$result = LuaToPhpConverter::convertToPhpValue($node); |
62
|
|
|
|
63
|
|
|
$this->assertEquals( |
64
|
|
|
[ |
65
|
|
|
'foo' => [ |
66
|
|
|
'bar' => [ |
67
|
|
|
1337, |
68
|
|
|
], |
69
|
|
|
], |
70
|
|
|
], |
71
|
|
|
$result |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testEmptyTable() { |
76
|
|
|
$parser = new Parser(new TokenStream(new InputStream('{}'))); |
77
|
|
|
|
78
|
|
|
$node = $parser->parse(); |
79
|
|
|
|
80
|
|
|
$result = LuaToPhpConverter::convertToPhpValue($node); |
81
|
|
|
|
82
|
|
|
$this->assertEquals([], $result); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
View Code Duplication |
public function testSimpleTableWithComments() { |
86
|
|
|
$parser = new Parser(new TokenStream(new InputStream('{ |
87
|
|
|
foo = "bar" -- comment |
88
|
|
|
}'))); |
89
|
|
|
|
90
|
|
|
$node = $parser->parse(); |
91
|
|
|
|
92
|
|
|
$result = LuaToPhpConverter::convertToPhpValue($node); |
93
|
|
|
|
94
|
|
|
$this->assertEquals( |
95
|
|
|
[ |
96
|
|
|
'foo' => 'bar', |
97
|
|
|
], |
98
|
|
|
$result |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
} |