ropes: Reset everything when clearing.
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Thu, 4 Dec 2014 18:53:01 +0000 (13:53 -0500)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Thu, 4 Dec 2014 18:53:01 +0000 (13:53 -0500)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

lib/standard/ropes.nit
tests/sav/test_ropes_buffer_clear.res [new file with mode: 0644]
tests/test_ropes_buffer_clear.nit [new file with mode: 0644]

index 12ad67e..db635d9 100644 (file)
@@ -240,6 +240,7 @@ class RopeBuffer
                str = ""
                length = 0
                rpos = 0
+               dumped = 0
        end
 
        redef fun substring(from, count) do
diff --git a/tests/sav/test_ropes_buffer_clear.res b/tests/sav/test_ropes_buffer_clear.res
new file mode 100644 (file)
index 0000000..951dbb9
--- /dev/null
@@ -0,0 +1,2 @@
+23
+3
diff --git a/tests/test_ropes_buffer_clear.nit b/tests/test_ropes_buffer_clear.nit
new file mode 100644 (file)
index 0000000..eba364e
--- /dev/null
@@ -0,0 +1,37 @@
+# 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.
+
+# Checks if `RopeBuffer.clear` actually reset everything.
+module test_ropes_buffer_clear
+
+import standard
+
+var buffer = new RopeBuffer
+
+buffer.append "1"
+# Force to flush the internal buffer, so that all the internal positions will be
+# set to a non-zero value.
+buffer.append("?" * (maxlen + 1))
+buffer.clear
+buffer.append "23"
+print buffer
+
+buffer = new RopeBuffer
+buffer.append "12"
+# Force to flush the internal buffer, so that all the internal positions will be
+# set to a non-zero value.
+buffer.append("?" * (maxlen + 1))
+buffer.clear
+buffer.append "3"
+print buffer