2024-08-29 11:35:03 +02:00
|
|
|
module Tests.Path
|
|
|
|
|
|
|
|
open NUnit.Framework
|
|
|
|
|
2024-12-07 12:17:48 +01:00
|
|
|
open Pentole
|
2024-08-29 11:35:03 +02:00
|
|
|
open Pentole.TestsExtensions
|
|
|
|
open Pentole.Path
|
|
|
|
|
2024-09-05 15:02:32 +02:00
|
|
|
[<Test>]
|
|
|
|
let constructor_test () =
|
|
|
|
"/" |> Path.of_string |> Result.isOk |> Assert.is_true
|
|
|
|
'\000' |> string |> Path.of_string |> Result.isOk |> Assert.is_false
|
2024-12-07 13:55:55 +01:00
|
|
|
|
2024-08-29 11:35:03 +02:00
|
|
|
[<Test>]
|
|
|
|
let absolute_test () =
|
2024-12-07 13:55:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
let is_absolute (p: IPath) =
|
|
|
|
p.string_value
|
|
|
|
|> System.IO.Path.IsPathFullyQualified
|
2024-08-29 11:35:03 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
[<Test>]
|
|
|
|
let resolve_test () =
|
|
|
|
let test (s:string) =
|
|
|
|
s
|
|
|
|
|> Path.of_string
|
2024-12-07 11:56:29 +01:00
|
|
|
|> Result.map FileSystem.resolve
|
2024-12-07 12:17:48 +01:00
|
|
|
|> Result.Unsafe.get
|
|
|
|
let p (n: string ) = Path.of_string n |> Result.Unsafe.get
|
2024-08-29 11:35:03 +02:00
|
|
|
|
|
|
|
"/" |> test |> Assert.ok_is_equal (p "/")
|
|
|
|
"/etc/../" |> test |> Assert.ok_is_equal (p "/")
|
|
|
|
"/etc/../etc" |> test |> Assert.ok_is_equal (p "/etc")
|
|
|
|
|
|
|
|
[<Test>]
|
|
|
|
let equality_test () =
|
2024-12-07 12:17:48 +01:00
|
|
|
let p (n: string ) = Path.of_string n |> Result.Unsafe.get
|
2024-08-29 11:35:03 +02:00
|
|
|
Assert.are_equal (p "/etc") (p "/etc/")
|
2024-12-07 13:55:55 +01:00
|
|
|
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/")
|
|
|
|
|
2024-08-29 11:35:03 +02:00
|
|
|
[<Test>]
|
|
|
|
let parent_test () =
|
2024-12-07 13:55:55 +01:00
|
|
|
let p (n: string ) = Path.of_string n |> Result.Unsafe.get
|
2024-08-29 11:35:03 +02:00
|
|
|
let test (s:string) =
|
|
|
|
s
|
|
|
|
|> Path.of_string
|
2024-12-07 13:55:55 +01:00
|
|
|
|> Result.Unsafe.get
|
2024-08-29 11:35:03 +02:00
|
|
|
|> parent
|
|
|
|
|
2024-12-07 13:55:55 +01:00
|
|
|
"/" |> 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/../")
|