<commit_before>package org.jetbrains.plugins.scala
package debugger
package renderers

import com.intellij.debugger.settings.NodeRendererSettings
import com.intellij.debugger.ui.tree.render._
import org.jetbrains.plugins.scala.debugger.ui.ScalaCollectionRenderer
import org.junit.experimental.categories.Category

import scala.concurrent.duration.{Duration, DurationInt}

/**
 * User: <NAME>
 * Date: 9/5/12
 */
@Category(Array(classOf[DebuggerTests]))
class ScalaCollectionRendererTest_until_2_11 extends ScalaCollectionRendererTestBase {
  override protected def supportedIn(version: ScalaVersion): Boolean = version  <= LatestScalaVersions.Scala_2_11
}
@Category(Array(classOf[DebuggerTests]))
class ScalaCollectionRendererTest_since_2_12 extends ScalaCollectionRendererTestBase {
  override protected def supportedIn(version: ScalaVersion): Boolean = version  >= LatestScalaVersions.Scala_2_12

  addFileWithBreakpoints("Lazy.scala",
    s"""
       |object Lazy {
       |  def main(args: Array[String]) {
       |    val stream = Stream.from(42)
       |    val a = 1$bp
       |  }
       |}
      """.replace("\r", "").stripMargin.trim
  )

  def testLazy(): Unit = {
    testLazyCollectionRendering("stream", "scala.collection.immutable.Stream$Cons", "Stream(42, ?)")
  }
}
@Category(Array(classOf[DebuggerTests]))
class ScalaCollectionRendererTest_since_2_13 extends ScalaCollectionRendererTestBase {
  override protected def supportedIn(version: ScalaVersion): Boolean = version  >= LatestScalaVersions.Scala_2_13

  addFileWithBreakpoints("Lazy.scala",
    s"""
       |object Lazy {
       |  def main(args: Array[String]) {
       |    val list = LazyList.from(1)
       |    val stream = Stream.from(1)
       |    val a = 1$bp
       |    val b = 2$bp
       |  }
       |}
      """.replace("\r", "").stripMargin.trim
  )
  def testLazy(): Unit = {
    testLazyCollectionRendering("list", "scala.collection.immutable.LazyList", "LazyList(<not computed>)")(10.seconds)
    testLazyCollectionRendering("stream", "scala.collection.immutable.Stream$Cons", "Stream(1, <not computed>)")(10.seconds)
  }
}

abstract class ScalaCollectionRendererTestBase extends RendererTestBase {
  private val UNIQUE_ID = "uniqueID"

  protected def testCollectionRenderer(collectionName: String,
                                       collectionClass: String,
                                       afterTypeLabel: String,
                                       collectionLength: Int,
                                       checkChildren: Boolean)
                                      (implicit timeout: Duration = DefaultTimeout): Unit = {
    import org.junit.Assert._
    runDebugger() {
      waitForBreakpoint()
      val (label, children) = renderLabelAndChildren(collectionName, _.getLabel, checkChildren, collectionLength)(timeout)
      val classRenderer: ClassRenderer = NodeRendererSettings.getInstance().getClassRenderer
      val typeName = classRenderer.renderTypeName(collectionClass)
      val expectedLabel = s"$collectionName = {$typeName@$UNIQUE_ID}$afterTypeLabel"

      assertEquals("node label value doesn't match", expectedLabel, label)

      if (checkChildren) {
        val intType = classRenderer.renderTypeName("java.lang.Integer")
        val intLabel = s"{$intType@$UNIQUE_ID}"
        var testIndex = 0
        children.foreach { childLabel =>
          val expectedChildLabel = s"$testIndex = $intLabel${testIndex + 1}"

          try
            assertEquals(expectedChildLabel, childLabel)
          catch {
            case err: AssertionError =>
              val childrenDebugText = childLabel.zipWithIndex
                .map { case (child, idx) => s"$idx: $child"}
                .mkString("\n")
              System.err.println(s"all children nodes labels:\n$childrenDebugText")
              throw err
          }
          testIndex += 1
        }
      }
    }
  }

