aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am4
-rw-r--r--test/Makefile.in9
-rw-r--r--test/Maketests5
-rw-r--r--test/regexsub.awk48
-rw-r--r--test/regexsub.ok30
6 files changed, 99 insertions, 2 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 387c6a9d..4fab85b2 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2021-08-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): regexsub, new test.
+ * regexsub.awk, regexsub.ok: New files.
+
2021-05-15 Eli Zaretskii <eliz@gnu.org>
* iolint.ok: Reorder results to follow the order of iolint.awk.
diff --git a/test/Makefile.am b/test/Makefile.am
index 3b8815d8..94dba463 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1059,6 +1059,8 @@ EXTRA_DIST = \
regexpbrack2.ok \
regexprange.awk \
regexprange.ok \
+ regexsub.awk \
+ regexsub.ok \
reginttrad.awk \
reginttrad.ok \
regnul1.awk \
@@ -1458,7 +1460,7 @@ GAWK_EXT_TESTS = \
procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
profile7 profile8 profile9 profile10 profile11 profile12 profile13 \
profile14 profile15 pty1 pty2 \
- rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin \
+ rebuf regexsub regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin \
rsstart1 rsstart2 rsstart3 rstest6 \
sandbox1 shadow shadowbuiltin sortfor sortfor2 sortu \
sourcesplit split_after_fpat \
diff --git a/test/Makefile.in b/test/Makefile.in
index 43003216..18ccdfcb 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1322,6 +1322,8 @@ EXTRA_DIST = \
regexpbrack2.ok \
regexprange.awk \
regexprange.ok \
+ regexsub.awk \
+ regexsub.ok \
reginttrad.awk \
reginttrad.ok \
regnul1.awk \
@@ -1721,7 +1723,7 @@ GAWK_EXT_TESTS = \
procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
profile7 profile8 profile9 profile10 profile11 profile12 profile13 \
profile14 profile15 pty1 pty2 \
- rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin \
+ rebuf regexsub regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin \
rsstart1 rsstart2 rsstart3 rstest6 \
sandbox1 shadow shadowbuiltin sortfor sortfor2 sortu \
sourcesplit split_after_fpat \
@@ -4821,6 +4823,11 @@ profile15:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+regexsub:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regnul1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index fabc2ad5..ac6c98b6 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1885,6 +1885,11 @@ profile15:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+regexsub:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regnul1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
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
+}
diff --git a/test/regexsub.ok b/test/regexsub.ok
new file mode 100644
index 00000000..44511ebc
--- /dev/null
+++ b/test/regexsub.ok
@@ -0,0 +1,30 @@
+Initialize strong regex
+Test gsub on strong regex
+rgx1 = '[abc]' typeof(rgx1) = 'regexp'
+rgx2 = '[abc]' typeof(rgx2) = 'regexp'
+Test gsub() a strong regex
+rgx1 = '[abc]' typeof(rgx1) = 'regexp'
+rgx2 = '[aec]' typeof(rgx2) = 'regexp'
+Test value not found in regex
+rgx1 = '[abc]' typeof(rgx1) = 'regexp'
+Test gsub on numbers
+v1 = '12345' typeof(v1) = 'number'
+v2 = '12345' typeof(v2) = 'number'
+v1 = '12345' typeof(v1) = 'number'
+v2 = '12x45' typeof(v2) = 'string'
+Test value not found in number
+v1 = '12345' typeof(v1) = 'number'
+Test gensub on regex
+a = @/abc/ typeof(a) = 'regexp'
+c = "axc" typeof(c) = 'string'
+Test value not found in regex
+b = @/abc/ typeof(b) = 'regexp'
+c = "abc" typeof(c) = 'string'
+Test gensub on numbers
+a = "12345" typeof(a) = 'number'
+b = "12345" typeof(b) = 'number'
+c = "12x45" typeof(c) = 'string'
+Test value not found in number
+b = "12345" typeof(b) = 'number'
+c = "12345" typeof(c) = 'string'
+string 12345