Added JS files.
[nit.git] / tests / test_ropes.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 var x :String = new RopeString
16
17 x = x + "NODE"
18 x = x + "AT"
19 x = x + "TEST"
20
21 print x
22
23 var lst = new List[String]
24
25 lst.push(new RopeString.from("ZZ"))
26
27 lst.push((lst.last * 5))
28
29 lst.push(lst.last.insert_at("AA", 2))
30
31 lst.push(lst.last.insert_at("NN", 0))
32
33 lst.push(lst.last.insert_at("II", 1))
34
35 lst.push(lst.last.insert_at(lst.last, 2))
36
37 var ss = lst.last.substring(4,4)
38
39 print ss
40
41 ss = ss.as(RopeString).insert_at("DD", 2)
42
43 print ss
44
45 ss = ss.insert_at("EE", 0)
46
47 print ss
48
49 ss = ss.insert_at("FF", ss.length)
50
51 print ss
52
53 ss = ss.to_lower
54
55 print ss
56
57 ss = ss.to_upper
58
59 print ss
60
61 ss = ss.reversed
62
63 print ss
64
65 var atb = new Array[String]
66
67 var s = new RopeString
68 s = s.prepend(".types").as(RopeString)
69 s = s.prepend("./examples/hello_world.nit".substring(11,11)).as(RopeString)
70 s = s.append(".").as(RopeString)
71 s = s.append("1").as(RopeString)
72 s = s.append(".o").as(RopeString)
73
74 print s
75
76 var str = new RopeString.from("now") + " step" + " live..."
77
78 print str
79
80 print str.reversed
81
82 for i in str.chars do printn i
83 printn "\n"
84
85 for i in [0..str.length[ do printn str.chars[i]
86 printn "\n"
87
88 var iter = str.chars.iterator
89 for i in [0..str.length[ do
90 assert str.chars[i] == iter.item
91 iter.next
92 end
93
94 assert "now step live...".hash == str.hash
95
96 for i in str.chars.iterator_from(8) do printn i
97 printn "\n"
98
99 for i in str.chars.iterator_from(str.length-1) do printn i
100 printn "\n"
101
102 for i in str.as(RopeString).reverse_substrings_from(12) do printn i
103 printn "\n"
104
105 for i in str.chars.reverse_iterator do printn i
106 printn "\n"
107
108 for i in str.chars.reverse_iterator_from(0) do printn i
109 printn "\n"
110
111 var str2 = str.as(RopeString).insert_at(str.substring_from(3), 3)
112
113 print str2
114
115 print str2.substring(2,3)
116
117 for i in lst do print i
118