Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nestedNameSpecifier test #1562

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ private static void expressions(LexerfulGrammarBuilder b) {

b.rule(nestedNameSpecifier).is(
b.firstOf(
"::",
"::", // C++
b.sequence(typeName, "::"), // C++
b.sequence(namespaceName, "::"), // C++
b.sequence(decltypeSpecifier, "::") // C++
Expand Down
32 changes: 28 additions & 4 deletions cxx-squid/src/test/java/org/sonar/cxx/parser/ExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,39 @@ public void nestedNameSpecifier() {
mockRule(CxxGrammarImpl.decltypeSpecifier);
mockRule(CxxGrammarImpl.simpleTemplateId);

assertThat(p).matches(":: typeName ::");
// basic
assertThat(p).matches("::");
assertThat(p).matches("typeName ::");
assertThat(p).matches(":: namespaceName ::");
assertThat(p).matches("namespaceName ::");
assertThat(p).matches("decltypeSpecifier ::");

// nested-name-specifier identifier ::
assertThat(p).matches(":: foo ::");
assertThat(p).matches("typeName :: foo ::");
assertThat(p).matches("namespaceName :: simpleTemplateId ::");
}
assertThat(p).matches("namespaceName :: foo ::");
assertThat(p).matches("decltypeSpecifier :: foo ::");

// nested-name-specifier simple-template-id ::
assertThat(p).matches(":: simpleTemplateId ::");
assertThat(p).matches("typeName :: simpleTemplateId ::");
assertThat(p).matches("namespaceName :: simpleTemplateId ::");
assertThat(p).matches("decltypeSpecifier :: simpleTemplateId ::");

// nested-name-specifier template simple-template-id ::
assertThat(p).matches(":: template simpleTemplateId ::");
assertThat(p).matches("typeName :: template simpleTemplateId ::");
assertThat(p).matches("namespaceName :: template simpleTemplateId ::");
assertThat(p).matches("decltypeSpecifier :: template simpleTemplateId ::");

// some deeper nested tests
assertThat(p).matches(":: foo1 :: foo2 :: foo3 :: foo4 ::");
assertThat(p).matches("typeName :: foo2 :: foo3 :: foo4 ::");
assertThat(p).matches("namespaceName :: foo2 :: foo3 :: foo4 ::");
assertThat(p).matches("decltypeSpecifier :: foo2 :: foo3 :: foo4 ::");
assertThat(p).matches(":: foo1 :: simpleTemplateId :: foo2 :: simpleTemplateId ::");
assertThat(p).matches(":: foo1 :: template simpleTemplateId :: foo2 :: template simpleTemplateId ::");
}

@Test
public void postfixExpression() {
p.setRootRule(g.rule(CxxGrammarImpl.postfixExpression));
Expand Down