Sync local packages into the registry repo and update index.json and README.md to include all 9 packages.
145 lines
5.6 KiB
Plaintext
145 lines
5.6 KiB
Plaintext
import lib
|
|
|
|
// --- basename edge cases ---
|
|
|
|
fn test_basename_root(): Unit with {Test} =
|
|
Test.assertEqualMsg("", lib.basename("/"), "basename of root")
|
|
|
|
fn test_basename_multiple_slashes(): Unit with {Test} =
|
|
Test.assertEqualMsg("", lib.basename("///"), "basename of ///")
|
|
|
|
fn test_basename_dotfile(): Unit with {Test} =
|
|
Test.assertEqualMsg(".hidden", lib.basename("/home/.hidden"), "basename of dotfile")
|
|
|
|
fn test_basename_dots_in_name(): Unit with {Test} =
|
|
Test.assertEqualMsg("file.tar.gz", lib.basename("/path/to/file.tar.gz"), "basename with multiple dots")
|
|
|
|
fn test_basename_single_char(): Unit with {Test} =
|
|
Test.assertEqualMsg("x", lib.basename("x"), "basename of single char")
|
|
|
|
fn test_basename_deep_path(): Unit with {Test} =
|
|
Test.assertEqualMsg("deep.txt", lib.basename("/a/b/c/d/e/deep.txt"), "basename of deep path")
|
|
|
|
fn test_basename_space_in_name(): Unit with {Test} =
|
|
Test.assertEqualMsg("my file.txt", lib.basename("/path/my file.txt"), "basename with space")
|
|
|
|
// --- dirname edge cases ---
|
|
|
|
fn test_dirname_root(): Unit with {Test} =
|
|
Test.assertEqualMsg("/", lib.dirname("/"), "dirname of root")
|
|
|
|
fn test_dirname_root_file(): Unit with {Test} =
|
|
Test.assertEqualMsg("/", lib.dirname("/a"), "dirname of root-level file")
|
|
|
|
fn test_dirname_deep(): Unit with {Test} =
|
|
Test.assertEqualMsg("/a/b/c", lib.dirname("/a/b/c/d"), "dirname of deep path")
|
|
|
|
fn test_dirname_empty(): Unit with {Test} =
|
|
Test.assertEqualMsg(".", lib.dirname(""), "dirname of empty")
|
|
|
|
fn test_dirname_relative(): Unit with {Test} =
|
|
Test.assertEqualMsg("a/b", lib.dirname("a/b/c"), "dirname of relative path")
|
|
|
|
// --- extension edge cases ---
|
|
|
|
fn isSome(opt: Option<String>, expected: String): Bool =
|
|
match opt {
|
|
Some(v) => v == expected,
|
|
None => false,
|
|
}
|
|
|
|
fn isNone(opt: Option<String>): Bool =
|
|
match opt {
|
|
Some(_) => false,
|
|
None => true,
|
|
}
|
|
|
|
fn test_extension_dotfile(): Unit with {Test} =
|
|
Test.assert(isNone(lib.extension(".bashrc")), "extension of .bashrc is None")
|
|
|
|
fn test_extension_trailing_dot(): Unit with {Test} =
|
|
Test.assert(isSome(lib.extension("file."), ""), "extension of file. is empty string")
|
|
|
|
fn test_extension_multiple_dots(): Unit with {Test} =
|
|
Test.assert(isSome(lib.extension("archive.tar.gz"), "gz"), "extension of .tar.gz is gz")
|
|
|
|
fn test_extension_empty(): Unit with {Test} =
|
|
Test.assert(isNone(lib.extension("")), "extension of empty is None")
|
|
|
|
fn test_extension_no_dot(): Unit with {Test} =
|
|
Test.assert(isNone(lib.extension("Makefile")), "extension of Makefile is None")
|
|
|
|
fn test_extension_hidden_with_ext(): Unit with {Test} =
|
|
Test.assert(isSome(lib.extension(".config.json"), "json"), "extension of .config.json is json")
|
|
|
|
fn test_extension_dot_in_dir(): Unit with {Test} =
|
|
Test.assert(isSome(lib.extension("/path.d/file.txt"), "txt"), "extension through dotted dir")
|
|
|
|
// --- stripExtension edge cases ---
|
|
|
|
fn test_strip_extension_dotfile(): Unit with {Test} =
|
|
Test.assertEqualMsg("", lib.stripExtension(".bashrc"), "stripExtension of dotfile")
|
|
|
|
fn test_strip_extension_trailing_dot(): Unit with {Test} =
|
|
Test.assertEqualMsg("file", lib.stripExtension("file."), "stripExtension trailing dot")
|
|
|
|
fn test_strip_extension_double(): Unit with {Test} =
|
|
Test.assertEqualMsg("file.tar", lib.stripExtension("file.tar.gz"), "stripExtension only strips last")
|
|
|
|
fn test_strip_extension_dot_in_dir(): Unit with {Test} =
|
|
Test.assertEqualMsg("/usr/local.d/config", lib.stripExtension("/usr/local.d/config.ini"), "stripExtension with dot in dir")
|
|
|
|
// --- join edge cases ---
|
|
|
|
fn test_join_both_empty(): Unit with {Test} =
|
|
Test.assertEqualMsg("", lib.join("", ""), "join empty + empty")
|
|
|
|
fn test_join_double_slash(): Unit with {Test} =
|
|
Test.assertEqualMsg("/foo/bar", lib.join("/foo/", "/bar"), "join normalizes double slash")
|
|
|
|
fn test_join_root(): Unit with {Test} =
|
|
Test.assertEqualMsg("/bar", lib.join("/", "bar"), "join root + relative")
|
|
|
|
fn test_join_three_parts(): Unit with {Test} = {
|
|
let result = lib.join(lib.join("/a", "b"), "c")
|
|
Test.assertEqualMsg("/a/b/c", result, "three-part join")
|
|
}
|
|
|
|
// --- stem edge cases ---
|
|
|
|
fn test_stem_dotfile(): Unit with {Test} =
|
|
Test.assertEqualMsg(".hidden", lib.stem(".hidden"), "stem of dotfile preserved")
|
|
|
|
fn test_stem_multiple_dots(): Unit with {Test} =
|
|
Test.assertEqualMsg("file.tar", lib.stem("file.tar.gz"), "stem of .tar.gz")
|
|
|
|
fn test_stem_no_dir_no_ext(): Unit with {Test} =
|
|
Test.assertEqualMsg("README", lib.stem("README"), "stem of extensionless file")
|
|
|
|
// --- isAbsolute / isRelative edge cases ---
|
|
|
|
fn test_is_absolute_empty(): Unit with {Test} =
|
|
Test.assertEqualMsg(false, lib.isAbsolute(""), "empty is not absolute")
|
|
|
|
fn test_is_relative_empty(): Unit with {Test} =
|
|
Test.assertEqualMsg(true, lib.isRelative(""), "empty is relative")
|
|
|
|
fn test_is_absolute_just_slash(): Unit with {Test} =
|
|
Test.assertEqualMsg(true, lib.isAbsolute("/"), "/ is absolute")
|
|
|
|
// --- hasExtension / replaceExtension edge cases ---
|
|
|
|
fn test_has_extension_case_sensitive(): Unit with {Test} =
|
|
Test.assertEqualMsg(false, lib.hasExtension("file.TXT", "txt"), "hasExtension is case sensitive")
|
|
|
|
fn test_has_extension_partial(): Unit with {Test} =
|
|
Test.assertEqualMsg(false, lib.hasExtension("file.txta", "txt"), "hasExtension no partial match")
|
|
|
|
fn test_replace_extension_dotfile(): Unit with {Test} =
|
|
Test.assertEqualMsg(".md", lib.replaceExtension(".bashrc", "md"), "replaceExtension on dotfile")
|
|
|
|
fn test_replace_extension_chain(): Unit with {Test} = {
|
|
let result = lib.replaceExtension(lib.replaceExtension("file.txt", "md"), "html")
|
|
Test.assertEqualMsg("file.html", result, "chained replaceExtension")
|
|
}
|