From e3c7c148f9b2e92a8bb25e2e6b7417e72a116572 Mon Sep 17 00:00:00 2001 From: Abdullah Islam Date: Wed, 8 Nov 2023 21:26:19 +0600 Subject: [PATCH] added testing for functions from lib/path.awk --- Makefile | 1 + scripts/test.awk | 24 ++++++++++++++++++++++++ testing/output/functionOutputs.txt | 10 ++++++++++ 3 files changed, 35 insertions(+) create mode 100644 scripts/test.awk create mode 100644 testing/output/functionOutputs.txt diff --git a/Makefile b/Makefile index b9cad42..bd3f3e9 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/scripts/test.awk b/scripts/test.awk new file mode 100644 index 0000000..4e3f99b --- /dev/null +++ b/scripts/test.awk @@ -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")) +} \ No newline at end of file diff --git a/testing/output/functionOutputs.txt b/testing/output/functionOutputs.txt new file mode 100644 index 0000000..d60937b --- /dev/null +++ b/testing/output/functionOutputs.txt @@ -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