// Copyright 2022 schukai GmbH // SPDX-License-Identifier: AGPL-3.0 package configuration import ( "path" "testing" ) func TestPathValue(t *testing.T) { data := []struct { path string expected string base string }{ {"/a/b/c", "/a/b", "c"}, {"/a/b/c/", "/a/b/c", "c"}, // trailing slash are ignored {"/a/b/c/d.txt", "/a/b/c", "d.txt"}, {"/a/b/c/d/", "/a/b/c/d", "d"}, {"/a/b/c/d/e", "/a/b/c/d", "e"}, {"/a/b/../c/d/e", "/a/c/d", "e"}, } for _, d := range data { t.Run("Dir-"+d.path, func(t *testing.T) { p := PathValue(d.path) if p.Dir() != d.expected { t.Errorf("Expected %s, got %s", d.expected, p.Dir()) } }) } for _, d := range data { t.Run("Base-"+d.path, func(t *testing.T) { p := PathValue(d.path) if p.Base() != d.base { t.Errorf("Expected %s, got %s", d.base, p.Base()) } }) } for _, d := range data { t.Run("String-"+d.path, func(t *testing.T) { p := PathValue(d.path) if p.String() != string(p) { t.Errorf("Expected %s, got %s", string(p), p.String()) } }) } for _, d := range data { t.Run("Ext-"+d.path, func(t *testing.T) { p := PathValue(d.path) if p.Ext() != path.Ext(d.path) { t.Errorf("Expected %s, got %s", path.Ext(d.path), p.Ext()) } }) } }