Test Setup Failed
Branch master (d251e3)
by Koen
02:30
created

LuaTokenStreamTest::testInvalidCharacter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * LuaTokenStreamTest.php
4
 *
5
 * @author Koen Vlaswinkel <[email protected]>
6
 * @since  21/12/2015 17:19
7
 */
8
9
namespace Vlaswinkel\Lua\Tests;
10
11
use Vlaswinkel\Lua\Lua;
12
use Vlaswinkel\Lua\LuaInputStream;
13
use Vlaswinkel\Lua\LuaToken;
14
use Vlaswinkel\Lua\LuaTokenStream;
15
16
class LuaTokenStreamTest extends \PHPUnit_Framework_TestCase {
17 View Code Duplication
    public function testDoubleQuotedString() {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
        $obj = new LuaTokenStream(new LuaInputStream('"foo"'));
19
20
        $token = $obj->next();
21
        $this->assertEquals(LuaToken::TYPE_STRING, $token->getType());
22
        $this->assertEquals("foo", $token->getValue());
23
    }
24
25 View Code Duplication
    public function testSingleQuotedString() {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
        $obj = new LuaTokenStream(new LuaInputStream("'foo'"));
27
28
        $token = $obj->next();
29
        $this->assertEquals(LuaToken::TYPE_STRING, $token->getType());
30
        $this->assertEquals("foo", $token->getValue());
31
    }
32
33 View Code Duplication
    public function testNumberInt() {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
        $obj = new LuaTokenStream(new LuaInputStream("1337"));
35
36
        $token = $obj->next();
37
        $this->assertEquals(LuaToken::TYPE_NUMBER, $token->getType());
38
        $this->assertEquals(1337, $token->getValue());
39
    }
40
41 View Code Duplication
    public function testNumberFloat() {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
        $obj = new LuaTokenStream(new LuaInputStream("13.37"));
43
44
        $token = $obj->next();
45
        $this->assertEquals(LuaToken::TYPE_NUMBER, $token->getType());
46
        $this->assertEquals(13.37, $token->getValue());
47
    }
48
49
    public function testPunctuation() {
50
        foreach ([',', '{', '}', '=', '[', ']'] as $punc) {
51
            $obj = new LuaTokenStream(new LuaInputStream($punc));
52
53
            $token = $obj->next();
54
            $this->assertEquals(LuaToken::TYPE_PUNCTUATION, $token->getType());
55
            $this->assertEquals($punc, $token->getValue());
56
        }
57
    }
58
59 View Code Duplication
    public function testIdentifier() {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
        $obj = new LuaTokenStream(new LuaInputStream("foo"));
61
62
        $token = $obj->next();
63
        $this->assertEquals(LuaToken::TYPE_IDENTIFIER, $token->getType());
64
        $this->assertEquals('foo', $token->getValue());
65
    }
66
67
    public function testKeyword() {
68
        foreach (Lua::$luaKeywords as $keyword) {
69
            $obj = new LuaTokenStream(new LuaInputStream($keyword));
70
71
            $token = $obj->next();
72
            $this->assertEquals(LuaToken::TYPE_KEYWORD, $token->getType());
73
            $this->assertEquals($keyword, $token->getValue());
74
        }
75
    }
76
77
    /**
78
     * @expectedException \Vlaswinkel\Lua\LuaParseException
79
     * @expectedExceptionMessage Cannot handle character: * (ord: 42)
80
     */
81
    public function testInvalidCharacter() {
82
        $obj = new LuaTokenStream(new LuaInputStream("*"));
83
84
        $obj->next();
85
    }
86
}