72 lines · 2.0 KB · Text
RawDownload
#!/bin/rcecho T.builtin: test miscellaneous builtin functions >[1=2] $awk 'BEGIN { print index(123, substr(123, 2)) }' >foo1echo 2 >foo2diff foo1 foo2 || echo 'BAD: T.builtin: index/substr' >[1=2] $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)))}' >foo1echo '3.14159 0.000 0.000 3.14159 10.000' >foo2diff foo1 foo2 || echo 'BAD: T.builtin: sin/cos' >[1=2] $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' >[1=2] echo 'hello, WORLD!' |$awk '{ printf("%s|%s|%s\n", tolower($0), toupper($0), $0)}' >foo1echo 'hello, world!|HELLO, WORLD!|hello, WORLD!' >foo2diff foo1 foo2 || echo 'BAD: T.builtin: toupper/tolower' >[1=2] echo 'Dürst' |$awk '{ printf("%s|%s|%s\n", tolower($0), toupper($0), $0)}' >foo1echo 'dürst|DÜRST|Dürst' >foo2diff foo1 foo2 || echo 'BAD: T.builtin: toupper/tolower for utf-8' >[1=2] $awk 'BEGIN { print 0.01 }' /dev/null >foo1echo '0.01' >foo2diff foo1 foo2 || echo 'BAD: T.builtin: LC_NUMERIC radix (.) handling' >[1=2] $awk 'BEGIN {	j = 1; sprintf("%d", 99, ++j)	# does j get incremented?	if (j != 2)		print "BAD: T.builtin: printf arg list not evaluated"}' >[1=2] $awk 'BEGIN {	j = 1; substr("", 1, ++j)	# does j get incremented?	if (j != 2)		print "BAD: T.builtin: substr arg list not evaluated"}' >[1=2] $awk 'BEGIN {	j = 1; sub(/1/, ++j, z)	# does j get incremented?	if (j != 2)		print "BAD: T.builtin: sub() arg list not evaluated"}' >[1=2] $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]foogrep 'too many arg' foo >/dev/null || echo 'BAD: T.builtin: too many args not caught' >[1=2] echo 'aa ba b c' >foo0echo '123' >foo1$awk '{ n = split($0, x); print length(x) }' <foo0 >foo2diff foo1 foo2 || echo 'BAD: T.builtin: length array' >[1=2]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t