diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-03 09:15:47 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-03 09:15:47 +0300 |
commit | 448c45412600cd9844caf2336f5bf6c459145d08 (patch) | |
tree | a14ba06e9823772f97cd7f6e1e4429f9798864bf | |
parent | 8d0b9648204d05537828e70ee1816834dc3b1d34 (diff) | |
download | egawk-448c45412600cd9844caf2336f5bf6c459145d08.tar.gz egawk-448c45412600cd9844caf2336f5bf6c459145d08.tar.bz2 egawk-448c45412600cd9844caf2336f5bf6c459145d08.zip |
Add some test file for use during development.
-rw-r--r-- | a.awk | 7 | ||||
-rw-r--r-- | hardregex-semantics.awk | 95 | ||||
-rw-r--r-- | y.awk | 1 | ||||
-rw-r--r-- | z.awk | 1 | ||||
-rw-r--r-- | z2.awk | 8 | ||||
-rw-r--r-- | z3.awk | 19 |
6 files changed, 131 insertions, 0 deletions
@@ -0,0 +1,7 @@ +BEGIN { + f = "foo" + p = "o+" + fun = "match" + @fun(f, p) + print RSTART, RLENGTH +} diff --git a/hardregex-semantics.awk b/hardregex-semantics.awk new file mode 100644 index 00000000..84fcef93 --- /dev/null +++ b/hardregex-semantics.awk @@ -0,0 +1,95 @@ +# This file describes the semantics for hard regex constants +# As much as possible it's executable code so that it can be used +# (or split into) test cases for development and regression testing. + +function simple_tests( fbre, numresult, strresult) +{ + # usable as case value + switch ("foobaaar") { + case @/fo+ba+r/: + print "switch-case: ok" + break + default: + print "switch-case: fail" + break + } + + # usable with ~ and !~ + if ("foobaaar" ~ @/fo+ba+r/) + print "match ~: ok" + else + print "match ~: fail" + + if ("quasimoto" !~ @/fo+ba+r/) + print "match !~: ok" + else + print "match !~: fail" + + # assign to variable, use in match + fbre = @/fo+ba+r/ + if ("foobaaar" ~ fbre) + print "variable match ~: ok" + else + print "variable match ~: fail" + + if ("quasimoto" !~ fbre) + print "variable match !~: ok" + else + print "variable match !~: fail" + + # Use as numeric value, should be zero + numresult = fbre + 42 + if (numresult == 42) + print "variable as numeric value: ok" + else + print "variable as numeric value: fail" + + # Use as string value, should be string value of text + strresult = "<" fbre ">" + if (strresult == "<fo+ba+r>") + print "variable as string value: ok" + else + print "variable as string value: fail", strresult + + # typeof should work + if (typeof(@/fo+ba+r/) == "regexp") + print "typeof constant: ok" + else + print "typeof constant: fail" + + if (typeof(fbre) == "regexp") + print "typeof variable: ok" + else + print "typeof variable: fail" + + # conversion to number, works. should it be fatal? + fbre++ + if (fbre == 1) + print "conversion to number: ok" + else + print "conversion to number: fail" + + if (typeof(fbre) == "scalar_n") + print "typeof variable after conversion: ok" + else + print "typeof variable after conversion: fail" +} + +BEGIN { + simple_tests() + + # use with match, constant + # use with match, variable + # use with sub, constant + # use with sub, variable + # use with gsub, constant + # use with gsub, variable + # use with gensub, constant + # use with gensub, variable + # use with split, constant + # use with split, variable + # use with patsplit, constant + # use with patsplit, variable + + # indirect call tests... +} @@ -0,0 +1 @@ +BEGIN { f = "foo" ; sub(@/f/, "q", f); print f } @@ -0,0 +1 @@ +BEGIN { f = "foo" ; p = @/o/ ; gsub(p, "q", f); print f } @@ -0,0 +1,8 @@ +BEGIN { + f = "foo" + p = @/o/ +// gsub(p, "q", f) + fun = "gsub" + @fun(p, "q", f) + print f +} @@ -0,0 +1,19 @@ +function testit(count, re, repl, fun, bi, n1, n2) +{ + $0 = "foo" + n1 = gsub(re, repl) + bi = $0 + + $0 = "foo" + fun = "gsub" + n2 = @fun(re, repl) + printf("%d: n1 = %d, bi -> %s, n2 = %d, indirect -> %s\n", + count, n1, bi, n2, $0) +} + +BEGIN { + testit(1, @/o/, "q") + p = @/o/ +stopme() + testit(2, p, "q") +} |