Test Failed
Branch master (4e8b13)
by Konrad
13:21
created

TurtleParserTest::testParseDecimals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 32
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 46
rs 9.408
1
<?php
2
3
/*
4
 * This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under
5
 * the terms of the GPL-3 license.
6
 *
7
 * (c) Konrad Abicht <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Tests\Integration\Parser;
14
15
use sweetrdf\InMemoryStoreSqlite\Log\Logger;
16
use sweetrdf\InMemoryStoreSqlite\NamespaceHelper;
17
use sweetrdf\InMemoryStoreSqlite\Parser\TurtleParser;
18
use sweetrdf\InMemoryStoreSqlite\StringReader;
19
use Tests\TestCase;
20
21
class TurtleParserTest extends TestCase
22
{
23
    private function getSubjectUnderTest(): TurtleParser
24
    {
25
        return new TurtleParser(new Logger(), new NamespaceHelper(), new StringReader());
26
    }
27
28
    /**
29
     * Demonstrates that parsing decimals works.
30
     *
31
     * @see https://github.com/sweetrdf/in-memory-store-sqlite/issues/8
32
     */
33
    public function testParseDecimals()
34
    {
35
        $sut = $this->getSubjectUnderTest();
36
37
        $data = '@prefix : <http://ex/> .
38
        :decimals :dec 1.0, 2.2, 0.1 .';
39
40
        $sut->parse('http://', $data);
41
42
        $this->assertEquals(
43
            [
44
                [
45
                    'type' => 'triple',
46
                    's' => 'http://ex/decimals',
47
                    's_type' => 'uri',
48
                    'p' => 'http://ex/dec',
49
                    'p_type' => 'uri',
50
                    'o' => '1.0',
51
                    'o_type' => 'literal',
52
                    'o_datatype' => 'http://www.w3.org/2001/XMLSchema#decimal',
53
                    'o_lang' => '',
54
                ],
55
                [
56
                    'type' => 'triple',
57
                    's' => 'http://ex/decimals',
58
                    's_type' => 'uri',
59
                    'p' => 'http://ex/dec',
60
                    'p_type' => 'uri',
61
                    'o' => '2.2',
62
                    'o_type' => 'literal',
63
                    'o_datatype' => 'http://www.w3.org/2001/XMLSchema#decimal',
64
                    'o_lang' => '',
65
                ],
66
                [
67
                    'type' => 'triple',
68
                    's' => 'http://ex/decimals',
69
                    's_type' => 'uri',
70
                    'p' => 'http://ex/dec',
71
                    'p_type' => 'uri',
72
                    'o' => '0.1',
73
                    'o_type' => 'literal',
74
                    'o_datatype' => 'http://www.w3.org/2001/XMLSchema#decimal',
75
                    'o_lang' => '',
76
                ],
77
            ],
78
            $sut->getTriples()
79
        );
80
    }
81
82
    /**
83
     * Test reusing StringReader instance.
84
     */
85
    public function testParseReusingStringReader()
86
    {
87
        $sut = $this->getSubjectUnderTest();
88
89
        /*
90
         * first run
91
         */
92
        $data = '@prefix : <http://ex/> .
93
        :decimals :dec 1.0, 2.2, 0.1 .';
94
95
        $sut->parse('http://', $data);
96
97
        $this->assertEquals(
98
            [
99
                'type' => 'triple',
100
                's' => 'http://ex/decimals',
101
                's_type' => 'uri',
102
                'p' => 'http://ex/dec',
103
                'p_type' => 'uri',
104
                'o' => '1.0',
105
                'o_type' => 'literal',
106
                'o_datatype' => 'http://www.w3.org/2001/XMLSchema#decimal',
107
                'o_lang' => '',
108
            ],
109
            $sut->getTriples()[0]
110
        );
111
112
        /*
113
         * second run
114
         */
115
        $data = '@prefix : <http://ex/> .
116
        :decimals :dec "foo", 0.42 .';
117
118
        $sut->parse('http://', $data);
119
120
        $this->assertEquals(
121
            [
122
                [
123
                    'type' => 'triple',
124
                    's' => 'http://ex/decimals',
125
                    's_type' => 'uri',
126
                    'p' => 'http://ex/dec',
127
                    'p_type' => 'uri',
128
                    'o' => 'foo',
129
                    'o_type' => 'literal',
130
                    'o_datatype' => '',
131
                    'o_lang' => '',
132
                ],
133
                [
134
                    'type' => 'triple',
135
                    's' => 'http://ex/decimals',
136
                    's_type' => 'uri',
137
                    'p' => 'http://ex/dec',
138
                    'p_type' => 'uri',
139
                    'o' => '0.42',
140
                    'o_type' => 'literal',
141
                    'o_datatype' => 'http://www.w3.org/2001/XMLSchema#decimal',
142
                    'o_lang' => '',
143
                ],
144
            ],
145
            $sut->getTriples()
146
        );
147
    }
148
}
149