77 lines
2.4 KiB
Forth
77 lines
2.4 KiB
Forth
module Tests.Path
|
|
|
|
open NUnit.Framework
|
|
|
|
open Pentole
|
|
open Pentole.TestsExtensions
|
|
open Pentole.Path
|
|
|
|
[<Test>]
|
|
let constructor_test () =
|
|
"/" |> Path.of_string |> Result.isOk |> Assert.is_true
|
|
'\000' |> string |> Path.of_string |> Result.isOk |> Assert.is_false
|
|
|
|
[<Test>]
|
|
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
|
|
|
|
[<Test>]
|
|
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")
|
|
|
|
[<Test>]
|
|
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/")
|
|
|
|
[<Test>]
|
|
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/../")
|