aboutsummaryrefslogtreecommitdiffstats
path: root/test/regexsub.awk
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2021-08-26 22:01:10 +0300
committerArnold D. Robbins <arnold@skeeve.com>2021-08-26 22:01:10 +0300
commit340b2837d42b956dbf9d34f9a66c674bb62ca377 (patch)
tree5ff147390f457eebc06628bcca06cb6d7c59d0c9 /test/regexsub.awk
parent251db3795ba7dc4054c2df486c0e0e91e0b28f58 (diff)
parent585a9456283db7169ea53a328824e55deb998d8f (diff)
downloadegawk-340b2837d42b956dbf9d34f9a66c674bb62ca377.tar.gz
egawk-340b2837d42b956dbf9d34f9a66c674bb62ca377.tar.bz2
egawk-340b2837d42b956dbf9d34f9a66c674bb62ca377.zip
Merge branch 'gawk-5.1-stable'
Diffstat (limited to 'test/regexsub.awk')
-rw-r--r--test/regexsub.awk48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/regexsub.awk b/test/regexsub.awk
new file mode 100644
index 00000000..92dede7b
--- /dev/null
+++ b/test/regexsub.awk
@@ -0,0 +1,48 @@
+BEGIN {
+ print "Initialize strong regex"
+ rgx2 = rgx1 = @/[abc]/
+ print "Test gsub on strong regex"
+ printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 1, rgx1, 1, typeof(rgx1))
+ printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 2, rgx2, 2, typeof(rgx2))
+ print "Test gsub() a strong regex"
+ gsub(/b/, "e", rgx2)
+ printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 1, rgx1, 1, typeof(rgx1))
+ printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 2, rgx2, 2, typeof(rgx2))
+
+ print "Test value not found in regex"
+ gsub(/x/, "y", rgx1) # should not change
+ printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 1, rgx1, 1, typeof(rgx1))
+
+ print "Test gsub on numbers"
+ v2 = v1 = 12345
+ printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 1, v1, 1, typeof(v1))
+ printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 2, v2, 2, typeof(v2))
+ gsub(/3/, "x", v2)
+ printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 1, v1, 1, typeof(v1))
+ printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 2, v2, 2, typeof(v2))
+ print "Test value not found in number"
+ gsub(/9/, "x", v1)
+ printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 1, v1, 1, typeof(v1))
+
+ print "Test gensub on regex"
+ a = b = @/abc/
+ c = gensub(/b/, "x", "g", a)
+ printf("a = @/%s/\ttypeof(a) = '%s'\n", a, typeof(a))
+ printf("c = \"%s\"\ttypeof(c) = '%s'\n", c, typeof(c))
+ print "Test value not found in regex"
+ c = gensub(/q/, "x", "g", b)
+ printf("b = @/%s/\ttypeof(b) = '%s'\n", b, typeof(b))
+ printf("c = \"%s\"\ttypeof(c) = '%s'\n", c, typeof(c))
+
+ print "Test gensub on numbers"
+ a = b = 12345
+ c = gensub(/3/, "x", "g", a)
+ printf("a = \"%s\"\ttypeof(a) = '%s'\n", a, typeof(a))
+ printf("b = \"%s\"\ttypeof(b) = '%s'\n", b, typeof(b))
+ printf("c = \"%s\"\ttypeof(c) = '%s'\n", c, typeof(c))
+ print "Test value not found in number"
+ c = gensub(/9/, "x", "g", b)
+ printf("b = \"%s\"\ttypeof(b) = '%s'\n", b, typeof(b))
+ printf("c = \"%s\"\ttypeof(c) = '%s'\n", c, typeof(c))
+ print typeof(c), c
+}