@@ -932,14 +932,14 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
932
932
copies of the Software, and to permit persons to whom the Software is
933
933
furnished to do so, subject to the following conditions:]]
934
934
935
- assert .are .same (should , data )
935
+ assert .are .same (should , data , diff_str ( should , data ) )
936
936
end )
937
937
938
938
it_cross_plat (" should read the first line of file" , function ()
939
939
local p = Path :new " LICENSE"
940
940
local data = p :head (1 )
941
941
local should = [[ MIT License]]
942
- assert .are .same (should , data )
942
+ assert .are .same (should , data , diff_str ( should , data ) )
943
943
end )
944
944
945
945
it_cross_plat (" should max read whole file" , function ()
@@ -966,7 +966,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
966
966
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
967
967
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
968
968
SOFTWARE.]]
969
- assert .are .same (should , data )
969
+ assert .are .same (should , data , diff_str ( should , data ) )
970
970
end )
971
971
972
972
it_cross_plat (" handles unix lf line endings" , function ()
@@ -1018,14 +1018,14 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1018
1018
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1019
1019
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1020
1020
SOFTWARE.]]
1021
- assert .are .same (should , data )
1021
+ assert .are .same (should , data , diff_str ( should , data ) )
1022
1022
end )
1023
1023
1024
1024
it_cross_plat (" should read the last line of file" , function ()
1025
1025
local p = Path :new " LICENSE"
1026
1026
local data = p :tail (1 )
1027
1027
local should = [[ SOFTWARE.]]
1028
- assert .are .same (should , data )
1028
+ assert .are .same (should , data , diff_str ( should , data ) )
1029
1029
end )
1030
1030
1031
1031
it_cross_plat (" should max read whole file" , function ()
@@ -1052,7 +1052,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1052
1052
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1053
1053
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1054
1054
SOFTWARE.]]
1055
- assert .are .same (should , data )
1055
+ assert .are .same (should , data , diff_str ( should , data ) )
1056
1056
end )
1057
1057
1058
1058
it_cross_plat (" handles unix lf line endings" , function ()
@@ -1098,18 +1098,72 @@ SOFTWARE.]]
1098
1098
end )
1099
1099
1100
1100
describe (" readbyterange" , function ()
1101
+ after_each (function ()
1102
+ uv .fs_unlink " foobar.txt"
1103
+ end )
1104
+
1101
1105
it_cross_plat (" should read bytes at given offset" , function ()
1102
1106
local p = Path :new " LICENSE"
1103
1107
local data = p :readbyterange (13 , 10 )
1104
1108
local should = " Copyright "
1105
- assert .are .same (should , data )
1109
+ assert .are .same (should , data , diff_str ( should , data ) )
1106
1110
end )
1107
1111
1108
1112
it_cross_plat (" supports negative offset" , function ()
1109
1113
local p = Path :new " LICENSE"
1110
1114
local data = p :readbyterange (- 10 , 10 )
1111
1115
local should = " SOFTWARE.\n "
1112
- assert .are .same (should , data )
1116
+ assert .are .same (should , data , diff_str (should , data ))
1117
+ end )
1118
+
1119
+ it_cross_plat (" handles unix lf line endings" , function ()
1120
+ local p = Path :new " foobar.txt"
1121
+ p :touch ()
1122
+
1123
+ local txt = " foo\n bar\n baz"
1124
+ p :write (txt , " w" )
1125
+ local data = p :readbyterange (3 , 5 )
1126
+ local expect = " \n bar\n "
1127
+ assert .are .same (expect , data , diff_str (expect , data ))
1128
+ end )
1129
+
1130
+ it_cross_plat (" handles windows crlf line endings" , function ()
1131
+ local p = Path :new " foobar.txt"
1132
+ p :touch ()
1133
+
1134
+ local txt = " foo\r\n bar\r\n baz"
1135
+ p :write (txt , " w" )
1136
+ local data = p :readbyterange (3 , 5 )
1137
+ local expect = " \r\n bar"
1138
+ assert .are .same (expect , data , diff_str (expect , data ))
1139
+ end )
1140
+
1141
+ it_cross_plat (" handles mac cr line endings" , function ()
1142
+ local p = Path :new " foobar.txt"
1143
+ p :touch ()
1144
+
1145
+ local txt = " foo\r bar\r baz"
1146
+ p :write (txt , " w" )
1147
+ local data = p :readbyterange (3 , 5 )
1148
+ local expect = " \r bar\r "
1149
+ assert .are .same (expect , data , diff_str (expect , data ))
1150
+ end )
1151
+
1152
+ it_cross_plat (" offset larger than size" , function ()
1153
+ local p = Path :new " foobar.txt"
1154
+ p :touch ()
1155
+
1156
+ local txt = " hello"
1157
+ p :write (txt , " w" )
1158
+ local data = p :readbyterange (10 , 3 )
1159
+ assert .are .same (" " , data )
1160
+ end )
1161
+
1162
+ it_cross_plat (" no offset" , function ()
1163
+ local p = Path :new " LICENSE"
1164
+ local data = p :readbyterange (0 , 11 )
1165
+ local should = " MIT License"
1166
+ assert .are .same (should , data , diff_str (should , data ))
1113
1167
end )
1114
1168
end )
1115
1169
@@ -1129,13 +1183,14 @@ SOFTWARE.]]
1129
1183
end )
1130
1184
1131
1185
it_cross_plat (" doesn't find file" , function ()
1132
- local p = Path :new " . "
1186
+ local p = Path :new ( path . root ())
1133
1187
local res = p :find_upwards " aisohtenaishoetnaishoetnasihoetnashitoen"
1134
1188
assert .is_nil (res )
1135
1189
end )
1136
1190
end )
1137
1191
1138
1192
describe (" expand" , function ()
1193
+ uv .os_setenv (" FOOVAR" , " foo" )
1139
1194
uv .os_setenv (" BARVAR" , " bar" )
1140
1195
1141
1196
describe (" unix" , function ()
@@ -1144,7 +1199,7 @@ SOFTWARE.]]
1144
1199
end
1145
1200
1146
1201
it (" match valid env var" , function ()
1147
- local p = Path :new " foo /$BARVAR/baz"
1202
+ local p = Path :new " $FOOVAR /$BARVAR/baz"
1148
1203
assert .are .same (" foo/bar/baz" , p :expand ())
1149
1204
end )
1150
1205
@@ -1160,7 +1215,7 @@ SOFTWARE.]]
1160
1215
end
1161
1216
1162
1217
it_win (" match valid env var" , function ()
1163
- local p = Path :new " foo /%BARVAR%/baz"
1218
+ local p = Path :new " %foovar% /%BARVAR%/baz"
1164
1219
local expect = Path :new " foo/bar/baz"
1165
1220
assert .are .same (expect .filename , p :expand ())
1166
1221
end )
0 commit comments