Rename REAMDE to README.md
[nit.git] / tests / test_ropes_buffer_to_s.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 # Checks the immutability of the strings returned by `RopeBuffer.to_s`.
16 module test_ropes_buffer_to_s
17
18 import standard
19
20 # Note: In this sort of test, never print the string more than once: the string
21 # itself may cache an flatten representation of itself when `print` calls `to_s`
22 # on it. For example, the original bug that motivated the writting of the
23 # present test got unoticed until we tried to edit the buffer **before**
24 # outputting `s`.
25
26 var buffer = new RopeBuffer
27 var s: String
28
29 sys.stdout.write "`clear` and `append`: "
30 buffer.append "abcd"
31 s = buffer.to_s
32 buffer.clear
33 buffer.append "ef"
34 print s
35
36 sys.stdout.write "`clear` and `add`: "
37 buffer.clear
38 buffer.add 'a'
39 buffer.add 'b'
40 s = buffer.to_s
41 buffer.clear
42 buffer.add 'c'
43 print s
44
45 sys.stdout.write "`add` at `maxlen + 1`: "
46 buffer.clear
47 buffer.add 'c'
48 s = buffer.to_s
49 buffer.append("*" * (maxlen -1))
50 buffer.add 'x'
51 print s
52
53 sys.stdout.write "`append` up to `maxlen + 1`: "
54 buffer.clear
55 buffer.append "ab"
56 s = buffer.to_s
57 buffer.append("*" * (maxlen -1))
58 print s
59
60 sys.stdout.write "`reverse`: "
61 buffer.clear
62 buffer.append "xyz"
63 s = buffer.to_s
64 buffer.reverse
65 print s
66
67 sys.stdout.write "`upper`: "
68 buffer.clear
69 buffer.append "foo"
70 s = buffer.to_s
71 buffer.upper
72 print s
73
74 sys.stdout.write "`lower`: "
75 buffer.clear
76 buffer.append "BAR"
77 s = buffer.to_s
78 buffer.lower
79 print s