#!/bin/bash # # argtype_test.sh -- the @@@argtype description is Klammertext source # (engine tier: -k none, every definition inline). # # Decided 2026-09-13 (Andy): the second argument of @@@argtype has the # "klammertext" type, so Argtype::m_desc holds the description EXACTLY AS # WRITTEN -- # a quoted "^@date" keeps its caret -- and whoever displays it hands the # text to a Machine (kdesc's listing through ref/, the Handbook). Before, # the description was assembled from katom text, where the katomizer has # already stripped the caret of a quoted special, so "(^@date and # ^@datetime)" reached the generator as "(@date and @datetime)" and re-read # as two klammer applications. A display that cannot render -- an argument # error -- shows the source unquoted instead. # # Note the neighbour: tst/argtype_test (no .sh) is the C++ diagnostic # program, the fourth such name collision after eval, state and target. # # Usage: ./argtype_test.sh (needs KLAMMERTEXT_HOME set; ktext/kdiag on PATH) # Exit code: 0 if all tests pass, 1 otherwise. KTEXT="${KTEXT:-ktext}"; KDIAG="${KDIAG:-kdiag}" PASS=0; FAIL=0 red=$'\033[31m'; green=$'\033[32m'; bold=$'\033[1m'; reset=$'\033[0m' pass() { echo "${green}PASS${reset} $1"; PASS=$((PASS+1)); } fail() { echo "${red}FAIL${reset} $1"; [ -n "$2" ] && echo " $2"; FAIL=$((FAIL+1)); } flat() { tr '\n' ' ' | tr -s ' '; } # error text is justified: match wrap-insensitively echo "${bold}@@@argtype description tests${reset}" echo "============================" echo DEF='@@@target tt | T @@@ @@@argtype lang | see ^@date and ^: here, ^| bar too :pattern [a-z][a-z] @@@' T=$(mktemp -d) # 1. The registry holds the source as written (kdiag --machine is the # programmer's dump and shows the stored text). out=$("$KDIAG" --system --machine "$DEF" 2>&1 | flat) if echo "$out" | grep -qF 'see ^@date and ^: here, ^| bar too'; then pass " 1. the description is stored exactly as written (carets kept)" else fail " 1. the description is stored exactly as written (carets kept)" "$(echo "$out" | grep -o 'lang.\{0,60\}' | head -1)"; fi # 2. A quoted ":" inside the description does not start an option: the # :pattern that follows is still the pattern (a valid value passes). out=$("$KTEXT" --klammersets none -s "$DEF @@w.k c.lang : W @@ @@w.tt :: [*c*] @@ @w de @" -t tt -d 2>&1 | flat) if echo "$out" | grep -qF '[de]'; then pass " 2. ^: in the description does not end it; :pattern still applies" else fail " 2. ^: in the description does not end it; :pattern still applies" "$out"; fi # 3. An invalid value's error shows the description UNQUOTED -- plain text # for a reader who cannot render it. out=$("$KTEXT" --klammersets none -s "$DEF @@w.k c.lang : W @@ @@w.tt :: [*c*] @@ @w 123 @" -t tt -d 2>&1 | flat) if echo "$out" | grep -qF 'describes see @date and : here, | bar too'; then pass " 3. an argument error shows the description unquoted" else fail " 3. an argument error shows the description unquoted" "$out"; fi if ! echo "$out" | grep -qF '^@'; then pass " 4. ... and no caret leaks into the error" else fail " 4. ... and no caret leaks into the error"; fi # 5. A klammer's LITERAL parameter is a different type and is untouched: # its "^" forms are processed ("^@" prints "@"), as they always were. The application is in a # FILE after the -s definitions: the literal-marking pass needs the # klammer registered before the unit holding the application is read, # and "--" ends the --klammersets list before the filename. printf '@lit ^@ and # and | x lit@\n' > "$T/lit.kt" out=$("$KTEXT" --klammersets none -s '@@@target tt | T @@@ @@lit.k t.literal : L @@ @@lit.tt :: [*t*] @@' -- "$T/lit.kt" -t tt -d 2>&1 | flat) if echo "$out" | grep -qF '[@ and # and | x]'; then pass " 5. the literal parameter of a klammer still holds its content as written" else fail " 5. the literal parameter of a klammer still holds its content as written" "$out"; fi rm -rf "$T" echo echo "============================" echo "Results: ${green}$PASS passed${reset}, ${red}$FAIL failed${reset}" [ $FAIL -eq 0 ]