-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support session control statements (closes #10)
- Loading branch information
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
plsql-frontend/src/main/java/org/sonar/plugins/plsqlopen/api/SessionControlGrammar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.sonar.plugins.plsqlopen.api; | ||
|
||
import static com.sonar.sslr.api.GenericTokenType.EOF; | ||
import static org.sonar.plugins.plsqlopen.api.PlSqlGrammar.IDENTIFIER_NAME; | ||
import static org.sonar.plugins.plsqlopen.api.PlSqlKeyword.*; | ||
import static org.sonar.plugins.plsqlopen.api.PlSqlPunctuator.*; | ||
|
||
import org.sonar.sslr.grammar.GrammarRuleKey; | ||
import org.sonar.sslr.grammar.LexerfulGrammarBuilder; | ||
|
||
public enum SessionControlGrammar implements GrammarRuleKey { | ||
|
||
ALTER_SESSION, | ||
SET_ROLE, | ||
SESSION_CONTROL_COMMAND; | ||
|
||
public static void buildOn(LexerfulGrammarBuilder b) { | ||
|
||
b.rule(ALTER_SESSION).is(ALTER, SESSION, b.oneOrMore(b.anyTokenButNot(b.firstOf(SEMICOLON, DIVISION, EOF)))); | ||
|
||
b.rule(SET_ROLE).is(SET, ROLE, | ||
b.firstOf( | ||
NONE, | ||
b.sequence(ALL, b.optional(EXCEPT, b.oneOrMore(IDENTIFIER_NAME, b.optional(COMMA)))), | ||
b.oneOrMore(IDENTIFIER_NAME, b.optional(IDENTIFIED, BY, b.anyToken()), b.optional(COMMA)) | ||
)); | ||
|
||
b.rule(SESSION_CONTROL_COMMAND).is(b.firstOf(ALTER_SESSION, SET_ROLE), b.optional(SEMICOLON)); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...tend/src/test/java/org/sonar/plugins/plsqlopen/api/session/SessionControlGrammarTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.sonar.plugins.plsqlopen.api.session; | ||
|
||
import static org.sonar.sslr.tests.Assertions.assertThat; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.sonar.plugins.plsqlopen.api.RuleTest; | ||
import org.sonar.plugins.plsqlopen.api.SessionControlGrammar; | ||
|
||
public class SessionControlGrammarTest extends RuleTest { | ||
|
||
@Before | ||
public void init() { | ||
setRootRule(SessionControlGrammar.SESSION_CONTROL_COMMAND); | ||
} | ||
|
||
@Test | ||
public void matchesAlterSession() { | ||
assertThat(p).matches("alter session set nls_date_format = 'dd/mm/yyyy';"); | ||
} | ||
|
||
@Test | ||
public void matchesSetRole() { | ||
assertThat(p).matches("set role foo;"); | ||
assertThat(p).matches("set role foo, bar, baz;"); | ||
} | ||
|
||
@Test | ||
public void matchesSetRoleNone() { | ||
assertThat(p).matches("set role none;"); | ||
} | ||
|
||
@Test | ||
public void matchesSetRoleAll() { | ||
assertThat(p).matches("set role all;"); | ||
} | ||
|
||
@Test | ||
public void matchesSetRoleAllExcept() { | ||
assertThat(p).matches("set role all except foo;"); | ||
assertThat(p).matches("set role all except foo, bar, baz;"); | ||
} | ||
|
||
@Test | ||
public void matchesSetRoleWithPassword() { | ||
assertThat(p).matches("set role foo identified by pass;"); | ||
assertThat(p).matches("set role foo identified by pass, bar, baz;"); | ||
} | ||
|
||
} |