summaryrefslogtreecommitdiff
path: root/tests/general/string.icn
blob: 960befc1a898f32299039e5a79f8ba98c0dfeac2 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
record array(a,b,c,d,e,f,g)

procedure p1()
   write(" ----> ",image() | "none")
   write("s := \"abcd\" ----> ",image(s := "abcd") | "none")
   write("s := \"x\" ----> ",image(s := "x") | "none")
   write("s ||:= \"x\" ----> ",image(s ||:= "x") | "none")
   write("s ----> ",image(s) | "none")
   write("s := \"x\" ----> ",image(s := "x") | "none")
   write("s ||:= \"xx\" ----> ",image(s ||:= "xx") | "none")
   write("s ----> ",image(s) | "none")
   write("s := \"x\" ----> ",image(s := "x") | "none")
   write("s ||:= \"X\" ----> ",image(s ||:= "X") | "none")
   write("s ----> ",image(s) | "none")
end

procedure p2()
   write("s := \"x\" ----> ",image(s := "x") | "none")
   write("s ||:= \"abc\" ----> ",image(s ||:= "abc") | "none")
   write("s ----> ",image(s) | "none")
   write("s := \"x\" ----> ",image(s := "x") | "none")
   write("s ==:= \"x\" ----> ",image(s ==:= "x") | "none")
   write("s ----> ",image(s) | "none")
   write("s := \"x\" ----> ",image(s := "x") | "none")
   write("s ==:= \"xx\" ----> ",image(s ==:= "xx") | "none")
   write("s ----> ",image(s) | "none")
   write("s := \"x\" ----> ",image(s := "x") | "none")
   write("s ==:= \"X\" ----> ",image(s ==:= "X") | "none")
end

procedure p3()
   write("s ----> ",image(s) | "none")
   write("s := \"x\" ----> ",image(s := "x") | "none")
   write("s ==:= \"abc\" ----> ",image(s ==:= "abc") | "none")
   write("s ----> ",image(s) | "none")
   write("{s[1:2] := \"xx\";s} ----> ",image({s[1:2] := "xx";s}) | "none")
   write("{s[-1:0] := \"\";s} ----> ",image({s[-1:0] := "";s}) | "none")
   write("{s[1] := \"abc\";s} ----> ",image({s[1] := "abc";s}) | "none")
   write("{s[1+:2] := \"y\";s} ----> ",image({s[1+:2] := "y";s}) | "none")
   write("{s[2] :=: s[3];s} ----> ",image({s[2] :=: s[3];s}) | "none")
   write("s[6] := \"t\" ----> ",image(s[6] := "t") | "none")
   write("s[0-:6] := \"u\" ----> ",image(s[0-:6] := "u") | "none")
end

procedure p4()
   write("{s[1:0] :=: s[0:1];s} ----> ",image({s[1:0] :=: s[0:1];s}) | "none")
   write("\"x\" << \"x\" ----> ",image("x" << "x") | "none")
   write("\"x\" << \"X\" ----> ",image("x" << "X") | "none")
   write("\"X\" << \"x\" ----> ",image("X" << "x") | "none")
   write("\"xx\" <<= \"xx\" ----> ",image("xx" <<= "xx") | "none")
   write("\"xxx\" <<= \"xx\" ----> ",image("xxx" <<= "xx") | "none")
   write("\"xx\" <<= \"xxx\" ----> ",image("xx" <<= "xxx") | "none")
   write("\"x\" >>= \"x\" ----> ",image("x" >>= "x") | "none")
   write("\"x\" >>= \"xx\" ----> ",image("x" >>= "xx") | "none")
   write("\"xx\" >>= \"x\" ----> ",image("xx" >>= "x") | "none")
   write("\"x\" >> \"x\" ----> ",image("x" >> "x") | "none")
end

procedure p5()
   write("\"x\" >> \"X\" ----> ",image("x" >> "X") | "none")
   write("\"X\" >> \"x\" ----> ",image("X" >> "x") | "none")
   write("\"x\" == \"x\" ----> ",image("x" == "x") | "none")
   write("\"x\" == \"X\" ----> ",image("x" == "X") | "none")
   write("\"X\" == \"x\" ----> ",image("X" == "x") | "none")
   write("\"x\" ~== \"x\" ----> ",image("x" ~== "x") | "none")
   write("\"x\" ~== \"X\" ----> ",image("x" ~== "X") | "none")
   write("\"X\" ~== \"x\" ----> ",image("X" ~== "x") | "none")
   write("every i := 1 to 9 do write(integer(repl(\"2\",i))) ----> ",image(every i := 1 to 9 do write(integer(repl("2",i)))) | "none")
   write("every i := 1 to 9 do write(repl(\"2\",i) + 1) ----> ",image(every i := 1 to 9 do write(repl("2",i) + 1)) | "none")
