misc/jenkins: fix checklicense.sh
[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 #alt1 import splay_ropes
16 #alt2 import bufferized_ropes
17
18 var x :String = new RopeString
19
20 x = x + "NODE"
21 x = x + "AT"
22 x = x + "TEST"
23
24 print x
25
26 var lst = new List[String]
27
28 lst.push(new RopeString.from("ZZ"))
29
30 lst.push((lst.last * 5))
31
32 lst.push(lst.last.insert_at("AA", 2))
33
34 lst.push(lst.last.insert_at("NN", 0))
35
36 lst.push(lst.last.insert_at("II", 1))
37
38 lst.push(lst.last.insert_at(lst.last, 2))
39
40 var ss = lst.last.substring(4,4)
41
42 print ss
43
44 ss = ss.as(RopeString).insert_at("DD", 2)
45
46 print ss
47
48 ss = ss.insert_at("EE", 0)
49
50 print ss
51
52 ss = ss.insert_at("FF", ss.length)
53
54 print ss
55
56 ss = ss.to_lower
57
58 print ss
59
60 ss = ss.to_upper
61
62 print ss
63
64 ss = ss.reversed
65
66 print ss
67
68 var atb = new Array[String]
69
70 var s: String = new RopeString
71 s = s + "./examples/hello_world.nit".substring(11,11) + ".types"
72 s += "."
73 s += "1"
74 s += ".o"
75
76 print s
77
78 var str = new RopeString.from("now") + " step" + " live..."
79
80 print str
81
82 print str.reversed
83
84 for i in str.chars do printn i
85 printn "\n"
86
87 for i in [0..str.length[ do printn str.chars[i]
88 printn "\n"
89
90 var iter = str.chars.iterator
91 for i in [0..str.length[ do
92 assert str.chars[i] == iter.item
93 iter.next
94 end
95
96 assert "now step live...".hash == str.hash
97
98 for i in str.chars.iterator_from(8) do printn i
99 printn "\n"
100
101 for i in str.chars.iterator_from(str.length-1) do printn i
102 printn "\n"
103
104 for i in str.as(RopeString).reverse_substrings_from(12) do printn i
105 printn "\n"
106
107 for i in str.chars.reverse_iterator do printn i
108 printn "\n"
109
110 for i in str.chars.reverse_iterator_from(0) do printn i
111 printn "\n"
112
113 var str2 = str.as(RopeString).insert_at(str.substring_from(3), 3)
114
115 print str2
116
117 print str2.substring(2,3)
118
119 for i in lst do print i
120