Skip to content

Commit

Permalink
Merge pull request #1562 from guwirth/nested-name-specifier
Browse files Browse the repository at this point in the history
nestedNameSpecifier test
  • Loading branch information
guwirth authored Oct 2, 2018
2 parents d948649 + 13161c7 commit 41f8bf7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
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

0 comments on commit 41f8bf7

Please sign in to comment.