end

procedure p6()
   write("every i := 1 to 30 do write(integer(repl(\"0\",i) || \"2\")) ----> ",image(every i := 1 to 30 do write(integer(repl("0",i) || "2"))) | "none")
   write("every i := 1 to 30 do write((repl(\"0\",i) || \"2\") + 1) ----> ",image(every i := 1 to 30 do write((repl("0",i) || "2") + 1)) | "none")
   write("c1 := 'abcde' ----> ",image(c1 := 'abcde') | "none")
   write("c2 := 'aeuoi' ----> ",image(c2 := 'aeuoi') | "none")
   write("c1 ++ c2 ----> ",image(c1 ++ c2) | "none")
   write("c1 -- c2 ----> ",image(c1 -- c2) | "none")
   write("c1 ** c2 ----> ",image(c1 ** c2) | "none")
   write("2 ~=== +2 ----> ",image(2 ~=== +2) | "none")
   write("3 ~=== *\"abc\" ----> ",image(3 ~=== *"abc") | "none")
end

procedure p7()
   write("'abc' ~=== ('abc' ++ '') ----> ",image('abc' ~=== ('abc' ++ '')) | "none")
   write("any('aeiou',&lcase) ----> ",image(any('aeiou',&lcase)) | "none")
   write("any('aeiou',&ucase) ----> ",image(any('aeiou',&ucase)) | "none")
   write("every write(any('aeiou',&lcase,1 to 5,10 to 20)) ----> ",image(every write(any('aeiou',&lcase,1 to 5,10 to 20))) | "none")
   write("match(\"abc\",\"abcabcabcabc\") ----> ",image(match("abc","abcabcabcabc")) | "none")
   write("match(\"abc\",\"xabcabcabcabc\") ----> ",image(match("abc","xabcabcabcabc")) | "none")
   write("every write(match(\"abc\",\"xabcabcabcabc\",1 to 10,1 to 10)) ----> ",image(every write(match("abc","xabcabcabcabc",1 to 10,1 to 10))) | "none")
   write("upto('56d&',&lcase) ----> ",image(upto('56d&',&lcase)) | "none")
   write("upto('56d&',&ucase) ----> ",image(upto('56d&',&ucase)) | "none")
   write("upto('56d&',&lcase,15) ----> ",image(upto('56d&',&lcase,15)) | "none")
   write("many(&lcase,\"this is a Test\") ----> ",image(many(&lcase,"this is a Test")) | "none")
end

procedure p8()
   write("many(&lcase,\"this is a Test\",5) ----> ",image(many(&lcase,"this is a Test",5)) | "none")
   write("many(&lcase,\"this is a Test\",5,9) ----> ",image(many(&lcase,"this is a Test",5,9)) | "none")
   write("find(\"aa\",\"xxaaaaaa\") ----> ",image(find("aa","xxaaaaaa")) | "none")
   write("every write(find(\"aa\",\"xxaaaaaa\")) ----> ",image(every write(find("aa","xxaaaaaa"))) | "none")
   write("every write(find(\"aa\",\"xxaaaaaa\",4,7)) ----> ",image(every write(find("aa","xxaaaaaa",4,7))) | "none")
   write("bal('-','(',')',\"-35\") ----> ",image(bal('-','(',')',"-35")) | "none")
   write("bal('+','(',')',\"((2*x)+3)+(5*y)\") ----> ",image(bal('+','(',')',"((2*x)+3)+(5*y)")) | "none")
   write("every write(bal('+','(',')',\"((2*x)+3)+(5*y)\",1 to 10)) ----> ",image(every write(bal('+','(',')',"((2*x)+3)+(5*y)",1 to 10))) | "none")
   write("bal('+','[','[',\"[[2*x[+3[+[5*y[\") ----> ",image(bal('+','[','[',"[[2*x[+3[+[5*y[")) | "none")
   write("bal('+','([','])',\"([2*x)+3]+(5*y]\") ----> ",image(bal('+','([','])',"([2*x)+3]+(5*y]")) | "none")
   write("bal(,,,\"()+()\") ----> ",image(bal(,,,"()+()")) | "none")
end

procedure p9()
   write("bal(&cset,,,\"()+()\") ----> ",image(bal(&cset,,,"()+()")) | "none")
end

procedure main()
   p1()
   p2()
   p3()
   p4()
   p5()
   p6()
   p7()
   p8()
   p9()
end

global s