module Tests.Path open NUnit.Framework open Pentole open Pentole.TestsExtensions open Pentole.Path [] let constructor_test () = "/" |> Path.of_string |> Result.isOk |> Assert.is_true '\000' |> string |> Path.of_string |> Result.isOk |> Assert.is_false [] let absolute_test () = let is_absolute (p: IPath) = p.string_value |> System.IO.Path.IsPathFullyQualified let test (s:string) = s |> Path.of_string |> Result.map is_absolute "/" |> test |> Assert.ok_is_true "//" |> test |> Assert.ok_is_true "tmp/" |> test |> Assert.ok_is_false "tmp" |> test |> Assert.ok_is_false "~" |> test |> Assert.ok_is_false "." |> test |> Assert.ok_is_false ".." |> test |> Assert.ok_is_false "../" |> test |> Assert.ok_is_false "../../" |> test |> Assert.ok_is_false "..a" |> test |> Assert.ok_is_false ":a" |> test |> Assert.ok_is_false "\\a" |> test |> Assert.ok_is_false "/etc/../" |> test |> Assert.ok_is_true "/tmp/Char:é" |> test |> Assert.ok_is_true [] let resolve_test () = let test (s:string) = s |> Path.of_string |> Result.map FileSystem.resolve |> Result.Unsafe.get let p (n: string ) = Path.of_string n |> Result.Unsafe.get "/" |> test |> Assert.ok_is_equal (p "/") "/etc/../" |> test |> Assert.ok_is_equal (p "/") "/etc/../etc" |> test |> Assert.ok_is_equal (p "/etc") [] let equality_test () = let p (n: string ) = Path.of_string n |> Result.Unsafe.get Assert.are_equal (p "/etc") (p "/etc/") Assert.are_not_equal (p "etc") (p "/etc/") Assert.are_not_equal (p "etc") (p "/etc") Assert.are_equal (Path.of_string "/tmp" ) ( Path.of_string "/tmp/") Assert.is_true (Path.of_string "/tmp" = Path.of_string "/tmp/") [] let parent_test () = let p (n: string ) = Path.of_string n |> Result.Unsafe.get let test (s:string) = s |> Path.of_string |> Result.Unsafe.get |> parent "/" |> test |> Assert.are_equal (p "/") "/etc/" |> test |> Assert.are_equal (p "/") "/etc/conf" |> test |> Assert.are_equal (p "/etc") "/etc/../etc" |> test |> Assert.are_equal (p "/etc/../") "etc/../etc" |> test |> Assert.are_equal (p "etc/../") [] let exitsts_test () = let p (n: string ) = Path.of_string n |> Result.Unsafe.get FileSystem.exists (p "/tmp/") |> Assert.is_true FileSystem.exists (p "/IHOPE_this_DOESNT_exist/") |> Assert.is_false