1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fold constants (fix #504)

This commit is contained in:
Nicolas Williams
2014-07-27 17:33:22 -05:00
parent ae27178352
commit 2e2538ccb8
4 changed files with 120 additions and 1 deletions

View File

@@ -20,6 +20,59 @@ if [ -z "$d" ]; then
exit 0
fi
## Test constant folding
# String constant folding (addition only)
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '"foo"' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
# Numeric constant folding (not all ops yet)
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '1+1' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '1-1' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '2*3' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '9/3' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '9==3' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '9!=3' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '9<=3' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
n=`$VALGRIND $Q ./jq -n --debug-dump-disasm '9>=3' | wc -l`
if [ $n -ne 5 ]; then
echo "Constant expression folding for strings didn't work"
exit 1
fi
## Test library/module system
cat > "$d/.jq" <<EOF
def foo: "baz";
def f: "wat";