ldmc/test/test.sh

83 lines
3.2 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
run_test_case() {
mkdir -p target/src
mkdir -p .tmp
echo "
-----------------------------------------------------------------------------
Running test case ${TEST_NAME}"
ldmc "${SRC_TYPE}" "${DST_TYPE}" ../morphisms/*.morphism-base 2>|.tmp/ldmc_err 1>| target/src/${TEST_NAME}.c \
|| (echo "... error at generation:"; cat .tmp/ldmc_err; return -1);
gcc -I../morphisms/runtime/include target/src/${TEST_NAME}.c -o target/${TEST_NAME} \
|| (echo "... error at compilation:"; return -2);
LEN="$(echo -n "${EXPECT}" | wc -c)"
RESULT="$(echo -n ${INPUT} | ./target/${TEST_NAME} 2>.tmp/target_err | head -c ${LEN})"
if [ "${RESULT}" == "${EXPECT}" ];
then
echo "... ok"
else
echo -e "... incorrect result\n"
cat .tmp/target_err
echo -e ""
echo -e "INPUT:\n$(echo -n "${INPUT}" | hexyl)"
echo -e "EXPECTED:\n$(echo -n "${EXPECT}" | hexyl)"
echo -e "GOT:\n$(echo -n "${RESULT}" | hexyl)"
fi
rm -rf .tmp
}
TEST_NAME=test-radix-convert
SRC_TYPE=" ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10> ~ Char ~ Ascii ~ native.UInt8>"
DST_TYPE=" ~ <PosInt 16 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 16> ~ Char ~ Ascii ~ native.UInt8>"
INPUT="255"
EXPECT="ff"
run_test_case
TEST_NAME=test-msb-cont
SRC_TYPE="<Seq~<ValueTerminated 0> native.UInt8>"
DST_TYPE="<Seq~MsbCont native.UInt8>"
INPUT=$(printf '\x01\x02\x03')
EXPECT=$(printf '\x81\x82\x03')
run_test_case
TEST_NAME=test-value-sep1
SRC_TYPE="<Seq <Seq Char~native.UInt8>> ~ <ValueSep ':' Char~native.UInt8> ~ <Seq~<ValueTerminated 0> Char~native.UInt8>"
DST_TYPE="<Seq <Seq Char~native.UInt8>> ~ <ValueSep ',' Char~native.UInt8> ~ <Seq~<ValueTerminated 0> Char~native.UInt8>"
INPUT="abc:def:hello world:test"
EXPECT="abc,def,hello world,test"
run_test_case
TEST_NAME=test-value-sep2
SRC_TYPE="<Seq <Seq native.UInt8>> ~ <ValueSep ':' native.UInt8> ~ <Seq~<ValueTerminated 0> native.UInt8>"
DST_TYPE="<Seq <Seq native.UInt8>> ~ <ValueSep '\\n' native.UInt8> ~ <Seq~<ValueTerminated 0> native.UInt8>"
INPUT="abc:def:hello world:test"
EXPECT=$(echo -en "abc\ndef\nhello world\ntest")
run_test_case
TEST_NAME=test-value-sep-digit
SRC_TYPE="<Seq <Seq <Digit 16>~Char~Ascii~native.UInt8>> ~ <ValueSep ':' Char~Ascii~native.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~native.UInt8>"
DST_TYPE="<Seq <Seq <Digit 16>~Char~Ascii~native.UInt8>> ~ <ValueSep '.' Char~Ascii~native.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~native.UInt8>"
INPUT="c0:ff:ee"
EXPECT=$(echo -en "c0.ff.ee")
run_test_case
TEST_NAME=test-utf8-to-ascii
SRC_TYPE="<Seq Char~Unicode> ~ UTF-8 ~ <Seq ~ <ValueTerminated 0> native.UInt8>"
DST_TYPE="<Seq~<ValueTerminated 0> Char ~ Ascii ~ native.UInt8>"
INPUT="Hℵelαlo WΓΓΓorl⇒d"
EXPECT="Hello World"
run_test_case
TEST_NAME=test-value-sep-posint
SRC_TYPE="<Seq ~<PosInt 16 BigEndian>~<Seq <Digit 16>~Char~Ascii~native.UInt8>> ~ <ValueSep ':' Char~Ascii~native.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~native.UInt8>"
DST_TYPE="<Seq ~<PosInt 16 BigEndian>~<Seq <Digit 16>~Char~Ascii~native.UInt8>> ~ <ValueSep '.' Char~Ascii~native.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~native.UInt8>"
INPUT="c0:ff:ee"
EXPECT=$(echo -en "c0.ff.ee")
run_test_case