Sync local packages into the registry repo and update index.json and README.md to include all 9 packages.
89 lines
3.9 KiB
Plaintext
89 lines
3.9 KiB
Plaintext
import lib
|
|
|
|
// Integration tests: realistic path manipulation workflows
|
|
|
|
// Build a full output path from components
|
|
fn test_build_output_path(): Unit with {Test} = {
|
|
let srcFile = "/home/user/project/src/pages/about.md"
|
|
let outDir = "/home/user/project/_site"
|
|
let name = lib.stem(srcFile)
|
|
let outFile = lib.join(outDir, lib.join(name, "index.html"))
|
|
Test.assertEqualMsg("/home/user/project/_site/about/index.html", outFile, "build output path from source")
|
|
}
|
|
|
|
// Convert all markdown files to HTML paths
|
|
fn test_extension_swap_workflow(): Unit with {Test} = {
|
|
let file = "/content/posts/hello-world.md"
|
|
let result = lib.replaceExtension(file, "html")
|
|
Test.assertEqualMsg("/content/posts/hello-world.html", result, "swap .md to .html")
|
|
Test.assertEqualMsg("html", match lib.extension(result) { Some(e) => e, None => "" }, "verify new extension")
|
|
}
|
|
|
|
// Decompose a path and reconstruct it
|
|
fn test_decompose_reconstruct(): Unit with {Test} = {
|
|
let original = "/var/log/app/error.log"
|
|
let dir = lib.dirname(original)
|
|
let name = lib.basename(original)
|
|
let reconstructed = lib.join(dir, name)
|
|
Test.assertEqualMsg(original, reconstructed, "decompose and reconstruct path")
|
|
}
|
|
|
|
// Process a list of file paths: extract stems
|
|
fn test_batch_stem_extraction(): Unit with {Test} = {
|
|
let s1 = lib.stem("/posts/hello.md")
|
|
let s2 = lib.stem("/posts/world.md")
|
|
let s3 = lib.stem("/posts/readme.txt")
|
|
Test.assertEqualMsg("hello", s1, "batch stem 1")
|
|
Test.assertEqualMsg("world", s2, "batch stem 2")
|
|
Test.assertEqualMsg("readme", s3, "batch stem 3")
|
|
}
|
|
|
|
// Create sibling file path (same dir, different name)
|
|
fn test_sibling_file(): Unit with {Test} = {
|
|
let original = "/assets/css/main.css"
|
|
let dir = lib.dirname(original)
|
|
let sibling = lib.join(dir, "reset.css")
|
|
Test.assertEqualMsg("/assets/css/reset.css", sibling, "sibling file in same directory")
|
|
}
|
|
|
|
// Multi-level path construction
|
|
fn test_multi_level_join(): Unit with {Test} = {
|
|
let base = "/var/www"
|
|
let path = lib.join(lib.join(lib.join(base, "html"), "blog"), "index.html")
|
|
Test.assertEqualMsg("/var/www/html/blog/index.html", path, "multi-level path join")
|
|
Test.assertEqualMsg("/var/www/html/blog", lib.dirname(path), "dirname of multi-level")
|
|
Test.assertEqualMsg("index.html", lib.basename(path), "basename of multi-level")
|
|
Test.assert(lib.isAbsolute(path), "multi-level path is absolute")
|
|
}
|
|
|
|
// Verify path properties are consistent
|
|
fn test_path_property_consistency(): Unit with {Test} = {
|
|
let path = "src/components/Button.tsx"
|
|
Test.assertEqualMsg(true, lib.isRelative(path), "is relative")
|
|
Test.assertEqualMsg(false, lib.isAbsolute(path), "is not absolute")
|
|
Test.assertEqualMsg(true, lib.hasExtension(path, "tsx"), "has .tsx extension")
|
|
Test.assertEqualMsg(false, lib.hasExtension(path, "ts"), "does not have .ts extension")
|
|
Test.assertEqualMsg("Button", lib.stem(path), "stem is Button")
|
|
Test.assertEqualMsg("src/components", lib.dirname(path), "dirname is src/components")
|
|
}
|
|
|
|
// Swap extension and verify roundtrip
|
|
fn test_extension_roundtrip(): Unit with {Test} = {
|
|
let original = "report.csv"
|
|
let swapped = lib.replaceExtension(original, "json")
|
|
Test.assertEqualMsg("report.json", swapped, "csv -> json")
|
|
let back = lib.replaceExtension(swapped, "csv")
|
|
Test.assertEqualMsg("report.csv", back, "json -> csv roundtrip")
|
|
}
|
|
|
|
// Build a path for a static site generator output
|
|
fn test_ssg_path_pipeline(): Unit with {Test} = {
|
|
let inputFile = "content/blog/my-first-post.md"
|
|
let slug = lib.stem(inputFile)
|
|
let outputDir = lib.join("_site", slug)
|
|
let outputFile = lib.join(outputDir, "index.html")
|
|
Test.assertEqualMsg("my-first-post", slug, "extract slug")
|
|
Test.assertEqualMsg("_site/my-first-post", outputDir, "output directory")
|
|
Test.assertEqualMsg("_site/my-first-post/index.html", outputFile, "full output path")
|
|
}
|