1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 #alt3 import bufferized_ropes
17 var str
= "Woe to you, oh earth and sea for the Devil sends the beast with wrath because he knows the time is short. Let him who hath understanding reckon the number of the beast, for it is a human number, its number is Six Hundred and Sixty-Six."
26 trimable
= spaces
+ str
+ spaces
29 #alt1 txt = new FlatBuffer.from(str)
30 #alt1 trimable = new FlatBuffer.from(spaces)
31 #alt1 trimable.append(str)
32 #alt1 trimable.append(spaces)
33 #alt1 num = new FlatBuffer.from(numstr)
35 #alt2 txt = new RopeString.from(str)
36 #alt2 trimable = new RopeString.from(spaces)
37 #alt2 trimable = trimable + str
38 #alt2 trimable = trimable + spaces
39 #alt2 num = new RopeString.from(numstr)
41 #alt3 txt = new RopeString.from(str)
42 #alt3 trimable = new RopeString.from(spaces)
43 #alt3 trimable = trimable + str
44 #alt3 trimable = trimable + spaces
45 #alt3 num = new RopeString.from(numstr)
47 # Test Text methods on all types of receivers
49 print txt
.substring
(0, 105)
50 print txt
.substring_from
(106)
52 assert not txt
.is_empty
53 print txt
.index_of
('h')
54 print txt
.index_of_from
('h', 105)
55 print txt
.index_of
('Z')
56 print txt
.last_index_of
('L')
57 print txt
.last_index_of_from
('D', 105)
58 print txt
.has_substring
("Woe", 0)
59 print txt
.has_substring
("Let", 106)
60 assert trimable
!= txt
61 assert trimable
.trim
== txt
63 assert txt
.has_prefix
("Woe")
64 assert txt
.has_suffix
("Six.")
65 assert txt
.hash
== trimable
.trim
.hash
67 # Test Text.chars (SequenceRead[Char]) methods on all receivers
71 assert chars
!= txt
.substring_from
(106).chars
72 assert chars
[0] == 'W'
73 assert chars
.count
('o') == 11
74 assert chars
.first
== chars
[0]
76 assert spaces
.chars
.has_only
(' ')
77 assert chars
.index_of
('D') == 37
78 assert not chars
.is_empty
86 assert count
== txt
.length
87 var iter_from
= txt
.substring_from
(105).chars
.iterator
88 var txt_iter_from
= chars
.iterator_from
(105)
89 while iter_from
.is_ok
do
90 assert iter_from
.item
== txt_iter_from
.item
94 assert not iter_from
.is_ok
and not txt_iter_from
.is_ok
95 var txt_reviter
= chars
.reverse_iterator_from
(104)
96 var sub_reviter
= txt
.substring
(0,105).chars
.reverse_iterator
97 while txt_reviter
.is_ok
do
98 assert txt_reviter
.item
== sub_reviter
.item
102 print chars
.join
(" ")