Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_string2.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 fun test(s: String)
16 do
17 print s.length
18 print s.chars.first
19 print s.chars.last
20 print s.chars[2]
21 print s.substring(1, 2)
22 print s.substring(-1, 2)
23 print s.substring(1, 0)
24 print s.substring(2, 5)
25
26 print s.substring_from(1)
27 print s.substring_from(-1)
28 print s.substring_from(2)
29
30 print s.has_substring("bc",1)
31 print not s.has_substring("bc",2)
32
33 print s.has_prefix("ab")
34 print not s.has_prefix("bc")
35
36 print s.has_suffix("de")
37 print not s.has_suffix("cd")
38
39 print s.to_upper
40 print s.to_lower
41
42 print s == "abcde"
43 print s < "abcdf"
44 print s > "abcdd"
45 print s > "abcd"
46 print s < "abcdef"
47 print "z" + s + "z" == "zabcdez"
48 end
49
50 test("abcde")
51 test("ab"+"cde")
52 test("xabcdex".substring(1,5))