Skip to content

Commit

Permalink
feat(grammar): Add BOOLEAN_TEST_CONDITION node to support IS TRUE/FAL…
Browse files Browse the repository at this point in the history
…SE conditions in addition to IS NULL
  • Loading branch information
felipebz committed Sep 29, 2024
1 parent ed033a6 commit 1ca3c0e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2939,36 +2939,6 @@
"sqlrf/annotations_clause-5.sql" : [
3
],
"sqlrf/boolean_and_agg-2.sql" : [
4
],
"sqlrf/boolean_and_agg-3.sql" : [
4
],
"sqlrf/boolean_and_agg-4.sql" : [
4
],
"sqlrf/boolean_and_agg-5.sql" : [
4
],
"sqlrf/boolean_and_agg-6.sql" : [
4
],
"sqlrf/boolean_or_agg-2.sql" : [
4
],
"sqlrf/boolean_or_agg-3.sql" : [
4
],
"sqlrf/boolean_or_agg-4.sql" : [
4
],
"sqlrf/boolean_or_agg-5.sql" : [
4
],
"sqlrf/boolean_or_agg-6.sql" : [
4
],
"sqlrf/constraint-1.sql" : [
10
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"sqlrf/boolean_and_agg-6.sql" : [
2,
2
],
"sqlrf/boolean_or_agg-6.sql" : [
2
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package org.sonar.plugins.plsqlopen.api
import com.felipebz.flr.grammar.GrammarRuleKey
import org.sonar.plsqlopen.sslr.PlSqlGrammarBuilder
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar.CONCATENATION_EXPRESSION
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar.NULL_LITERAL
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar.OBJECT_REFERENCE
import org.sonar.plugins.plsqlopen.api.PlSqlKeyword.*

Expand All @@ -39,6 +40,7 @@ enum class ConditionsGrammar : GrammarRuleKey {

// conditions
RELATIONAL_CONDITION,
BOOLEAN_TEST_CONDITION,
LIKE_CONDITION,
BETWEEN_CONDITION,
MULTISET_CONDITION,
Expand Down Expand Up @@ -71,6 +73,10 @@ enum class ConditionsGrammar : GrammarRuleKey {
CONCATENATION_EXPRESSION, RELATIONAL_OPERATOR, CONCATENATION_EXPRESSION
).skip()

b.rule(BOOLEAN_TEST_CONDITION).define(
CONCATENATION_EXPRESSION, IS, b.optional(NOT), b.firstOf(NULL_LITERAL, TRUE, FALSE)
)

b.rule(LIKE_CONDITION).define(
CONCATENATION_EXPRESSION,
b.optional(NOT), LIKE,
Expand Down Expand Up @@ -244,6 +250,7 @@ enum class ConditionsGrammar : GrammarRuleKey {
b.rule(CONDITION).define(
b.firstOf(
RELATIONAL_CONDITION,
BOOLEAN_TEST_CONDITION,
LIKE_CONDITION,
BETWEEN_CONDITION,
MULTISET_CONDITION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,6 @@ enum class PlSqlGrammar : GrammarRuleKey {

b.rule(POSTFIX_EXPRESSION).define(OBJECT_REFERENCE,
b.optional(b.firstOf(
b.sequence(IS, b.optional(NOT), NULL_LITERAL),
ANALYTIC_CLAUSE,
b.sequence(KEEP_CLAUSE, b.optional(ANALYTIC_CLAUSE))))).skipIfOneChild()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ class OtherExpressionTest : RuleTest() {
assertThat(p).matches("var is not null")
}

@Test
fun matchesIsTrue() {
assertThat(p).matches("var is true")
}

@Test
fun matchesIsNotTrue() {
assertThat(p).matches("var is not true")
}

@Test
fun matchesIsFalse() {
assertThat(p).matches("var is false")
}

@Test
fun matchesIsNotFalse() {
assertThat(p).matches("var is not false")
}

@Test
fun matchesBasicIn() {
assertThat(p).matches("var in (1)")
Expand Down

0 comments on commit 1ca3c0e

Please sign in to comment.