Skip to content

Commit

Permalink
Tests for conditional operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
badly-drawn-wizards committed Mar 22, 2024
1 parent e95387d commit 4f4232c
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,24 @@ class ConditionalTests extends RubyCode2CpgFixture {
}
}

"`f(x ? y : z)` is lowered into conditional operator" in {
val cpg = code("""
|f(x ? y : z)
|""".stripMargin)
val List(cond) = cpg.call(Operators.conditional).l
val List(x,y,z) = cond.argument.l
x.code shouldBe "x"
List(y,z).isBlock.astChildren.isIdentifier.code.l shouldBe List("y","z")
}

"`f(unless x then y else z end)` is lowered into conditional operator" in {
val cpg = code("""
|f(unless x then y else z end)
|""".stripMargin)
val List(cond) = cpg.call(Operators.conditional).l
val List(x,y,z) = cond.argument.l
List(x).isCall.name(Operators.logicalNot).argument.code.l shouldBe List("x")
List(y,z).isBlock.astChildren.isIdentifier.code.l shouldBe List("y","z")
}

}

0 comments on commit 4f4232c

Please sign in to comment.