From 4f4232c63f15c9ec10578eee39a11e2bf8824275 Mon Sep 17 00:00:00 2001 From: Reuben Steenekamp Date: Fri, 22 Mar 2024 16:14:28 +0200 Subject: [PATCH] Tests for conditional operators. --- .../querying/ConditionalTests.scala | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/querying/ConditionalTests.scala b/joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/querying/ConditionalTests.scala index 8159757c2395..92841f3e2366 100644 --- a/joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/querying/ConditionalTests.scala +++ b/joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/querying/ConditionalTests.scala @@ -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") + } + }