@@ -46,6 +46,38 @@ local function plat_path(p)
46
46
return p :gsub (" /" , " \\ " )
47
47
end
48
48
49
+
50
+ -- set up mock file with consistent eol regardless of system (git autocrlf settings)
51
+ -- simplifies reading tests
52
+ local licence_lines = {
53
+ " MIT License" ,
54
+ " " ,
55
+ " Copyright (c) 2020 TJ DeVries" ,
56
+ " " ,
57
+ " Permission is hereby granted, free of charge, to any person obtaining a copy" ,
58
+ ' of this software and associated documentation files (the "Software"), to deal' ,
59
+ " in the Software without restriction, including without limitation the rights" ,
60
+ " to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" ,
61
+ " copies of the Software, and to permit persons to whom the Software is" ,
62
+ " furnished to do so, subject to the following conditions:" ,
63
+ " " ,
64
+ " The above copyright notice and this permission notice shall be included in all" ,
65
+ " copies or substantial portions of the Software." ,
66
+ " " ,
67
+ ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR' ,
68
+ " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," ,
69
+ " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" ,
70
+ " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" ,
71
+ " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," ,
72
+ " OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" ,
73
+ " SOFTWARE." ,
74
+ " " ,
75
+ }
76
+
77
+ local license_str = table.concat (licence_lines , " \n " )
78
+ local tmp_license = Path :new " TMP_LICENSE"
79
+ tmp_license :write (license_str , " w" )
80
+
49
81
describe (" Path2" , function ()
50
82
describe (" filename" , function ()
51
83
local function get_paths ()
@@ -919,7 +951,7 @@ describe("Path2", function()
919
951
end )
920
952
921
953
it_cross_plat (" should read head of file" , function ()
922
- local p = Path :new " LICENSE "
954
+ local p = Path :new " TMP_LICENSE "
923
955
local data = p :head ()
924
956
local should = [[ MIT License
925
957
@@ -936,14 +968,14 @@ furnished to do so, subject to the following conditions:]]
936
968
end )
937
969
938
970
it_cross_plat (" should read the first line of file" , function ()
939
- local p = Path :new " LICENSE "
971
+ local p = Path :new " TMP_LICENSE "
940
972
local data = p :head (1 )
941
973
local should = [[ MIT License]]
942
974
assert .are .same (should , data , diff_str (should , data ))
943
975
end )
944
976
945
977
it_cross_plat (" should max read whole file" , function ()
946
- local p = Path :new " LICENSE "
978
+ local p = Path :new " TMP_LICENSE "
947
979
local data = p :head (1000 )
948
980
local should = [[ MIT License
949
981
@@ -1006,7 +1038,7 @@ SOFTWARE.]]
1006
1038
end )
1007
1039
1008
1040
it_cross_plat (" should read tail of file" , function ()
1009
- local p = Path :new " LICENSE "
1041
+ local p = Path :new " TMP_LICENSE "
1010
1042
local data = p :tail ()
1011
1043
local should = [[ The above copyright notice and this permission notice shall be included in all
1012
1044
copies or substantial portions of the Software.
@@ -1022,14 +1054,14 @@ SOFTWARE.]]
1022
1054
end )
1023
1055
1024
1056
it_cross_plat (" should read the last line of file" , function ()
1025
- local p = Path :new " LICENSE "
1057
+ local p = Path :new " TMP_LICENSE "
1026
1058
local data = p :tail (1 )
1027
1059
local should = [[ SOFTWARE.]]
1028
1060
assert .are .same (should , data , diff_str (should , data ))
1029
1061
end )
1030
1062
1031
1063
it_cross_plat (" should max read whole file" , function ()
1032
- local p = Path :new " LICENSE "
1064
+ local p = Path :new " TMP_LICENSE "
1033
1065
local data = p :tail (1000 )
1034
1066
local should = [[ MIT License
1035
1067
@@ -1103,14 +1135,14 @@ SOFTWARE.]]
1103
1135
end )
1104
1136
1105
1137
it_cross_plat (" should read bytes at given offset" , function ()
1106
- local p = Path :new " LICENSE "
1138
+ local p = Path :new " TMP_LICENSE "
1107
1139
local data = p :readbyterange (13 , 10 )
1108
1140
local should = " Copyright "
1109
1141
assert .are .same (should , data , diff_str (should , data ))
1110
1142
end )
1111
1143
1112
1144
it_cross_plat (" supports negative offset" , function ()
1113
- local p = Path :new " LICENSE "
1145
+ local p = Path :new " TMP_LICENSE "
1114
1146
local data = p :readbyterange (- 10 , 10 )
1115
1147
local should = " SOFTWARE.\n "
1116
1148
assert .are .same (should , data , diff_str (should , data ))
@@ -1160,7 +1192,7 @@ SOFTWARE.]]
1160
1192
end )
1161
1193
1162
1194
it_cross_plat (" no offset" , function ()
1163
- local p = Path :new " LICENSE "
1195
+ local p = Path :new " TMP_LICENSE "
1164
1196
local data = p :readbyterange (0 , 11 )
1165
1197
local should = " MIT License"
1166
1198
assert .are .same (should , data , diff_str (should , data ))
@@ -1240,3 +1272,5 @@ SOFTWARE.]]
1240
1272
end )
1241
1273
end )
1242
1274
end )
1275
+
1276
+ tmp_license :rm ()
0 commit comments