lib/standard/ropes: Added test for Ropes.
authorLucas Bajolet <r4pass@hotmail.com>
Thu, 5 Jun 2014 15:25:02 +0000 (11:25 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 9 Jun 2014 15:58:51 +0000 (11:58 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

tests/sav/test_ropes.res [new file with mode: 0644]
tests/test_ropes.nit [new file with mode: 0644]

diff --git a/tests/sav/test_ropes.res b/tests/sav/test_ropes.res
new file mode 100644 (file)
index 0000000..7e4b7c1
--- /dev/null
@@ -0,0 +1,26 @@
+NODEATTEST
+INZZ
+INDDZZ
+EEINDDZZ
+EEINDDZZFF
+eeinddzzff
+EEINDDZZFF
+FFZZDDNIEE
+hello_world.types.1.o
+now step live...
+...evil pets won
+now step live...
+now step live...
+ live...
+.
+ live stepnow
+...evil pets won
+n
+now step live... step live...
+w s
+ZZ
+ZZZZZZZZZZ
+ZZAAZZZZZZZZ
+NNZZAAZZZZZZZZ
+NIINZZAAZZZZZZZZ
+NINIINZZAAZZZZZZZZINZZAAZZZZZZZZ
diff --git a/tests/test_ropes.nit b/tests/test_ropes.nit
new file mode 100644 (file)
index 0000000..3040d12
--- /dev/null
@@ -0,0 +1,118 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# 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.
+
+var x :String = new RopeString
+
+x = x + "NODE"
+x = x + "AT"
+x = x + "TEST"
+
+print x
+
+var lst = new List[String]
+
+lst.push(new RopeString.from("ZZ"))
+
+lst.push((lst.last * 5))
+
+lst.push(lst.last.insert_at("AA", 2))
+
+lst.push(lst.last.insert_at("NN", 0))
+
+lst.push(lst.last.insert_at("II", 1))
+
+lst.push(lst.last.insert_at(lst.last, 2))
+
+var ss = lst.last.substring(4,4)
+
+print ss
+
+ss = ss.as(RopeString).insert_at("DD", 2)
+
+print ss
+
+ss = ss.insert_at("EE", 0)
+
+print ss
+
+ss = ss.insert_at("FF", ss.length)
+
+print ss
+
+ss = ss.to_lower
+
+print ss
+
+ss = ss.to_upper
+
+print ss
+
+ss = ss.reversed
+
+print ss
+
+var atb = new Array[String]
+
+var s = new RopeString
+s = s.prepend(".types").as(RopeString)
+s = s.prepend("./examples/hello_world.nit".substring(11,11)).as(RopeString)
+s = s.append(".").as(RopeString)
+s = s.append("1").as(RopeString)
+s = s.append(".o").as(RopeString)
+
+print s
+
+var str = new RopeString.from("now") + " step" + " live..."
+
+print str
+
+print str.reversed
+
+for i in str.chars do printn i
+printn "\n"
+
+for i in [0..str.length[ do printn str.chars[i]
+printn "\n"
+
+var iter = str.chars.iterator
+for i in [0..str.length[ do
+       assert str.chars[i] == iter.item
+       iter.next
+end
+
+assert "now step live...".hash == str.hash
+
+for i in str.chars.iterator_from(8) do printn i
+printn "\n"
+
+for i in str.chars.iterator_from(str.length-1) do printn i
+printn "\n"
+
+for i in str.as(RopeString).reverse_substrings_from(12) do printn i
+printn "\n"
+
+for i in str.chars.reverse_iterator do printn i
+printn "\n"
+
+for i in str.chars.reverse_iterator_from(0) do printn i
+printn "\n"
+
+var str2 = str.as(RopeString).insert_at(str.substring_from(3), 3)
+
+print str2
+
+print str2.substring(2,3)
+
+for i in lst do print i
+