-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLinesTest.hack
128 lines (115 loc) · 3.24 KB
/
LinesTest.hack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
namespace Nuxed\Test\Filesystem;
use namespace Nuxed\Filesystem;
use type Facebook\HackTest\HackTest;
use type Facebook\HackTest\DataProvider;
use function Facebook\FBExpect\expect;
class LinesTest extends HackTest {
<<DataProvider('provideCountData')>>
public function testCount(Container<string> $lines, int $expected): void {
$lines = new Filesystem\Lines($lines);
expect($lines->count())->toBeSame($expected);
}
public function provideCountData(): Container<(Container<string>, int)> {
return vec[
tuple(vec[], 0),
tuple(vec['foo', 'bar', 'baz'], 3),
tuple(vec['foo', 'bar', 'baz', 'qux'], 4),
tuple(vec['foo'], 1),
];
}
<<DataProvider('provideFirstData')>>
public function testFirst(Container<string> $lines, string $expected): void {
$lines = new Filesystem\Lines($lines);
expect($lines->first())->toBeSame($expected);
}
public function provideFirstData(): Container<(Container<string>, string)> {
return vec[
tuple(vec[''], ''),
tuple(vec['', 'foo', 'bar'], ''),
tuple(vec['foo', 'foo'], 'foo'),
tuple(vec['bar', 'baz'], 'bar'),
];
}
public function testFirstThrowsForEmptyLines(): void {
$lines = new Filesystem\Lines(vec[]);
expect(() ==> $lines->first())
->toThrow(
Filesystem\Exception\OutOfRangeException::class,
'Lines instance is empty.',
);
}
<<DataProvider('provideJumpData')>>
public function testJump(
Container<string> $lines,
string $expectedFirst,
Container<string> $expectedRest,
): void {
$lines = new Filesystem\Lines($lines);
list($first, $rest) = $lines->jump();
expect($first)
->toBeSame($expectedFirst);
expect(vec($rest->getIterator()))
->toBeSame(vec($expectedRest));
}
public function provideJumpData(
): Container<(Container<string>, string, Container<string>)> {
return vec[
tuple(vec['foo'], 'foo', vec[]),
tuple(vec['foo', 'bar'], 'foo', vec['bar']),
tuple(vec['foo', 'bar', 'baz'], 'foo', vec['bar', 'baz']),
tuple(vec[''], '', vec[]),
];
}
<<DataProvider('provideBlankData')>>
public function testBlank(string $line, bool $expected): void {
Filesystem\Lines::blank($line)
|> expect($$)->toBeSame($expected);
}
public function provideBlankData(): Container<(string, bool)> {
return vec[
tuple('', true),
tuple(" \t", true),
tuple('foo', false),
tuple(' ', true),
tuple(
'
',
false,
),
tuple(
'
',
false,
),
];
}
<<DataProvider('provideToStringData')>>
public function testToString(
Container<string> $lines,
string $expected,
): void {
new Filesystem\Lines($lines)
|> $$->toString()
|> expect($$)->toBeSame($expected);
}
public function provideToStringData(
): Container<(Container<string>, string)> {
return vec[
tuple(vec[], ''),
tuple(vec['foo'], 'foo'),
tuple(
vec['foo', 'bar'],
'foo
bar',
),
];
}
public function testLinesIsIterator(): void {
$lines = new Filesystem\Lines(vec['foo', 'bar']);
$result = vec[];
foreach ($lines as $line) {
$result[] = $line;
}
expect($result)->toBeSame(vec['foo', 'bar']);
}
}