Add tests
This commit is contained in:
@ -305,7 +305,7 @@ TOKEN :
|
|||||||
{
|
{
|
||||||
< #CHRPREF : <STRPREF>>
|
< #CHRPREF : <STRPREF>>
|
||||||
| < CHARACTER : <CHRPREF>
|
| < CHARACTER : <CHRPREF>
|
||||||
"'" ( ( ~["'","\\","\r","\n"] ) | ( "\\" ( ~["\n","\r"] ) ) )* "'" >
|
"'" ( ( ~["'","\\","\r","\n"] ) | ( "\\" ( ~["\n","\r"] ) ) )+ "'" >
|
||||||
|
|
||||||
| < #STRPREF : ("L" | "u" | "U" | "u8")? >
|
| < #STRPREF : ("L" | "u" | "U" | "u8")? >
|
||||||
| < STRING : <STRPREF>
|
| < STRING : <STRPREF>
|
||||||
|
@ -8,18 +8,12 @@ import static org.junit.Assert.assertEquals;
|
|||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
||||||
import net.sourceforge.pmd.lang.ast.TokenMgrError;
|
|
||||||
|
|
||||||
public class CPPTokenizerTest extends CpdTextComparisonTest {
|
public class CPPTokenizerTest extends CpdTextComparisonTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException expectedException = ExpectedException.none();
|
|
||||||
|
|
||||||
public CPPTokenizerTest() {
|
public CPPTokenizerTest() {
|
||||||
super(".cpp");
|
super(".cpp");
|
||||||
}
|
}
|
||||||
@ -73,12 +67,6 @@ public class CPPTokenizerTest extends CpdTextComparisonTest {
|
|||||||
doTest("specialComments");
|
doTest("specialComments");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUnicodeEscapeInIdentifier() {
|
|
||||||
Tokens tokens = parse(" void main() { int a\\u0048; }");
|
|
||||||
assertEquals(10, tokens.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiLineMacros() {
|
public void testMultiLineMacros() {
|
||||||
doTest("multilineMacros");
|
doTest("multilineMacros");
|
||||||
@ -94,7 +82,6 @@ public class CPPTokenizerTest extends CpdTextComparisonTest {
|
|||||||
expectTokenMgrError(" void main() { int ⚜ = __; }");
|
expectTokenMgrError(" void main() { int ⚜ = __; }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTokenizerWithSkipBlocks() {
|
public void testTokenizerWithSkipBlocks() {
|
||||||
doTest("simpleSkipBlocks", "_skipDefault", skipBlocks());
|
doTest("simpleSkipBlocks", "_skipDefault", skipBlocks());
|
||||||
@ -128,10 +115,7 @@ public class CPPTokenizerTest extends CpdTextComparisonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLexicalErrorFilename() {
|
public void testLexicalErrorFilename() {
|
||||||
expectedException.expect(TokenMgrError.class);
|
expectTokenMgrError(sourceText("issue-1559"), dontSkipBlocks());
|
||||||
expectedException.expectMessage("Lexical error in file issue-1559.cpp at");
|
|
||||||
|
|
||||||
doTest("issue-1559", "", dontSkipBlocks());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,4 +3,5 @@
|
|||||||
int $yx = 42;
|
int $yx = 42;
|
||||||
int 県 = µweiß42;
|
int 県 = µweiß42;
|
||||||
int ❶ = __;
|
int ❶ = __;
|
||||||
|
int a\u0048; // unicode escape
|
||||||
}
|
}
|
@ -30,5 +30,9 @@ L5
|
|||||||
[__] 13 14
|
[__] 13 14
|
||||||
[;] 15 15
|
[;] 15 15
|
||||||
L6
|
L6
|
||||||
|
[int] 5 7
|
||||||
|
[a\\u0048] 9 15
|
||||||
|
[;] 16 16
|
||||||
|
L7
|
||||||
[}] 2 2
|
[}] 2 2
|
||||||
EOF
|
EOF
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
void main() {
|
void main() {
|
||||||
char x = L'a'; // wide chars
|
char x = L'a'; // wide chars
|
||||||
x = '\0x05'; // hex
|
x = '\0x05'; // hex
|
||||||
x = L''; // empty
|
// x = L''; // empty character is an error
|
||||||
|
|
||||||
print("\ oMedia"); // whitespace escape
|
print("\ oMedia"); // whitespace escape
|
||||||
|
|
||||||
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// digit separators
|
// digit separators
|
||||||
auto integer_literal = 1'000'000;
|
auto integer_literal = 1'000''000;
|
||||||
auto floating_point_literal = 0.000'015'3;
|
auto floating_point_literal = 0.000'015'3;
|
||||||
auto hex_literal = 0x0F00'abcd'6f3d;
|
auto hex_literal = 0x0F00'abcd'6f3d;
|
||||||
auto silly_example = 1'0'0'000'00;
|
auto silly_example = 1'0'0'000'00;
|
||||||
|
@ -16,11 +16,6 @@ L3
|
|||||||
[=] 7 7
|
[=] 7 7
|
||||||
['\\0x05'] 9 15
|
['\\0x05'] 9 15
|
||||||
[;] 16 16
|
[;] 16 16
|
||||||
L4
|
|
||||||
[x] 5 5
|
|
||||||
[=] 7 7
|
|
||||||
[L''] 9 11
|
|
||||||
[;] 12 12
|
|
||||||
L6
|
L6
|
||||||
[print] 5 9
|
[print] 5 9
|
||||||
[(] 10 10
|
[(] 10 10
|
||||||
@ -103,8 +98,8 @@ L35
|
|||||||
[auto] 5 8
|
[auto] 5 8
|
||||||
[integer_literal] 10 24
|
[integer_literal] 10 24
|
||||||
[=] 26 26
|
[=] 26 26
|
||||||
[1'000'000] 28 36
|
[1'000''000] 28 37
|
||||||
[;] 37 37
|
[;] 38 38
|
||||||
L36
|
L36
|
||||||
[auto] 5 8
|
[auto] 5 8
|
||||||
[floating_point_literal] 10 31
|
[floating_point_literal] 10 31
|
||||||
|
@ -39,14 +39,8 @@ abstract class BaseTextComparisonTest {
|
|||||||
expectedSuffix: String = "",
|
expectedSuffix: String = "",
|
||||||
transformTextContent: (String) -> String) {
|
transformTextContent: (String) -> String) {
|
||||||
val expectedFile = findTestFile(resourceLoader, "${resourcePrefix}/$fileBaseName$expectedSuffix$ExpectedExt").toFile()
|
val expectedFile = findTestFile(resourceLoader, "${resourcePrefix}/$fileBaseName$expectedSuffix$ExpectedExt").toFile()
|
||||||
val sourceFile = findTestFile(resourceLoader, "${resourcePrefix}/$fileBaseName$extensionIncludingDot").toFile()
|
|
||||||
|
|
||||||
assert(sourceFile.isFile) {
|
val actual = transformTextContent(sourceText(fileBaseName))
|
||||||
"Source file $sourceFile is missing"
|
|
||||||
}
|
|
||||||
|
|
||||||
val sourceText = sourceFile.readText(Charsets.UTF_8).normalize()
|
|
||||||
val actual = transformTextContent(sourceText)
|
|
||||||
|
|
||||||
if (!expectedFile.exists()) {
|
if (!expectedFile.exists()) {
|
||||||
expectedFile.writeText(actual)
|
expectedFile.writeText(actual)
|
||||||
@ -58,6 +52,17 @@ abstract class BaseTextComparisonTest {
|
|||||||
assertEquals(expected.normalize(), actual.normalize(), "File comparison failed, see the reference: $expectedFile")
|
assertEquals(expected.normalize(), actual.normalize(), "File comparison failed, see the reference: $expectedFile")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun sourceText(fileBaseName: String): String {
|
||||||
|
val sourceFile = findTestFile(resourceLoader, "${resourcePrefix}/$fileBaseName$extensionIncludingDot").toFile()
|
||||||
|
|
||||||
|
assert(sourceFile.isFile) {
|
||||||
|
"Source file $sourceFile is missing"
|
||||||
|
}
|
||||||
|
|
||||||
|
val sourceText = sourceFile.readText(Charsets.UTF_8).normalize()
|
||||||
|
return sourceText
|
||||||
|
}
|
||||||
|
|
||||||
// Outputting a path makes for better error messages
|
// Outputting a path makes for better error messages
|
||||||
private val srcTestResources = let {
|
private val srcTestResources = let {
|
||||||
// this is set from maven surefire
|
// this is set from maven surefire
|
||||||
|
Reference in New Issue
Block a user