about summary refs log tree commit diff
path: root/t/2000-expr.t
diff options
context:
space:
mode:
Diffstat (limited to 't/2000-expr.t')
-rwxr-xr-xt/2000-expr.t252
1 files changed, 252 insertions, 0 deletions
diff --git a/t/2000-expr.t b/t/2000-expr.t
new file mode 100755
index 0000000..a564baa
--- /dev/null
+++ b/t/2000-expr.t
@@ -0,0 +1,252 @@
+#!/bin/sh
+. ./t/lib.sh
+
+plan 24
+
+check 'parse error detection' <<'EOF'
+lr -t 'xyzzy'
+>>>2 /parse error: unknown expression/
+>>>= 2
+EOF
+
+check 'number too big detection' <<'EOF'
+lr -t 'size > 99999999999999999999999999999999999999999'
+>>>2 /parse error: number too big/
+>>>= 2
+EOF
+
+check 'unterminated string' <<'EOF'
+lr -t 'name == "runaway'
+>>>2 /parse error: unterminated string/
+>>>= 2
+EOF
+
+check 'invalid regex' <<'EOF'
+lr -t 'name =~ "[runaway"'
+>>>2 /parse error: invalid regex/
+>>>= 2
+EOF
+
+check 'name' <<'EOF'
+treegen
+lr -t 'name == "a"'
+<<<
+f:a
+f:b
+f:c
+>>>
+a
+EOF
+
+check 'name, no match' <<'EOF'
+treegen
+lr -t 'name == "q"'
+<<<
+f:a
+f:b
+f:c
+>>>
+EOF
+
+check 'name, inner quotes' <<'EOF'
+treegen
+lr -t 'name == "quo""te"'
+<<<
+f:quo"te
+>>>
+quo"te
+EOF
+
+check 'name, environment variable' <<'EOF'
+treegen
+export NAME=b
+lr -t 'name == $NAME'
+<<<
+f:a
+f:b
+f:c
+>>>
+b
+EOF
+
+check 'name =~' <<'EOF'
+treegen
+lr -t 'name =~ "a|b"'
+<<<
+f:a
+f:b
+f:c
+>>>
+a
+b
+EOF
+
+check 'name =~~' <<'EOF'
+treegen
+lr -t 'name =~~ "a|b"'
+<<<
+f:A
+f:B
+f:C
+>>>
+A
+B
+EOF
+
+check 'name ~~' <<'EOF'
+treegen
+lr -t 'name ~~ "*.c"'
+<<<
+f:bar.c
+f:foo.c
+f:foo.h
+>>>
+bar.c
+foo.c
+EOF
+
+check 'name ~~~' <<'EOF'
+treegen
+lr -t 'name ~~~ "*.c"'
+<<<
+f:bar.c
+f:foo.C
+f:foo.h
+>>>
+bar.c
+foo.C
+EOF
+
+check 'type = f' <<'EOF'
+treegen
+lr -t 'type = f'
+<<<
+f:a
+f:b/c
+>>>
+a
+b/c
+EOF
+
+check 'type != f' <<'EOF'
+treegen
+lr -t 'type != f'
+<<<
+f:a
+f:b/c
+>>>
+.
+b
+EOF
+
+check 'type = l' <<'EOF'
+treegen
+lr -t 'type = l'
+<<<
+f:a
+l:a:b
+>>>
+b
+EOF
+
+check 'parentheses' <<'EOF'
+treegen
+lr -t '(((type = f)))'
+<<<
+f:a
+f:b/c
+>>>
+a
+b/c
+EOF
+
+check 'logic: or' <<'EOF'
+treegen
+lr -t 'name == "a" || name == "c"'
+<<<
+f:a
+f:b
+f:c
+>>>
+a
+c
+EOF
+
+check 'logic: negation' <<'EOF'
+treegen
+lr -t 'type = f && !(name == "a" || name == "c")'
+<<<
+f:a
+f:b
+f:c
+>>>
+b
+EOF
+
+check 'logic: and' <<'EOF'
+treegen
+lr -t 'name ~~ "*a*" && name ~~ "*c*"'
+<<<
+f:abc
+f:ade
+f:ebc
+>>>
+abc
+EOF
+
+check 'size ==' <<'EOF'
+treegen
+lr -t 'size == 42'
+<<<
+f:a
+f:b:42
+f:c
+>>>
+b
+EOF
+
+check 'size =' <<'EOF'
+treegen
+lr -t 'size = 42'
+<<<
+f:a
+f:b:42
+f:c
+>>>
+b
+EOF
+
+check 'size comparison, I' <<'EOF'
+treegen
+lr -t 'size > 40 && size < 60'
+<<<
+f:a
+f:b:42
+f:c:90
+>>>
+b
+EOF
+
+check 'size comparison, II' <<'EOF'
+treegen
+lr -t 'size > 1M && size < 1G'
+<<<
+f:a
+f:b:2097152
+f:c:90
+>>>
+b
+EOF
+
+check 'size comparison, III' <<'EOF'
+treegen
+lr -t 'size >= 4k'
+<<<
+f:a:4095
+f:b:4096
+f:c:4097
+>>>
+b
+c
+EOF
+