#
# $Id: atest,v 1.5 2000/08/04 21:28:14 malekith Exp $
#
# this shall print :
#
# XXXXXXX
# YYYYYYY
# ZZZZZZZ
# VVVVVVV
#

proc test1() {
	string s1 = "X", s2;
	s2 = "X" * 3;
	hash h;
	int n;
	
	h{1} = "X";
	h{2} = "Y";
	n = 3;
	h[n] = "Z";
	string con;
	
	while (n)
		con += h[n--];

	for (n = 2; n >= 0; n--)
		con[2-n] -= n;
	print (s1 + `$s2$con` + "\n");

	return "Z" * 3;
}

proc test2() {
	string s1, s2, s3;
	
	s1 = s2 = s3 = "Y";
	
	string r;
	(`$s1$s2$s3` != "XXX") || (s3 += "!");
	((r = s1 + s2 + s3) == "YYY") && (s3 += "Y");

	hash x;
	string t1, t2 = "";
	x["hello"] = "ziuta";
	x{world} = "franek";
	walk x {
		x[$key] = $key;
	}
	walk x {
		t1 += x[$key];
		t2 += $val;
	}
	if (t1 == t2)
		t1 = "Y";
	if (t2 @ /hello/ && t2 @ /world/)
		t2 = "Y";
	if (t2 @ /(\w)/ && $1 == "Y")
		t1 += t2;
	print (r + s3 + t1 + "\n");

	return "Z" * 3;
}

# arg passing test
proc test3(string a, int k)
{
	a[0] = a[k];
	a[1] = 0;
	return a;
}

# hash del
proc test4()
{
	int i;
	hash h;
	string r;
	
	for (i = 0; i < 10; i++)
		h[i] = "V";
		
	walk h {
		if (atoi($key) > 6)
			h[$key] = undef();
	}

	walk h {
		print($val);
	}

	print("\n");
}

# re
proc test5()
{
	string s;
	
	s = "THE red FOX";
	
	if (s @ /fox/i)
		print("O");

	if (s @ /fox/ == 0)
		print("O");
	
	if (s @ /(blarb|F)(O)[xyzXYZ]/)
		print($2);
	
	if (!(s @ /(hey)(ho)/) && $1 == "")
		print("O");

	if ("hshshssh 31337 dhgfsdjhf" @ /(\d+)/ && atoi($1) == 31337)
		print("O");
		
	print("OO\n");
}

print(test1() + test2() + test3("1234Z37373", 4) + "\n");
test4();
test5();
