File: demo_multisub

package info (click to toggle)
runawk 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 712 kB
  • sloc: awk: 1,127; ansic: 736; sh: 420; makefile: 103
file content (40 lines) | stat: -rwxr-xr-x 1,285 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env runawk

#use "multisub.awk"
#use "alt_assert.awk"

function test (ideal, input, repls, num, keep,
       res)
{
#	print "ideal=" ideal > "/dev/stderr"
	res = multisub(input, repls, keep)
#	print "res=" res > "/dev/stderr"
	if (ideal != res){
		msg = ("test " num " failed")
		msg = msg "\n ideal=\"" ideal "\""
		msg = msg "\n res  =\"" res "\""
		abort(msg)
	}
#	print "test " num " succeeded"
}

BEGIN {
	test("osb", "[", "[:osb", -1)
	test("csb", "]", "]:csb", -2)
	test("", "", "", 1)
	test("aaa", "aaa", "", 2)
	test("aaa", "aaa", "b:c", 3)
	test("dc", "bbb", "b:c   bb:d", 4)
	test("e", "bbb", "b:c   bbb:e   bb:d", 5)
	test("Bd", "BBBA", "ABB:c   BBA:d", 6)
	test("ccBBde", "ABBABBBBBBAAB", "ABB:c   BBA:d   AB:e", 7)
	test("kABBA(acca)BC(saab)", "kabba(acca)bc(saab)", "a:A   b:B   c:C   [(][^()]*[)]:&", 7, "&")

	if (!__buggy_mawk)
		test("aaa\nbbb\nccc\tddd\aeee\a", "aaa\\nbbb\\nccc\\tddd\\aeee\\a", "\\t:\t   \\a:\a   \\n:\n", 7)

	test("question_question_osb_osb_csb_csb_ocb_ocb_ccb_ccb_or_or_orb_orb_crb_crb_star_star_plus_plus_dot_power_power_dollar_backslash_",
		"??[[]]{{}}||(())**++.^^$\\", "$:dollar_   ^:power_   .:dot_   +:plus_   *:star_   ):crb_   (:orb_   |:or_   }:ccb_   {:ocb_   [:osb_   ]:csb_   ?:question_   \\:backslash_", 8)

	exit 0
}