  protected def testCollectionRenderer(collectionName: String,
                                       collectionClass: String,
                                       afterTypeLabel: String,
                                       expectedChildrenLabels: Seq[String])
                                      (implicit timeout: Duration): Unit = {

    import org.junit.Assert._
    runDebugger() {
      waitForBreakpoint()
      val (label, childrenLabels) =
        renderLabelAndChildren(collectionName, _.getLabel, renderChildren = expectedChildrenLabels.nonEmpty, expectedChildrenLabels.size)

      val classRenderer: ClassRenderer = NodeRendererSettings.getInstance().getClassRenderer
      val typeName = classRenderer.renderTypeName(collectionClass)
      val expectedLabel = s"$collectionName = {$typeName@$UNIQUE_ID}$afterTypeLabel"<commit_msg>fix ScalaCollectionRendererTestBase debug info text<commit_after>package org.jetbrains.plugins.scala
package debugger
package renderers

import com.intellij.debugger.settings.NodeRendererSettings
import com.intellij.debugger.ui.tree.render._
import org.jetbrains.plugins.scala.debugger.ui.ScalaCollectionRenderer
import org.junit.experimental.categories.Category

import scala.concurrent.duration.{Duration, DurationInt}

/**
 * User: <NAME>
 * Date: 9/5/12
 */
@Category(Array(classOf[DebuggerTests]))
class ScalaCollectionRendererTest_until_2_11 extends ScalaCollectionRendererTestBase {
  override protected def supportedIn(version: ScalaVersion): Boolean = version  <= LatestScalaVersions.Scala_2_11
}
@Category(Array(classOf[DebuggerTests]))
class ScalaCollectionRendererTest_since_2_12 extends ScalaCollectionRendererTestBase {
  override protected def supportedIn(version: ScalaVersion): Boolean = version  >= LatestScalaVersions.Scala_2_12

  addFileWithBreakpoints("Lazy.scala",
    s"""
       |object Lazy {
       |  def main(args: Array[String]) {
       |    val stream = Stream.from(42)
       |    val a = 1$bp
       |  }
       |}
      """.replace("\r", "").stripMargin.trim
  )

  def testLazy(): Unit = {
    testLazyCollectionRendering("stream", "scala.collection.immutable.Stream$Cons", "Stream(42, ?)")
  }
}
@Category(Array(classOf[DebuggerTests]))
class ScalaCollectionRendererTest_since_2_13 extends ScalaCollectionRendererTestBase {
  override protected def supportedIn(version: ScalaVersion): Boolean = version  >= LatestScalaVersions.Scala_2_13

  addFileWithBreakpoints("Lazy.scala",
    s"""
       |object Lazy {
       |  def main(args: Array[String]) {
       |    val list = LazyList.from(1)
       |    val stream = Stream.from(1)
       |    val a = 1$bp
       |    val b = 2$bp
       |  }
       |}
      """.replace("\r", "").stripMargin.trim
  )
  def testLazy(): Unit = {
    testLazyCollectionRendering("list", "scala.collection.immutable.LazyList", "LazyList(<not computed>)")(10.seconds)
    testLazyCollectionRendering("stream", "scala.collection.immutable.Stream$Cons", "Stream(1, <not computed>)")(10.seconds)
  }
}

abstract class ScalaCollectionRendererTestBase extends RendererTestBase {
  private val UNIQUE_ID = "uniqueID"

  protected def testCollectionRenderer(collectionName: String,
                                       collectionClass: String,
                                       afterTypeLabel: String,
                                       collectionLength: Int,
                                       checkChildren: Boolean)
                                      (implicit timeout: Duration = DefaultTimeout): Unit = {
    import org.junit.Assert._
    runDebugger() {
      waitForBreakpoint()
      val (label, children) = renderLabelAndChildren(collectionName, _.getLabel, checkChildren, collectionLength)(timeout)
      val classRenderer: ClassRenderer = NodeRendererSettings.getInstance().getClassRenderer
      val typeName = classRenderer.renderTypeName(collectionClass)
      val expectedLabel = s"$collectionName = {$typeName@$UNIQUE_ID}$afterTypeLabel"

      assertEquals("node label value doesn't match", expectedLabel, label)

      if (checkChildren) {
        val intType = classRenderer.renderTypeName("java.lang.Integer")
        val intLabel = s"{$intType@$UNIQUE_ID}"
        var testIndex = 0
        children.foreach { childLabel =>
          val expectedChildLabel = s"$testIndex = $intLabel${testIndex + 1}"

          try
            assertEquals(expectedChildLabel, childLabel)
          catch {
            case err: AssertionError =>
              val childrenDebugText = children.zipWithIndex
                .map { case (child, idx) => s"$idx: $child"}
                .mkString("\n")
              System.err.println(s"all children nodes labels:\n$childrenDebugText")
              throw err
          }
          testIndex += 1
        }
      }
    }
  }

  protected def testCollectionRenderer(collectionName: String,
                                       collectionClass: String,
                                       afterTypeLabel: String,
                                       expectedChildrenLabels: Seq[String])
                                      (implicit timeout: Duration): Unit = {

    import org.junit.Assert._
    runDebugger() {
      waitForBreakpoint()
      val (label, childrenLabels) =
        renderLabelAndChildren(collectionName, _.getLabel, renderChildren = expectedChildrenLabels.nonEmpty, expectedChildrenLabels.size)

      val classRenderer: ClassRenderer = NodeRendererSettings.getInstance().getClassRenderer
      val typeName = classRenderer.renderTypeName(collectionClass)
      val expectedLabel = s"$collectionName = {$typeName@$UNIQUE_ID}$afterTypeLabel"
{'fraction_non_alphanumeric': 0.09857681038091251, 'fraction_numerical': 0.008162411050648808, 'mean_word_length': 2.7670476941269215, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '685777', 'n_tokens_mistral': 2617, 'n_tokens_neox': 2536, 'n_words': 501}