Skip to content

Commit 17930ea

Browse files
committed
Convert tests to use Assert DSL
1 parent 11d14b3 commit 17930ea

8 files changed

+78
-76
lines changed

src/main/php/text/StreamTokenizer.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ public function nextToken($delimiters= null) {
9090

9191
return array_shift($this->_stack);
9292
}
93-
}
93+
}

src/main/php/text/StringTokenizer.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php namespace text;
2-
32
/**
43
* A string tokenizer allows you to break a string into tokens,
54
* these being delimited by any character in the delimiter.
@@ -85,4 +84,4 @@ public function nextToken($delimiters= null) {
8584
}
8685
return array_shift($this->_stack);
8786
}
88-
}
87+
}

src/main/php/text/TextTokenizer.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php namespace text;
2-
2+
33
use io\IOException;
44
use io\streams\Reader;
55
use lang\IllegalStateException;
@@ -91,4 +91,4 @@ public function nextToken($delimiters= null) {
9191

9292
return array_shift($this->_stack);
9393
}
94-
}
94+
}

src/main/php/text/Tokenizer.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php namespace text;
2-
32
/**
43
* A tokenizer splits input strings into tokens.
54
*
@@ -67,4 +66,4 @@ public abstract function hasMoreTokens();
6766
* @return string
6867
*/
6968
public abstract function nextToken($delimiters= null);
70-
}
69+
}
Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace text\unittest;
22

3+
use unittest\Assert;
34
use unittest\{Ignore, Test, TestCase};
45

