@@ -845,7 +845,112 @@ describe("Path2", function()
845
845
it_cross_plat (" should return itself if it corresponds to path.root" , function ()
846
846
local p = Path :new (Path .path .root (vim .fn .getcwd ()))
847
847
assert .are .same (p :absolute (), p :parent ():absolute ())
848
- -- assert.are.same(p, p:parent())
848
+ assert .are .same (p , p :parent ())
849
+ end )
850
+ end )
851
+
852
+ describe (" head" , function ()
853
+ it_cross_plat (" should read head of file" , function ()
854
+ local p = Path :new " LICENSE"
855
+ local data = p :head ()
856
+ local should = [[ MIT License
857
+
858
+ Copyright (c) 2020 TJ DeVries
859
+
860
+ Permission is hereby granted, free of charge, to any person obtaining a copy
861
+ of this software and associated documentation files (the "Software"), to deal
862
+ in the Software without restriction, including without limitation the rights
863
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
864
+ copies of the Software, and to permit persons to whom the Software is
865
+ furnished to do so, subject to the following conditions:]]
866
+
867
+ assert .are .same (should , data )
868
+ end )
869
+
870
+ it_cross_plat (" should read the first line of file" , function ()
871
+ local p = Path :new " LICENSE"
872
+ local data = p :head (1 )
873
+ local should = [[ MIT License]]
874
+ assert .are .same (should , data )
875
+ end )
876
+
877
+ it_cross_plat (" head should max read whole file" , function ()
878
+ local p = Path :new " LICENSE"
879
+ local data = p :head (1000 )
880
+ local should = [[ MIT License
881
+
882
+ Copyright (c) 2020 TJ DeVries
883
+
884
+ Permission is hereby granted, free of charge, to any person obtaining a copy
885
+ of this software and associated documentation files (the "Software"), to deal
886
+ in the Software without restriction, including without limitation the rights
887
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
888
+ copies of the Software, and to permit persons to whom the Software is
889
+ furnished to do so, subject to the following conditions:
890
+
891
+ The above copyright notice and this permission notice shall be included in all
892
+ copies or substantial portions of the Software.
893
+
894
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
895
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
896
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
897
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
898
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
899
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
900
+ SOFTWARE.]]
901
+ assert .are .same (should , data )
902
+ end )
903
+ end )
904
+
905
+ describe (" tail" , function ()
906
+ it_cross_plat (" should read tail of file" , function ()
907
+ local p = Path :new " LICENSE"
908
+ local data = p :tail ()
909
+ local should = [[ The above copyright notice and this permission notice shall be included in all
910
+ copies or substantial portions of the Software.
911
+
912
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
913
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
914
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
915
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
916
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
917
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
918
+ SOFTWARE.]]
919
+ assert .are .same (should , data )
920
+ end )
921
+
922
+ it_cross_plat (" should read the last line of file" , function ()
923
+ local p = Path :new " LICENSE"
924
+ local data = p :tail (1 )
925
+ local should = [[ SOFTWARE.]]
926
+ assert .are .same (should , data )
927
+ end )
928
+
929
+ it_cross_plat (" tail should max read whole file" , function ()
930
+ local p = Path :new " LICENSE"
931
+ local data = p :tail (1000 )
932
+ local should = [[ MIT License
933
+
934
+ Copyright (c) 2020 TJ DeVries
935
+
936
+ Permission is hereby granted, free of charge, to any person obtaining a copy
937
+ of this software and associated documentation files (the "Software"), to deal
938
+ in the Software without restriction, including without limitation the rights
939
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
940
+ copies of the Software, and to permit persons to whom the Software is
941
+ furnished to do so, subject to the following conditions:
942
+
943
+ The above copyright notice and this permission notice shall be included in all
944
+ copies or substantial portions of the Software.
945
+
946
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
947
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
948
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
949
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
950
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
951
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
952
+ SOFTWARE.]]
953
+ assert .are .same (should , data )
849
954
end )
850
955
end )
851
956
end )
0 commit comments