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:
		
							
								
								
									
										53
									
								
								tests/run
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								tests/run
									
									
									
									
									
								
							@@ -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";
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user