aboutsummaryrefslogtreecommitdiff
path: root/libexec/nuageinit/tests/dirname.lua
blob: 9d76aed0ac119dadf27473dc8bdde881103420f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/libexec/flua
---
-- SPDX-License-Identifier: BSD-2-Clause
--
-- Copyright (c) 2026 Baptiste Daroussin <bapt@FreeBSD.org>

local n = require("nuage")

print(n.dirname("/my/path/path1"))

-- relative path with no directory component: nil
if n.dirname("path") then
	n.err('Expecting nil for n.dirname("path")')
end

-- nil input: nil
if n.dirname() then
	n.err("Expecting nil for n.dirname")
end

-- root path: returns "/"
if n.dirname("/") ~= "/" then
	n.err('Expecting "/" for n.dirname("/"), got: ' .. tostring(n.dirname("/")))
end

-- top-level directory: returns "/"
if n.dirname("/foo") ~= "/" then
	n.err('Expecting "/" for n.dirname("/foo")')
end

-- deep path
if n.dirname("/foo/bar/baz") ~= "/foo/bar/" then
	n.err('Expecting "/foo/bar/" for n.dirname("/foo/bar/baz")')
end