Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Fix clear operation in ListBuffer #370

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class ListBuffer[A]

def clear(): Unit = {
first = Nil
len = 0
last0 = null
aliased = false
}

def addOne(elem: A): this.type = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package strawman.collection.mutable

import strawman.collection.immutable.Nil

import org.junit.{Assert, Test}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(classOf[JUnit4])
class ListBufferTest {

@Test
def hasCorrectClear(): Unit = {
val b = ListBuffer.empty[String]
b += "a"
Assert.assertTrue(b.sameElements("a" :: Nil))
b.clear()
Assert.assertEquals(ListBuffer.empty[String], b)
b += "b"
Assert.assertTrue(b.sameElements("b" :: Nil))

val b2 = ListBuffer.empty[String]
b2 += "a"
val _ = b2.toList
b2.clear()
b2 += "b"
Assert.assertTrue(b2.sameElements("b" :: Nil))
}

}