Skip to content

Commit

Permalink
Add test for ExistsSimplifiableToContains (#711)
Browse files Browse the repository at this point in the history
* Add test for ExistsSimplifiableToContains
  • Loading branch information
saeltz authored Nov 28, 2022
1 parent ad598e4 commit a3036e2
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.sksamuel.scapegoat.inspections.collections

import com.sksamuel.scapegoat.InspectionTest
import com.sksamuel.scapegoat.{Inspection, InspectionTest}

/** @author Stephen Samuel */
class ExistsSimplifiableToContainsTest extends InspectionTest {

override val inspections = Seq(new ExistsSimplifiableToContains)
override val inspections: Seq[Inspection] = Seq(new ExistsSimplifiableToContains)

"should report warning" - {
"when exists is called with compatible type" in {
Expand All @@ -15,7 +15,7 @@ class ExistsSimplifiableToContainsTest extends InspectionTest {
|val list = List("sam", "spade")
|val exists2 = list.exists(_ == "spoof")
|val exists3 = (1 to 3).exists(_ == 2)
|} """.stripMargin
|}""".stripMargin

compileCodeSnippet(code)
compiler.scapegoat.feedback.warnings.size shouldBe 3
Expand All @@ -30,8 +30,7 @@ class ExistsSimplifiableToContainsTest extends InspectionTest {
| element.toLowerCase == "a"
| }
| }
|}
|""".stripMargin
|}""".stripMargin
compileCodeSnippet(code)
compiler.scapegoat.feedback.warnings.size shouldBe 1
}
Expand All @@ -44,7 +43,7 @@ class ExistsSimplifiableToContainsTest extends InspectionTest {
|val exists1 = List("sam").exists(x => x == new RuntimeException)
|val list = List("sam", "spade")
|val exists2 = list.exists(_ == 3)
|} """.stripMargin
|}""".stripMargin

compileCodeSnippet(code)
compiler.scapegoat.feedback.warnings.size shouldBe 0
Expand Down Expand Up @@ -72,8 +71,7 @@ class ExistsSimplifiableToContainsTest extends InspectionTest {
| element == element.toLowerCase
| }
| }
|}
|""".stripMargin
|}""".stripMargin
compileCodeSnippet(code)
compiler.scapegoat.feedback.warnings.size shouldBe 0
}
Expand All @@ -87,8 +85,16 @@ class ExistsSimplifiableToContainsTest extends InspectionTest {
| element.replaceAll("a", "").size == element.size
| }
| }
|}
|""".stripMargin
|}""".stripMargin
compileCodeSnippet(code)
compiler.scapegoat.feedback.warnings.size shouldBe 0
}

"when a Map's key and value are of the same type" in {
val code =
"""
|val map = Map("answer" -> "42")
|val isCorrect = map.exists(_._2 == "42")""".stripMargin
compileCodeSnippet(code)
compiler.scapegoat.feedback.warnings.size shouldBe 0
}
Expand Down

0 comments on commit a3036e2

Please sign in to comment.