@@ -932,14 +932,14 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
932932copies of the Software, and to permit persons to whom the Software is
933933furnished to do so, subject to the following conditions:]]
934934
935- assert .are .same (should , data )
935+ assert .are .same (should , data , diff_str ( should , data ) )
936936 end )
937937
938938 it_cross_plat (" should read the first line of file" , function ()
939939 local p = Path :new " LICENSE"
940940 local data = p :head (1 )
941941 local should = [[ MIT License]]
942- assert .are .same (should , data )
942+ assert .are .same (should , data , diff_str ( should , data ) )
943943 end )
944944
945945 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
966966LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
967967OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
968968SOFTWARE.]]
969- assert .are .same (should , data )
969+ assert .are .same (should , data , diff_str ( should , data ) )
970970 end )
971971
972972 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
10181018LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10191019OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10201020SOFTWARE.]]
1021- assert .are .same (should , data )
1021+ assert .are .same (should , data , diff_str ( should , data ) )
10221022 end )
10231023
10241024 it_cross_plat (" should read the last line of file" , function ()
10251025 local p = Path :new " LICENSE"
10261026 local data = p :tail (1 )
10271027 local should = [[ SOFTWARE.]]
1028- assert .are .same (should , data )
1028+ assert .are .same (should , data , diff_str ( should , data ) )
10291029 end )
10301030
10311031 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
10521052LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10531053OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10541054SOFTWARE.]]
1055- assert .are .same (should , data )
1055+ assert .are .same (should , data , diff_str ( should , data ) )
10561056 end )
10571057
10581058 it_cross_plat (" handles unix lf line endings" , function ()
@@ -1098,18 +1098,72 @@ SOFTWARE.]]
10981098 end )
10991099
11001100 describe (" readbyterange" , function ()
1101+ after_each (function ()
1102+ uv .fs_unlink " foobar.txt"
1103+ end )
1104+
11011105 it_cross_plat (" should read bytes at given offset" , function ()
11021106 local p = Path :new " LICENSE"
11031107 local data = p :readbyterange (13 , 10 )
11041108 local should = " Copyright "
1105- assert .are .same (should , data )
1109+ assert .are .same (should , data , diff_str ( should , data ) )
11061110 end )
11071111
11081112 it_cross_plat (" supports negative offset" , function ()
11091113 local p = Path :new " LICENSE"
11101114 local data = p :readbyterange (- 10 , 10 )
11111115 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 ))
11131167 end )
11141168 end )
11151169
@@ -1129,13 +1183,14 @@ SOFTWARE.]]
11291183 end )
11301184
11311185 it_cross_plat (" doesn't find file" , function ()
1132- local p = Path :new " . "
1186+ local p = Path :new ( path . root ())
11331187 local res = p :find_upwards " aisohtenaishoetnaishoetnasihoetnashitoen"
11341188 assert .is_nil (res )
11351189 end )
11361190 end )
11371191
11381192 describe (" expand" , function ()
1193+ uv .os_setenv (" FOOVAR" , " foo" )
11391194 uv .os_setenv (" BARVAR" , " bar" )
11401195
11411196 describe (" unix" , function ()
@@ -1144,7 +1199,7 @@ SOFTWARE.]]
11441199 end
11451200
11461201 it (" match valid env var" , function ()
1147- local p = Path :new " foo /$BARVAR/baz"
1202+ local p = Path :new " $FOOVAR /$BARVAR/baz"
11481203 assert .are .same (" foo/bar/baz" , p :expand ())
11491204 end )
11501205
@@ -1160,7 +1215,7 @@ SOFTWARE.]]
11601215 end
11611216
11621217 it_win (" match valid env var" , function ()
1163- local p = Path :new " foo /%BARVAR%/baz"
1218+ local p = Path :new " %foovar% /%BARVAR%/baz"
11641219 local expect = Path :new " foo/bar/baz"
11651220 assert .are .same (expect .filename , p :expand ())
11661221 end )
0 commit comments