1<?php
2
3/**
4 * Hoa
5 *
6 *
7 * @license
8 *
9 * New BSD License
10 *
11 * Copyright © 2007-2017, Hoa community. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 *     * Redistributions of source code must retain the above copyright
16 *       notice, this list of conditions and the following disclaimer.
17 *     * Redistributions in binary form must reproduce the above copyright
18 *       notice, this list of conditions and the following disclaimer in the
19 *       documentation and/or other materials provided with the distribution.
20 *     * Neither the name of the Hoa nor the names of its contributors may be
21 *       used to endorse or promote products derived from this software without
22 *       specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37namespace Hoa\Compiler\Test\Unit\Llk\Rule;
38
39use Hoa\Test;
40use Mock\Hoa\Compiler\Llk\Rule\Invocation as SUT;
41
42/**
43 * Class \Hoa\Compiler\Test\Unit\Llk\Rule\Invocation.
44 *
45 * Test suite of an invocation rule.
46 *
47 * @copyright  Copyright © 2007-2017 Hoa community
48 * @license    New BSD License
49 */
50class Invocation extends Test\Unit\Suite
51{
52    public function case_constructor()
53    {
54        $this
55            ->given(
56                $rule = 'foo',
57                $data = 'bar'
58            )
59            ->when($result = new SUT($rule, $data))
60            ->then
61                ->string($result->getRule())
62                    ->isEqualTo($rule)
63                ->string($result->getData())
64                    ->isEqualTo($data)
65                ->variable($result->getTodo())
66                    ->isNull()
67                ->integer($result->getDepth())
68                    ->isEqualTo(-1)
69                ->boolean($result->isTransitional())
70                    ->isFalse();
71    }
72
73    public function case_constructor_with_todo()
74    {
75        $this
76            ->given(
77                $rule = 'foo',
78                $data = 'bar',
79                $todo = ['baz', 'qux']
80            )
81            ->when($result = new SUT($rule, $data, $todo))
82            ->then
83                ->string($result->getRule())
84                    ->isEqualTo($rule)
85                ->string($result->getData())
86                    ->isEqualTo($data)
87                ->array($result->getTodo())
88                    ->isEqualTo($todo)
89                ->integer($result->getDepth())
90                    ->isEqualTo(-1)
91                ->boolean($result->isTransitional())
92                    ->isFalse();
93    }
94
95    public function case_constructor_with_todo_and_depth()
96    {
97        $this
98            ->given(
99                $rule  = 'foo',
100                $data  = 'bar',
101                $todo  = ['baz', 'qux'],
102                $depth = 42
103            )
104            ->when($result = new SUT($rule, $data, $todo, $depth))
105            ->then
106                ->string($result->getRule())
107                    ->isEqualTo($rule)
108                ->string($result->getData())
109                    ->isEqualTo($data)
110                ->array($result->getTodo())
111                    ->isEqualTo($todo)
112                ->integer($result->getDepth())
113                    ->isEqualTo($depth)
114                ->boolean($result->isTransitional())
115                    ->isFalse();
116    }
117
118    public function case_set_depth()
119    {
120        $this
121            ->given(
122                $rule       = 42,
123                $data       = 'bar',
124                $todo       = ['baz', 'qux'],
125                $depth      = 42,
126                $invocation = new SUT($rule, $data)
127            )
128            ->when($result = $invocation->setDepth($depth))
129            ->then
130                ->integer($result)
131                    ->isEqualTo(-1);
132    }
133
134    public function case_get_depth()
135    {
136        $this
137            ->given(
138                $rule       = 42,
139                $data       = 'bar',
140                $todo       = ['baz', 'qux'],
141                $depth      = 42,
142                $invocation = new SUT($rule, $data),
143                $invocation->setDepth($depth)
144            )
145            ->when($result = $invocation->getDepth())
146            ->then
147                ->integer($result)
148                    ->isEqualTo($depth);
149    }
150
151    public function case_is_transitional()
152    {
153        $this
154            ->given(
155                $rule       = 42,
156                $data       = 'bar',
157                $invocation = new SUT($rule, $data)
158            )
159            ->when($result = $invocation->isTransitional())
160            ->then
161                ->boolean($result)
162                    ->isTrue();
163    }
164}
165