shithub: kwa

Download patch

ref: 7e6d7d36f83f05f372cfbce43534a2747bfc39c3
parent: e6dff2afe66a7aea90440fe000f6b2f7513f1888
author: qwx <qwx@sciops.net>
date: Thu Sep 25 18:01:06 EDT 2025

add more tests

--- a/test/Compare.T1
+++ b/test/Compare.T1
@@ -1,6 +1,6 @@
 #!/bin/rc
 rfork e
-oldawk=trueawk
+oldawk=awk
 awk=kwa
 
 for(i in T.*)
--- /dev/null
+++ b/test/T.builtin
@@ -1,0 +1,88 @@
+#!/bin/rc
+echo T.builtin: test miscellaneous builtin functions
+
+$awk 'BEGIN { print index(123, substr(123, 2)) }' >foo1
+echo 2 >foo2
+diff foo1 foo2 || echo 'BAD: T.builtin (index/substr)'
+
+$awk 'BEGIN {
+	pi = 2 * atan2(1, 0)
+	printf("%.5f %.3f %.3f %.5f %.3f\n",
+		pi, sin(pi), cos(pi/2), exp(log(pi)), log(exp(10)))
+}' >foo1
+echo '3.14159 0.000 0.000 3.14159 10.000' >foo2
+diff foo1 foo2 || echo 'BAD: T.builtin (sin/cos)'
+
+$awk 'BEGIN {
+	s = srand(1)	# set a real random start
+	for (i = 1; i <= 10; i++)
+		print rand() >"foo1"
+	srand(s)	# reset it
+	for (i = 1; i <= 10; i++)
+		print rand() >"foo2"
+}'
+diff foo1 foo2 || echo 'BAD: T.builtin (rand)'
+
+echo 'hello, WORLD!' |
+$awk '{ printf("%s|%s|%s\n", tolower($0), toupper($0), $0)}' >foo1
+echo 'hello, world!|HELLO, WORLD!|hello, WORLD!' >foo2
+diff foo1 foo2 || echo 'BAD: T.builtin (toupper/tolower)'
+
+
+echo 'Dürst' |
+$awk '{ printf("%s|%s|%s\n", tolower($0), toupper($0), $0)}' >foo1
+echo 'dürst|DÜRST|Dürst' >foo2
+diff foo1 foo2 || echo 'BAD: T.builtin (toupper/tolower) for utf-8'
+
+$awk 'BEGIN { print 0.01 }' /dev/null >foo1
+echo '0.01' >foo2
+diff foo1 foo2 || echo 'BAD: T.builtin LC_NUMERIC radix (.) handling' 
+
+$awk 'BEGIN {
+	j = 1; sprintf("%d", 99, ++j)	# does j get incremented?
+	if (j != 2)
+		print "BAD: T.builtin (printf arg list not evaluated)"
+}'
+
+$awk 'BEGIN {
+	j = 1; substr("", 1, ++j)	# does j get incremented?
+	if (j != 2)
+		print "BAD: T.builtin (substr arg list not evaluated)"
+}'
+
+$awk 'BEGIN {
+	j = 1; sub(/1/, ++j, z)	# does j get incremented?
+	if (j != 2)
+		print "BAD: T.builtin (sub() arg list not evaluated)"
+}'
+
+$awk 'BEGIN {
+	j = 1; length("zzzz", ++j, ++j)	# does j get incremented?
+	if (j != 3)
+		print "BAD: T.builtin (excess length args not evaluated)"
+}' >[2]foo
+grep 'too many arg' foo >/dev/null || echo 'T.bad: too many args not caught'
+
+echo 'a
+a b
+a b c' >foo0
+echo '1
+2
+3' >foo1
+$awk '{ n = split($0, x); print length(x) }' <foo0 >foo2
+diff foo1 foo2 || echo 'BAD: T.builtin length array'
+
+# Test for backslash handling
+cat <<'EOF' >foo0
+BEGIN {
+    print "A\
+B";
+    print "CD"
+}
+EOF
+$awk -f foo0 /dev/null >foo1
+cat <<'EOF' >foo2
+AB
+CD
+EOF
+diff foo1 foo2 || echo 'BAD: T.builtin continuation handling (backslash)' 
--- /dev/null
+++ b/test/T.chem
@@ -1,0 +1,8 @@
+#!/bin/rc
+echo T.chem:  test chem.awk
+
+for(i in lsd1.p penicil.p res.p){
+	$awk -f chem.awk $i >foo1
+	$oldawk -f chem.awk $i >foo2
+	diff foo1 foo2 || echo 'BAD: T.chem on '^$i
+}
--- /dev/null
+++ b/test/T.delete
@@ -1,0 +1,20 @@
+#!/bin/rc
+echo T.delete: misc tests of array deletion
+
+echo '1 2 3 4
+1 2 3
+1
+' >foo0
+echo '4 3 0
+3 2 0
+1 0 0
+0 0 0' >foo2
+$awk '
+{	n = split($0, x)
+	delete x[1]
+	n1 = 0;	for (i in x) n1++
+	delete x; 
+	n2 = 0; for (i in x) n2++
+	print n, n1, n2
+}' foo0 >foo1
+diff foo1 foo2 || echo 'BAD: T.delete (1)'
--- /dev/null
+++ b/test/T.exprconv
@@ -1,0 +1,20 @@
+#!/bin/rc
+echo T.exprconv:  check conversion of expr to number
+
+$awk '
+BEGIN {	x = (1 > 0); print x
+	x = (1 < 0); print x
+	x = (1 == 1); print x
+	print ("a" >= "b")
+	print ("b" >= "a")
+	print (0 == 0.0)
+	# x = ((1 == 1e0) && (1 == 10e-1) && (1 == .1e2)); print x
+	exit
+}' >foo1
+echo '1
+0
+1
+0
+1
+1' >foo2
+cmp foo1 foo2 || echo 'BAD: T.exprconv (1 > 0, etc.)'
--- /dev/null
+++ b/test/lsd1.p
@@ -1,0 +1,15 @@
+.cstart
+B:	benzene pointing right
+F:	flatring pointing left put N at 5 double 3,4 with .V1 at B.V2
+	H below F.N
+R:	ring pointing right with .V4 at B.V6
+	front bond right from R.V6 ; H
+W:	ring pointing right with .V2 at R.V6 put N at 1 double 3,4
+	bond right from W.N ; CH3
+	back bond -60 from W.V5 ; H
+	bond up from W.V5 ; C
+	doublebond up from C ; O
+	bond right from C ; N
+	bond 45 from N ; C2H5
+	bond 135 from N ; C2H5
+.cend
--- /dev/null
+++ b/test/penicil.p
@@ -1,0 +1,39 @@
+.so /usr/bwk/talks/vg.mac
+.vg
+.ft R
+.cstart
+	# this is the structure of penicillin G, an antibiotic
+size 14
+R1:	ring4 pointing 45 put N at 2 
+	doublebond -135 from R1.V3 ; O
+	backbond up from R1.V1 ; H
+	frontbond -45 from R1.V4 ; N
+	H above N
+	bond left from N ; C
+	doublebond up ; O
+	bond length .1 left from C ; CH2
+	bond length .1 left
+	benzene pointing left
+R2:	flatring5 put S at 1 put N at 4 with .V5 at R1.V1
+	bond 20 from R2.V2 ; CH3
+	bond 90 from R2.V2 ; CH3
+	bond 90 from R2.V3 ; H
+	backbond 170 from R2.V3 ; COOH
+.cend
+.CW
+	# this is the structure of penicillin G, an antibiotic
+R1:	ring4 pointing 45 put N at 2 
+	doublebond -135 from R1.V3 ; O
+	backbond up from R1.V1 ; H
+	frontbond -45 from R1.V4 ; N
+	H above N
+	bond left from N ; C
+	doublebond up ; O
+	bond length .1 left from C ; CH2
+	bond length .1 left
+	benzene pointing left
+R2:	flatring5 put S at 1 put N at 4 with .V5 at R1.V1
+	bond 20 from R2.V2 ; CH3
+	bond 90 from R2.V2 ; CH3
+	bond 90 from R2.V3 ; H
+	backbond 170 from R2.V3 ; COOH
--- /dev/null
+++ b/test/res.p
@@ -1,0 +1,26 @@
+.cstart
+	CH3O
+	bond 60
+R1:	benzene
+R2:	aromatic flatring5 pointing down put N at 1 with .V3 at R1.V2
+	H below R2.V1
+R3:	ring put N at 3 with .V5 at R2.V5
+R4:	ring put N at 1 with .V1 at R3.V3
+	back bond -120 from R4.V4 ; H
+	back bond 60 from R4.V3 ; H
+R5:	ring with .V1 at R4.V3
+	bond -120 ; C
+	doublebond down from C ; O
+	CH3O left of C
+	back bond 60 from R5.V3 ; H
+	back bond down from R5.V4 ; O
+	CH3 right of O
+	bond 120 from R5.V3 ; O
+	bond right lenght .1 from O ; C
+	double bond down ; O
+	bond right length .1 from C 
+B:	benzene pointing right
+	bond 30 from B ; OCH3
+	bond right from B ; OCH3
+	bond 150 from B ; OCH3
+.cend
--