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