aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-04-03 09:15:47 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-04-03 09:15:47 +0300
commit448c45412600cd9844caf2336f5bf6c459145d08 (patch)
treea14ba06e9823772f97cd7f6e1e4429f9798864bf
parent8d0b9648204d05537828e70ee1816834dc3b1d34 (diff)
downloadegawk-448c45412600cd9844caf2336f5bf6c459145d08.tar.gz
egawk-448c45412600cd9844caf2336f5bf6c459145d08.tar.bz2
egawk-448c45412600cd9844caf2336f5bf6c459145d08.zip
Add some test file for use during development.
-rw-r--r--a.awk7
-rw-r--r--hardregex-semantics.awk95
-rw-r--r--y.awk1
-rw-r--r--z.awk1
-rw-r--r--z2.awk8
-rw-r--r--z3.awk19
6 files changed, 131 insertions, 0 deletions
diff --git a/a.awk b/a.awk
new file mode 100644
index 00000000..daed9d9f
--- /dev/null
+++ b/a.awk
@@ -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...
+}
diff --git a/y.awk b/y.awk
new file mode 100644
index 00000000..820e321e
--- /dev/null
+++ b/y.awk
@@ -0,0 +1 @@
+BEGIN { f = "foo" ; sub(@/f/, "q", f); print f }
diff --git a/z.awk b/z.awk
new file mode 100644
index 00000000..5df943c8
--- /dev/null
+++ b/z.awk
@@ -0,0 +1 @@
+BEGIN { f = "foo" ; p = @/o/ ; gsub(p, "q", f); print f }
diff --git a/z2.awk b/z2.awk
new file mode 100644
index 00000000..0a597b22
--- /dev/null
+++ b/z2.awk
@@ -0,0 +1,8 @@
+BEGIN {
+ f = "foo"
+ p = @/o/
+// gsub(p, "q", f)
+ fun = "gsub"
+ @fun(p, "q", f)
+ print f
+}
diff --git a/z3.awk b/z3.awk
new file mode 100644
index 00000000..408f5259
--- /dev/null
+++ b/z3.awk
@@ -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")
+}