forked from chrisboulton/php-diff
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFileTest.php
More file actions
146 lines (128 loc) · 3.44 KB
/
FileTest.php
File metadata and controls
146 lines (128 loc) · 3.44 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace Tests\Diff;
use InvalidArgumentException;
use jblond\Diff\File;
use PHPUnit\Framework\TestCase;
/**
*
*/
class FileTest extends TestCase
{
/**
* Test the type of EOF
*/
public function testGetEOLType()
{
$mac = new File();
$mac->setFile('tests/resources/eol/mac.txt');
$this->assertEquals(
'EOL type is Mac (CR)',
$mac->getEOLType()
);
$unix = new File();
$unix->setFile('tests/resources/eol/unix.txt');
$this->assertEquals(
'EOL type is Unix (LF)',
$unix->getEOLType()
);
$noEol = new File();
$noEol->setFile('tests/resources/eol/no-eol.txt');
$this->assertEquals(
'\ No newline at end of file',
$noEol->getEOLType()
);
$windows = new File();
$windows->setFile('tests/resources/eol/windows.txt');
$this->assertEquals(
'EOL type is Windows (CRLF)',
$windows->getEOLType()
);
$a = new File();
$a->setFile('tests/resources/a.txt');
$this->assertEquals(
'EOL type is Unix (LF)',
$a->getEOLType()
);
}
/**
* Bool test if the file has a line ending
*/
public function testHasNewLineAtTheEnd()
{
$mac = new File();
$mac->setFile('tests/resources/eol/mac.txt');
$this->assertEquals(
true,
$mac->hasNewLineAtTheEnd()
);
$unix = new File();
$unix->setFile('tests/resources/eol/unix.txt');
$this->assertEquals(
true,
$unix->hasNewLineAtTheEnd()
);
$noEol = new File();
$noEol->setFile('tests/resources/eol/no-eol.txt');
$this->assertEquals(
false,
$noEol->hasNewLineAtTheEnd()
);
$windows = new File();
$windows->setFile('tests/resources/eol/windows.txt');
$this->assertEquals(
true,
$windows->hasNewLineAtTheEnd()
);
$a = new File();
$a->setFile('tests/resources/a.txt');
$this->assertEquals(
true,
$a->hasNewLineAtTheEnd()
);
$b = new File();
$b->setFile('tests/resources/b.txt');
$this->assertEquals(
true,
$b->hasNewLineAtTheEnd()
);
}
/**
* Test get the last string from a file
*/
public function testGetLastLine()
{
$mac = new File();
$mac->setFile('tests/resources/eol/mac.txt');
$this->assertEquals(
"Lorem ipsum\r",
$mac->getLastLine()
);
$unix = new File();
$unix->setFile('tests/resources/eol/unix.txt');
$this->assertEquals(
"Lorem ipsum\n",
$unix->getLastLine()
);
$noEol = new File();
$noEol->setFile('tests/resources/eol/no-eol.txt');
$this->assertEquals(
"Lorem ipsum",
$noEol->getLastLine()
);
$windows = new File();
$windows->setFile('tests/resources/eol/windows.txt');
$this->assertEquals(
"Lorem ipsum\r\n",
$windows->getLastLine()
);
}
/**
* Test if the file exists
*/
public function testSetFile()
{
$this->expectException(InvalidArgumentException::class);
$file = new File();
$file->setFile('foo.txt');
}
}