diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ChangeLog | 6 | ||||
-rw-r--r-- | test/Makefile.am | 9 | ||||
-rw-r--r-- | test/Makefile.in | 23 | ||||
-rw-r--r-- | test/Maketests | 12 | ||||
-rw-r--r-- | test/gsubind.awk | 9 | ||||
-rw-r--r-- | test/gsubind.ok | 3 | ||||
-rw-r--r-- | test/typedregex1.awk | 296 | ||||
-rw-r--r-- | test/typedregex1.ok | 37 | ||||
-rw-r--r-- | test/typeof1.awk | 9 | ||||
-rw-r--r-- | test/typeof1.ok | 7 |
10 files changed, 406 insertions, 5 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 59b9fd40..b57a756f 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2015-06-19 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (gsubind, typedregex1, typeof1): New tests. + * gsubind.awk, gsubind.ok, typedregex1.awk, typedregex1.ok, + typeof1.awk, typeof1.ok: New files. + 2015-06-17 Andrew J. Schorr <aschorr@telemetry-investments.com> * inplace1.ok, inplace2.ok, inplace3.ok: Update line number in error diff --git a/test/Makefile.am b/test/Makefile.am index f13fa2fb..537a5655 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -381,6 +381,8 @@ EXTRA_DIST = \ gnureops.ok \ gsubasgn.awk \ gsubasgn.ok \ + gsubind.awk \ + gsubind.ok \ gsubtest.awk \ gsubtest.ok \ gsubtst2.awk \ @@ -979,6 +981,10 @@ EXTRA_DIST = \ tweakfld.awk \ tweakfld.in \ tweakfld.ok \ + typedregex1.awk \ + typedregex1.ok \ + typeof1.awk \ + typeof1.ok \ uninit2.awk \ uninit2.ok \ uninit3.awk \ @@ -1076,7 +1082,7 @@ GAWK_EXT_TESTS = \ colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars errno exit \ fieldwdth fpat1 fpat2 fpat3 fpat4 fpatnull fsfwfs funlen \ functab1 functab2 functab3 fwtest fwtest2 fwtest3 \ - genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops \ + genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops gsubind \ icasefs icasers id igncdym igncfs ignrcas2 ignrcase \ incdupe incdupe2 incdupe3 incdupe4 incdupe5 incdupe6 incdupe7 \ include include2 indirectbuiltin indirectcall indirectcall2 \ @@ -1093,6 +1099,7 @@ GAWK_EXT_TESTS = \ splitarg4 strftime \ strtonum switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 \ symtab7 symtab8 symtab9 \ + typedregex1 typeof1 timeout EXTRA_TESTS = inftest regtest diff --git a/test/Makefile.in b/test/Makefile.in index 08c04a02..a8895ed7 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -638,6 +638,8 @@ EXTRA_DIST = \ gnureops.ok \ gsubasgn.awk \ gsubasgn.ok \ + gsubind.awk \ + gsubind.ok \ gsubtest.awk \ gsubtest.ok \ gsubtst2.awk \ @@ -1236,6 +1238,10 @@ EXTRA_DIST = \ tweakfld.awk \ tweakfld.in \ tweakfld.ok \ + typedregex1.awk \ + typedregex1.ok \ + typeof1.awk \ + typeof1.ok \ uninit2.awk \ uninit2.ok \ uninit3.awk \ @@ -1332,7 +1338,7 @@ GAWK_EXT_TESTS = \ colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars errno exit \ fieldwdth fpat1 fpat2 fpat3 fpat4 fpatnull fsfwfs funlen \ functab1 functab2 functab3 fwtest fwtest2 fwtest3 \ - genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops \ + genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops gsubind \ icasefs icasers id igncdym igncfs ignrcas2 ignrcase \ incdupe incdupe2 incdupe3 incdupe4 incdupe5 incdupe6 incdupe7 \ include include2 indirectbuiltin indirectcall indirectcall2 \ @@ -1349,7 +1355,7 @@ GAWK_EXT_TESTS = \ splitarg4 strftime \ strtonum switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 \ symtab7 symtab8 symtab9 \ - timeout + typedregex1 typeof1 EXTRA_TESTS = inftest regtest INET_TESTS = inetdayu inetdayt inetechu inetecht @@ -1591,6 +1597,7 @@ uninstall-am: .PRECIOUS: Makefile + timeout # Message stuff is to make it a little easier to follow. # Make the pass-fail last and dependent on others to avoid @@ -3648,6 +3655,11 @@ gnureops: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +gsubind: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + icasefs: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @@ -3883,7 +3895,12 @@ symtab7: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -timeout: +typedregex1: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +typeof1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ diff --git a/test/Maketests b/test/Maketests index 017caa76..a674d5d0 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1092,6 +1092,11 @@ gnureops: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +gsubind: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + icasefs: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @@ -1327,7 +1332,12 @@ symtab7: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -timeout: +typedregex1: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +typeof1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ diff --git a/test/gsubind.awk b/test/gsubind.awk new file mode 100644 index 00000000..fce0d818 --- /dev/null +++ b/test/gsubind.awk @@ -0,0 +1,9 @@ +BEGIN { + f = "foo" + p = @/o/ + gsub(p, "q", f) + print f + fun = "gsub" + @fun(p, "q", f) + print f +} diff --git a/test/gsubind.ok b/test/gsubind.ok new file mode 100644 index 00000000..d25f018a --- /dev/null +++ b/test/gsubind.ok @@ -0,0 +1,3 @@ +fqq +gawk: gsubind.awk:7: fatal: gsub: can be called indirectly only with two arguments +EXIT CODE: 2 diff --git a/test/typedregex1.awk b/test/typedregex1.awk new file mode 100644 index 00000000..fc8ba805 --- /dev/null +++ b/test/typedregex1.awk @@ -0,0 +1,296 @@ +# 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 regexp 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" +} + +function match_tests( fbre, fun) +{ + if (match("foobaaar", @/fo+ba+r/)) + print "match(constant): ok" + else + print "match(constant): fail" + + fbre = @/fo+ba+r/ + if (match("foobaaar", fbre)) + print "match(variable): ok" + else + print "match(variable): fail" + + fun = "match" + if (@fun("foobaaar", @/fo+ba+r/)) + print "match(constant) indirect: ok" + else + print "match(constant) indirect: fail" + + if (@fun("foobaaar", fbre)) + print "match(variable) indirect: ok" + else + print "match(variable) indirect: fail" +} + +function sub_tests( fbre, count, target, fun) +{ + target = "abc foobaar def foobar ghi" + count = sub(@/fo+ba+r/, "XX", target) + if (count == 1 && target == "abc XX def foobar ghi") + print "sub(constant): ok" + else + print "sub(constant): fail" + + fbre = @/fo+ba+r/ + target = "abc foobaar def foobar ghi" + count = sub(fbre, "XX", target) + if (count == 1 && target == "abc XX def foobar ghi") + print "sub(variable): ok" + else + print "sub(variable): fail" + + fun = "sub" + $0 = "abc foobaar def foobar ghi" + count = @fun(@/fo+ba+r/, "XX") + if (count == 1 && $0 == "abc XX def foobar ghi") + print "sub(constant) indirect: ok" + else + print "sub(constant) indirect: fail" + + $0 = "abc foobaar def foobar ghi" + count = @fun(fbre, "XX") + if (count == 1 && $0 == "abc XX def foobar ghi") + print "sub(variable) indirect: ok" + else + print "sub(variable) indirect: fail" +} + +function gsub_tests( fbre, count, target, fun) +{ + target = "abc foobaar def foobar ghi" + count = gsub(@/fo+ba+r/, "XX", target) + if (count == 2 && target == "abc XX def XX ghi") + print "gsub(constant): ok" + else + print "gsub(constant): fail" + + fbre = @/fo+ba+r/ + target = "abc foobaar def foobar ghi" + count = gsub(fbre, "XX", target) + if (count == 2 && target == "abc XX def XX ghi") + print "gsub(variable): ok" + else + print "gsub(variable): fail" + + fun = "gsub" + $0 = "abc foobaar def foobar ghi" + count = @fun(@/fo+ba+r/, "XX") + if (count == 2 && $0 == "abc XX def XX ghi") + print "gsub(constant) indirect: ok" + else + print "gsub(constant) indirect: fail" + + $0 = "abc foobaar def foobar ghi" + count = @fun(fbre, "XX") + if (count == 2 && $0 == "abc XX def XX ghi") + print "gsub(variable) indirect: ok" + else + print "gsub(variable) indirect: fail" +} + +function gensub_tests( fbre, result, target, fun) +{ + target = "abc foobaar def foobar ghi" + result = gensub(@/fo+ba+r/, "XX", "g", target) + if (result == "abc XX def XX ghi") + print "gensub(constant): ok" + else + print "gensub(constant): fail" + + fbre = @/fo+ba+r/ + target = "abc foobaar def foobar ghi" + result = gensub(fbre, "XX", "g", target) + if (result == "abc XX def XX ghi") + print "gensub(variable): ok" + else + print "gensub(variable): fail" + + fun = "gensub" + $0 = "abc foobaar def foobar ghi" + result = @fun(@/fo+ba+r/, "XX", "g") + if (result == "abc XX def XX ghi") + print "gensub(constant) indirect: ok" + else + print "gensub(constant) indirect: fail" + + $0 = "abc foobaar def foobar ghi" + result = @fun(fbre, "XX", "g") + if (result == "abc XX def XX ghi") + print "gensub(variable) indirect: ok" + else + print "gensub(variable) indirect: fail" + + result = @fun(@/fo+ba+r/, "XX", "g", target) + if (result == "abc XX def XX ghi") + print "gensub(constant) indirect 2: ok" + else + print "gensub(constant) indirect 2: fail" + + result = @fun(fbre, "XX", "g", target) + if (result == "abc XX def XX ghi") + print "gensub(variable) indirect 2: ok" + else + print "gensub(variable) indirect 2: fail" +} + +function split_tests( fbre, data, seps, fun, b1) +{ + delete data + delete seps + b1 = split("a:b:c:d", data, @/:/, seps) + if (b1 == 4 && data[1] == "a" && seps[1] == ":") + print "split(constant): ok" + else + print "split(constant): fail" + + delete data + delete seps + fbre = @/:/ + b1 = split("a:b:c:d", data, fbre, seps) + if (b1 == 4 && data[1] == "a" && seps[1] == ":") + print "split(variable): ok" + else + print "split(variable): fail" + + fun = "split" + delete data + delete seps + b1 = @fun("a:b:c:d", data, @/:/, seps) + if (b1 == 4 && data[1] == "a" && seps[1] == ":") + print "split(constant) indirect: ok" + else + print "split(constant) indirect: fail" + + delete data + delete seps + b1 = @fun("a:b:c:d", data, fbre, seps) + if (b1 == 4 && data[1] == "a" && seps[1] == ":") + print "split(variable) indirect: ok" + else + print "split(variable) indirect: fail" +} + +function patsplit_tests( fbre, data, seps, fun, b1) +{ + delete data + delete seps + b1 = patsplit("a:b:c:d", data, @/[a-z]+/, seps) + if (b1 == 4 && data[1] == "a" && seps[1] == ":") + print "patsplit(constant): ok" + else + print "patsplit(constant): fail" + + delete data + delete seps + fbre = @/[a-z]+/ + b1 = patsplit("a:b:c:d", data, fbre, seps) + if (b1 == 4 && data[1] == "a" && seps[1] == ":") + print "patsplit(variable): ok" + else + print "patsplit(variable): fail" + + fun = "patsplit" + delete data + delete seps + b1 = @fun("a:b:c:d", data, @/[a-z]+/, seps) + if (b1 == 4 && data[1] == "a" && seps[1] == ":") + print "patsplit(constant) indirect: ok" + else + print "patsplit(constant) indirect: fail" + + delete data + delete seps + b1 = @fun("a:b:c:d", data, fbre, seps) + if (b1 == 4 && data[1] == "a" && seps[1] == ":") + print "patsplit(variable) indirect: ok" + else + print "patsplit(variable) indirect: fail" +} + +BEGIN { + simple_tests() + match_tests() + sub_tests() + gsub_tests() + gensub_tests() + split_tests() + patsplit_tests() +} diff --git a/test/typedregex1.ok b/test/typedregex1.ok new file mode 100644 index 00000000..03ef7cfa --- /dev/null +++ b/test/typedregex1.ok @@ -0,0 +1,37 @@ +switch-case: ok +match ~: ok +match !~: ok +variable match ~: ok +variable match !~: ok +variable as numeric value: ok +variable as string value: ok +typeof constant: ok +typeof variable: ok +conversion to number: ok +typeof variable after conversion: ok +match(constant): ok +match(variable): ok +match(constant) indirect: ok +match(variable) indirect: ok +sub(constant): ok +sub(variable): ok +sub(constant) indirect: ok +sub(variable) indirect: ok +gsub(constant): ok +gsub(variable): ok +gsub(constant) indirect: ok +gsub(variable) indirect: ok +gensub(constant): ok +gensub(variable): ok +gensub(constant) indirect: ok +gensub(variable) indirect: ok +gensub(constant) indirect 2: ok +gensub(variable) indirect 2: ok +split(constant): ok +split(variable): ok +split(constant) indirect: ok +split(variable) indirect: ok +patsplit(constant): ok +patsplit(variable): ok +patsplit(constant) indirect: ok +patsplit(variable) indirect: ok diff --git a/test/typeof1.awk b/test/typeof1.awk new file mode 100644 index 00000000..c301030e --- /dev/null +++ b/test/typeof1.awk @@ -0,0 +1,9 @@ +BEGIN { + a = 5 ; print typeof(a) + print typeof(b) + print typeof(@/foo/) + c = "foo" ; print typeof(c) + d[1] = 1 ; print typeof(d), typeof(d[1]) + e = @/foo/ ; print typeof(e) + print typeof(@/bar/) +} diff --git a/test/typeof1.ok b/test/typeof1.ok new file mode 100644 index 00000000..3a2f6a92 --- /dev/null +++ b/test/typeof1.ok @@ -0,0 +1,7 @@ +scalar_n +untyped +regexp +scalar_s +array scalar_n +regexp +regexp |