added testing for functions from lib/path.awk

This commit is contained in:
Abdullah Islam 2023-11-08 21:26:19 +06:00
parent f6d8c46314
commit e3c7c148f9
3 changed files with 35 additions and 0 deletions

View File

@ -24,6 +24,7 @@ upload:
scp -r html/* techn0path@vern.cc:public_html
test: testing/input/index.gmi testing/input/feed.txt
echo '' | mawk -f lib/navbar.awk -f lib/path.awk -f scripts/test.awk > testing/output/functionOutputs.txt
mawk -f lib/navbar.awk -f lib/path.awk -f scripts/html.awk -v 'sourcePath=testing/input' -- testing/input/index.gmi > testing/output/index.html
mawk -f lib/navbar.awk -f lib/path.awk -f scripts/gemini.awk -v 'sourcePath=testing/input' -- testing/input/index.gmi > testing/output/index.gmi
mawk -f lib/path.awk -f scripts/feed.awk -- testing/input/feed.txt > testing/output/feed.atom

24
scripts/test.awk Normal file
View File

@ -0,0 +1,24 @@
function assert(expectedValue, actualValue) {
if (expectedValue == actualValue) {
printf("%s == %s\n", expectedValue, actualValue)
} else {
printf("%s != %s\n", expectedValue, actualValue)
}
}
END {
print "=> getDirname('../path/deep/down/here')"
assert("../path/deep/down/", getDirname("../path/deep/down/here"))
print "=> getDirname('a_single_directory')"
assert(".", getDirname("a_single_directory"))
print "=> resolvePath('./path/to/irrelevant_directory/../file.txt')"
assert("path/to/file.txt", resolvePath("./path/to/irrelevant_directory/../file.txt"))
print "=> getRelativePath('parent/directory/', 'parent/path/to/file.txt')"
assert("../path/to/file.txt", getRelativePath("parent/directory", "parent/path/to/file.txt"))
print "=> getRelativePath('parent/directory/', 'parent/directory/path/to/file.txt')"
assert("path/to/file.txt", getRelativePath("parent/directory", "parent/directory/path/to/file.txt"))
}

View File

@ -0,0 +1,10 @@
=> getDirname('../path/deep/down/here')
../path/deep/down/ == ../path/deep/down/
=> getDirname('a_single_directory')
. == .
=> resolvePath('./path/to/irrelevant_directory/../file.txt')
path/to/file.txt != path/to/../
=> getRelativePath('parent/directory/', 'parent/path/to/file.txt')
../path/to/file.txt != to/path/parent
=> getRelativePath('parent/directory/', 'parent/directory/path/to/file.txt')
path/to/file.txt != path/directory/parent/to