X-Git-Url: http://nitlanguage.org diff --git a/tests/test_ropes.nit b/tests/test_ropes.nit index 86a0cd7..7ea9920 100644 --- a/tests/test_ropes.nit +++ b/tests/test_ropes.nit @@ -1,108 +1,117 @@ # This file is part of NIT ( http://www.nitlanguage.org ). # -# This file is free software, which comes along with NIT. This software is -# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. You can modify it if you want, provided this header -# is kept unaltered, and a notification of the changes is added. -# You are allowed to redistribute it and sell it, alone or as a part of -# another product. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -module test_ropes +import core +intrude import core::text::ropes -var str_part_1 = "Je" +# Force building a Rope +redef fun maxlen: Int do return once 2 -var str_part_2 = "suis" +var x :String = new Concat("NODE", "AT") -var str_part_3 = "ici" +x += "TEST" -var str_part_4 = "." +print x -var space = " " +var lst = new List[String] -var test = "Je suis ici." +lst.push("ZZ") -var rope_uniq_test = new ImmutableRope.with_string("zzzzzzzzzzzzzzzzzzzzzzzzzzzz") +lst.push((lst.last * 5)) -var not_rope_uniq_test = new ImmutableRope.with_string("zzzzzzzzzzzzzezzzzzzzzzzzzzz") +lst.push(lst.last.insert_at("AA", 2)) -################################ -# Rope methods tests # -################################ +lst.push(lst.last.insert_at("NN", 0)) -var buf = new Buffer +lst.push(lst.last.insert_at("II", 1)) -buf.append(str_part_1) -buf.append(space) -buf.append(str_part_2) -buf.append(space) -buf.append(str_part_3) -buf.append(str_part_4) +lst.push(lst.last.insert_at(lst.last, 2)) -print buf +var ss = lst.last.substring(4,4) -var buf_rope = new BufferRope +print ss -buf_rope.append_multi(str_part_1,space,str_part_2,space,str_part_3,str_part_4) +ss = ss.insert_at("DD", 2) -var buf_rope_with_str = new BufferRope.with_string(test) +print ss -print buf_rope*3 +ss = ss.insert_at("EE", 0) -print buf_rope_with_str*5 +print ss -print buf_rope + buf_rope_with_str +ss = ss.insert_at("FF", ss.length) -assert buf_rope.length == buf_rope_with_str.length +print ss -assert buf_rope == buf_rope_with_str +ss = ss.to_lower -assert buf_rope.multi_concat(buf_rope, buf_rope) == buf_rope * 3 +print ss -print buf_rope.subrope(0, 5) +ss = ss.to_upper -assert buf_rope.subrope(0, 5) == "Je su" +print ss -buf_rope.append("Hi !") +ss = ss.reversed -assert buf_rope > buf_rope_with_str +print ss -assert buf_rope == buf_rope.chars.to_s +var atb = new Array[String] -assert buf_rope.chars.to_s == buf_rope +var s: String = "./examples/hello_world.nit".substring(11,11) + ".types" +s += "." +s += "1" +s += ".o" -assert buf == buf_rope_with_str +print s -###################################### -# BufferRope methods tests # -###################################### +var str = "now" + " step" + " live..." -assert buf_rope + buf_rope == buf_rope.concat(buf_rope) +print str -assert buf_rope == buf_rope.freeze +print str.reversed -###################################### -# Rope.chars methods tests # -###################################### +for i in str.chars do printn i +printn "\n" -assert buf_rope.chars[3] == 's' +for i in [0..str.length[ do printn str.chars[i] +printn "\n" -assert buf_rope.chars.index_of('k') == -1 +var iter = str.chars.iterator +for i in [0..str.length[ do + assert str.chars[i] == iter.item + iter.next +end -assert buf_rope.chars.index_of('s') == 3 +assert "now step live...".hash == str.hash -assert buf_rope.chars.count('s') == 4 +for i in str.chars.iterator_from(8) do printn i +printn "\n" -assert buf_rope.chars.last == '!' +for i in str.chars.iterator_from(str.length-1) do printn i +printn "\n" -assert rope_uniq_test.chars.has_only('z') +for i in str.chars.reverse_iterator do printn i +printn "\n" -assert not not_rope_uniq_test.chars.has_only('z') +for i in str.chars.reverse_iterator_from(0) do printn i +printn "\n" -assert (new BufferRope).chars.has_only('l') +var str2 = str.insert_at(str.substring_from(3), 3) -print buf_rope.to_lower +print str2 -print buf_rope.to_upper +print str2.substring(2,3) +for i in lst do print i