awk_functions/assert.awk

23 lines
900 B
Awk

function assertEq(realValue, expectedValue) {
if (realValue == expectedValue)
printf "-> %s is a good result\n", realValue
else
printf "-> mismatch: %s (realValue) != %s\n", realValue, expectedValue
}
BEGIN {
printf "wassup gamers"
printf "\n==> function: relpath(base, path)\n"
assertEq(relpath("amogus/fibrele", "amogus/tokus/henche.txt"), "../tokus/henche.txt")
assertEq(relpath("amogus/", "amogus/henche.txt"), "henche.txt")
assertEq(relpath("/home/amogus/", "/home/amogus/henche.txt"), "henche.txt")
# assertEq(relpath("/home/amogus/", "amogus/henche.txt"), "/home/amogus/amogus/henche.txt")
printf "\n==> function: resolvePath(path)\n"
assertEq(resolvePath("../amogus/../amogus/frux"), "../amogus/frux")
assertEq(resolvePath("../amogus/frux"), "../amogus/frux")
assertEq(resolvePath("amogus/frux"), "amogus/frux")
assertEq(resolvePath("~/amogus/./frux"), "~/amogus/frux")
}