56
/**
@@ -9,7 +10,7 @@
910
* @see xp://net.xp_framework.unittest.text.StringTokenizerTest
1011
* @see xp://net.xp_framework.unittest.text.StreamTokenizerTest
1112
*/
12-
abstract class AbstractTokenizerTest extends TestCase {
13+
abstract class AbstractTokenizerTest {
1314

1415
/**
1516
* Retrieve a tokenizer instance
@@ -49,49 +50,49 @@ protected function allTokens($input, $delim) {
4950
#[Test]
5051
public function testSimpleString() {
5152
$t= $this->tokenizerInstance("Hello World!\nThis is an example", " \n");
52-
$this->assertEquals('Hello', $t->nextToken());
53-
$this->assertEquals('World!', $t->nextToken());
54-
$this->assertEquals('This', $t->nextToken());
55-
$this->assertEquals('is', $t->nextToken());
56-
$this->assertEquals('an', $t->nextToken());
57-
$this->assertEquals('example', $t->nextToken());
58-
$this->assertFalse($t->hasMoreTokens());
53+
Assert::equals('Hello', $t->nextToken());
54+
Assert::equals('World!', $t->nextToken());
55+
Assert::equals('This', $t->nextToken());
56+
Assert::equals('is', $t->nextToken());
57+
Assert::equals('an', $t->nextToken());
58+
Assert::equals('example', $t->nextToken());
59+
Assert::false($t->hasMoreTokens());
5960
}
6061

6162
#[Test]
6263
public function testSimpleStringWithDelims() {
6364
$t= $this->tokenizerInstance("Hello World!\nThis is an example", " \n", true);
64-
$this->assertEquals('Hello', $t->nextToken());
65-
$this->assertEquals(' ', $t->nextToken());
66-
$this->assertEquals('World!', $t->nextToken());
67-
$this->assertEquals("\n", $t->nextToken());
68-
$this->assertEquals('This', $t->nextToken());
69-
$this->assertEquals(' ', $t->nextToken());
70-
$this->assertEquals('is', $t->nextToken());
71-
$this->assertEquals(' ', $t->nextToken());
72-
$this->assertEquals('an', $t->nextToken());
73-
$this->assertEquals(' ', $t->nextToken());
74-
$this->assertEquals('example', $t->nextToken());
75-
$this->assertFalse($t->hasMoreTokens());
65+
Assert::equals('Hello', $t->nextToken());
66+
Assert::equals(' ', $t->nextToken());
67+
Assert::equals('World!', $t->nextToken());
68+
Assert::equals("\n", $t->nextToken());
69+
Assert::equals('This', $t->nextToken());
70+
Assert::equals(' ', $t->nextToken());
71+
Assert::equals('is', $t->nextToken());
72+
Assert::equals(' ', $t->nextToken());
73+
Assert::equals('an', $t->nextToken());
74+
Assert::equals(' ', $t->nextToken());
75+
Assert::equals('example', $t->nextToken());
76+
Assert::false($t->hasMoreTokens());
7677
}
7778

7879
#[Test]
7980
public function repetetiveDelimiters() {
8081
$t= $this->tokenizerInstance("Hello \nWorld!", " \n");
81-
$this->assertEquals('Hello', $t->nextToken());
82-
$this->assertEquals('', $t->nextToken());
83-
$this->assertEquals('World!', $t->nextToken());
84-
$this->assertFalse($t->hasMoreTokens());
82+
Assert::equals('Hello', $t->nextToken());
83+
Assert::equals('', $t->nextToken());
84+
Assert::equals('World!', $t->nextToken());
85+
Assert::false($t->hasMoreTokens());
8586
}
8687

8788
#[Test]
8889
public function repetetiveDelimitersWithDelims() {
8990
$t= $this->tokenizerInstance("Hello \nWorld!", " \n", true);
90-
$this->assertEquals('Hello', $t->nextToken());
91-
$this->assertEquals(' ', $t->nextToken());
92-
$this->assertEquals("\n", $t->nextToken());
93-
$this->assertEquals('World!', $t->nextToken());
94-
$this->assertFalse($t->hasMoreTokens());
91+
Assert::equals('Hello', $t->nextToken());
92+
Assert::equals(' ', $t->nextToken());
93+
Assert::equals("\n", $t->nextToken());
94+
Assert::equals('World!', $t->nextToken());
95+
Assert::false($t->hasMoreTokens());
9596
}
9697

9798
#[Test]
@@ -100,7 +101,7 @@ public function forIteration() {
100101
for ($t= $this->tokenizerInstance('A B C', ' '); $t->hasMoreTokens(); ) {
101102
$r[]= $t->nextToken();
102103
}
103-
$this->assertEquals(range('A', 'C'), $r);
104+
Assert::equals(range('A', 'C'), $r);
104105
}
105106

106107
#[Test]
@@ -110,7 +111,7 @@ public function whileIteration() {
110111
while ($t->hasMoreTokens()) {
111112
$r[]= $t->nextToken();
112113
}
113-
$this->assertEquals(range('A', 'C'), $r);
114+
Assert::equals(range('A', 'C'), $r);
114115
}
115116

116117
#[Test]
@@ -119,62 +120,62 @@ public function foreachIteration() {
119120
foreach ($this->tokenizerInstance('A B C', ' ') as $token) {
120121
$r[]= $token;
121122
}
122-
$this->assertEquals(range('A', 'C'), $r);
123+
Assert::equals(range('A', 'C'), $r);
123124
}
124125

125126
#[Test]
126127
public function reset() {
127128
$t= $this->tokenizerInstance('A B C', ' ');
128-
$this->assertTrue($t->hasMoreTokens());
129-
$this->assertEquals('A', $t->nextToken());
129+
Assert::true($t->hasMoreTokens());
130+
Assert::equals('A', $t->nextToken());
130131
$t->reset();
131-
$this->assertTrue($t->hasMoreTokens());
132-
$this->assertEquals('A', $t->nextToken());
132+
Assert::true($t->hasMoreTokens());
133+
Assert::equals('A', $t->nextToken());
133134
}
134135

135136
#[Test]
136137
public function pushBackTokens() {
137138
$t= $this->tokenizerInstance('1,2,5', ',');
138-
$this->assertEquals('1', $t->nextToken());
139-
$this->assertEquals('2', $t->nextToken());
139+
Assert::equals('1', $t->nextToken());
140+
Assert::equals('2', $t->nextToken());
140141
$t->pushBack('3,4,');
141-
$this->assertEquals('3', $t->nextToken());
142-
$this->assertEquals('4', $t->nextToken());
143-
$this->assertEquals('5', $t->nextToken());
142+
Assert::equals('3', $t->nextToken());
143+
Assert::equals('4', $t->nextToken());
144+
Assert::equals('5', $t->nextToken());
144145
}
145146

146147
#[Test]
147148
public function pushBackOrder() {
148149
$t= $this->tokenizerInstance('1,2,5', ',');
149-
$this->assertEquals('1', $t->nextToken());
150-
$this->assertEquals('2', $t->nextToken());
150+
Assert::equals('1', $t->nextToken());
151+
Assert::equals('2', $t->nextToken());
151152
$t->pushBack('4,');
152153
$t->pushBack('3,');
153-
$this->assertEquals('3', $t->nextToken());
154-
$this->assertEquals('4', $t->nextToken());
155-
$this->assertEquals('5', $t->nextToken());
154+
Assert::equals('3', $t->nextToken());
155+
Assert::equals('4', $t->nextToken());
156+
Assert::equals('5', $t->nextToken());
156157
}
157158

158159
#[Test]
159160
public function pushBackDelimiterAtEnd() {
160161
$t= $this->tokenizerInstance("One\nTwo", "\n");
161-
$this->assertEquals('One', $t->nextToken());
162-
$this->assertEquals('Two', $t->nextToken());
162+
Assert::equals('One', $t->nextToken());
163+
Assert::equals('Two', $t->nextToken());
163164
$t->pushBack("Two\n");
164-
$this->assertEquals('Two', $t->nextToken());
165+
Assert::equals('Two', $t->nextToken());
165166
}
166167

167168
#[Test]
168169
public function pushBackDelimiter() {
169-
$this->assertEquals(
170+
Assert::equals(
170171
['// This is a one-line comment', "\n", 'a', '=', ' ', 'b', ' ', '/', ' ', 'c', ';'],
171172
$this->allTokens("// This is a one-line comment\na= b / c;", "/\n =;", "/\n =;")
172173
);
173174
}
174175

175176
#[Test]
176177
public function pushBackRegex() {
177-
$this->assertEquals(
178+
Assert::equals(
178179
['var', ' ', 'pattern', ' ', '=', ' ', '/', '0?([0-9]+)\.0?([0-9]+)(\.0?([0-9]+))?', '/', ';'],
179180
$this->allTokens('var pattern = /0?([0-9]+)\.0?([0-9]+)(\.0?([0-9]+))?/;', "/\n =;")
180181
);
@@ -183,30 +184,30 @@ public function pushBackRegex() {
183184
#[Test]
184185
public function pushBackAfterHavingReadUntilEnd() {
185186
$t= $this->tokenizerInstance('1,2,', ',');
186-
$this->assertEquals('1', $t->nextToken());
187-
$this->assertEquals('2', $t->nextToken());
188-
$this->assertFalse($t->hasMoreTokens(), 'Should be at end');
187+
Assert::equals('1', $t->nextToken());
188+
Assert::equals('2', $t->nextToken());
189+
Assert::false($t->hasMoreTokens(), 'Should be at end');
189190
$t->pushBack('6,7');
190-
$this->assertTrue($t->hasMoreTokens(), 'Should have tokens after pushing back');
191-
$this->assertEquals('6', $t->nextToken(), 'Should yield token pushed back');
192-
$this->assertEquals('7', $t->nextToken(), 'Should yield token pushed back');
193-
$this->assertFalse($t->hasMoreTokens(), 'Should be at end again');
191+
Assert::true($t->hasMoreTokens(), 'Should have tokens after pushing back');
192+
Assert::equals('6', $t->nextToken(), 'Should yield token pushed back');
193+
Assert::equals('7', $t->nextToken(), 'Should yield token pushed back');
194+
Assert::false($t->hasMoreTokens(), 'Should be at end again');
194195
}
195196

196197
#[Test]
197198
public function pushBackWithDelimitersAfterHavingReadUntilEnd() {
198199
$t= $this->tokenizerInstance('1,2,', ',', true);
199-
$this->assertEquals('1', $t->nextToken());
200-
$this->assertEquals(',', $t->nextToken());
201-
$this->assertEquals('2', $t->nextToken());
202-
$this->assertEquals(',', $t->nextToken());
203-
$this->assertFalse($t->hasMoreTokens(), 'Should be at end');
200+
Assert::equals('1', $t->nextToken());
201+
Assert::equals(',', $t->nextToken());
202+
Assert::equals('2', $t->nextToken());
203+
Assert::equals(',', $t->nextToken());
204+
Assert::false($t->hasMoreTokens(), 'Should be at end');
204205
$t->pushBack('6,7');
205-
$this->assertTrue($t->hasMoreTokens(), 'Should have tokens after pushing back');
206-
$this->assertEquals('6', $t->nextToken(), 'Should yield token pushed back');
207-
$this->assertEquals(',', $t->nextToken());
208-
$this->assertEquals('7', $t->nextToken(), 'Should yield token pushed back');
209-
$this->assertFalse($t->hasMoreTokens(), 'Should be at end again');
206+
Assert::true($t->hasMoreTokens(), 'Should have tokens after pushing back');
207+
Assert::equals('6', $t->nextToken(), 'Should yield token pushed back');
208+
Assert::equals(',', $t->nextToken());
209+
Assert::equals('7', $t->nextToken(), 'Should yield token pushed back');
210+
Assert::false($t->hasMoreTokens(), 'Should be at end again');
210211
}
211212

212213
#[Test, Ignore('Remove ignore annotation to test performance')]
@@ -231,6 +232,6 @@ public function reading_past_end_returns_null() {
231232
while ($t->hasMoreTokens()) {
232233
$t->nextToken();
233234
}
234-
$this->assertEquals([null, null], [$t->nextToken(), $t->nextToken()]);
235+
Assert::equals([null, null], [$t->nextToken(), $t->nextToken()]);
235236
}
236237
}

src/test/php/text/unittest/StreamTokenizerTest.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use io\streams\MemoryInputStream;
44
use text\StreamTokenizer;
5+
use unittest\Assert;
56

67
class StreamTokenizerTest extends AbstractTokenizerTest {
78

src/test/php/text/unittest/StringTokenizerTest.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace text\unittest;
22

33
use text\StringTokenizer;
4+
use unittest\Assert;
45

56
class StringTokenizerTest extends AbstractTokenizerTest {
67

src/test/php/text/unittest/TextTokenizerTest.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use io\streams\{MemoryInputStream, TextReader};
44
use text\TextTokenizer;
5+
use unittest\Assert;
56

67
class TextTokenizerTest extends AbstractTokenizerTest {
78

0 commit comments

Comments
 (0)