1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it if you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or as a part of
15 var str_part_2
= "suis"
17 var str_part_3
= "ici"
23 var test
= "Je suis ici."
25 var rope_uniq_test
= new ImmutableRope.with_string
("zzzzzzzzzzzzzzzzzzzzzzzzzzzz")
27 var not_rope_uniq_test
= new ImmutableRope.with_string
("zzzzzzzzzzzzzezzzzzzzzzzzzzz")
29 ################################
30 # Rope methods tests #
31 ################################
35 buf
.append
(str_part_1
)
37 buf
.append
(str_part_2
)
39 buf
.append
(str_part_3
)
40 buf
.append
(str_part_4
)
44 var buf_rope
= new BufferRope
46 buf_rope
.append_multi
(str_part_1
,space
,str_part_2
,space
,str_part_3
,str_part_4
)
48 var buf_rope_with_str
= new BufferRope.with_string
(test
)
52 print buf_rope_with_str
*5
54 print buf_rope
+ buf_rope_with_str
56 assert buf_rope
.length
== buf_rope_with_str
.length
58 assert buf_rope
== buf_rope_with_str
60 assert buf_rope
.multi_concat
(buf_rope
, buf_rope
) == buf_rope
* 3
62 print buf_rope
.subrope
(0, 5)
64 assert buf_rope
.subrope
(0, 5) == "Je su"
66 buf_rope
.append
("Hi !")
68 assert buf_rope
> buf_rope_with_str
70 assert buf_rope
== buf_rope
.chars
.to_s
72 assert buf_rope
.chars
.to_s
== buf_rope
74 assert buf
== buf_rope_with_str
76 ######################################
77 # BufferRope methods tests #
78 ######################################
80 assert buf_rope
+ buf_rope
== buf_rope
.concat
(buf_rope
)
82 assert buf_rope
== buf_rope
.freeze
84 ######################################
85 # Rope.chars methods tests #
86 ######################################
88 assert buf_rope
.chars
[3] == 's'
90 assert buf_rope
.chars
.index_of
('k') == -1
92 assert buf_rope
.chars
.index_of
('s') == 3
94 assert buf_rope
.chars
.count
('s') == 4
96 assert buf_rope
.chars
.last
== '!'
98 assert rope_uniq_test
.chars
.has_only
('z')
100 assert not not_rope_uniq_test
.chars
.has_only
('z')
102 assert (new BufferRope).chars
.has_only
('l')
104 print buf_rope
.to_lower
106 print buf_rope
.to_upper