From aefabe0d799738c4a01219b7696e65669376e7ae Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 21 Feb 2011 19:09:58 +0100 Subject: [PATCH] fix parsing of character classes so that it's actually correct (PY-1929) --- python/python.iml | 2 +- .../testData/regexp/braceInPythonCharacterClass.py | 3 +++ .../testSrc/com/jetbrains/python/PyRegexpTest.java | 12 ++++++++++++ .../jetbrains/python/fixtures/PyLexerTestCase.java | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 python/testData/regexp/braceInPythonCharacterClass.py diff --git a/python/python.iml b/python/python.iml index 57624ffc30b3..aa0cfdc9decb 100644 --- a/python/python.iml +++ b/python/python.iml @@ -23,7 +23,7 @@ - + diff --git a/python/testData/regexp/braceInPythonCharacterClass.py b/python/testData/regexp/braceInPythonCharacterClass.py new file mode 100644 index 000000000000..8066c64a120e --- /dev/null +++ b/python/testData/regexp/braceInPythonCharacterClass.py @@ -0,0 +1,3 @@ +import re + +EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]') diff --git a/python/testSrc/com/jetbrains/python/PyRegexpTest.java b/python/testSrc/com/jetbrains/python/PyRegexpTest.java index 23bbb8869ed2..207b2cb2e242 100644 --- a/python/testSrc/com/jetbrains/python/PyRegexpTest.java +++ b/python/testSrc/com/jetbrains/python/PyRegexpTest.java @@ -1,5 +1,8 @@ package com.jetbrains.python; +import com.intellij.lexer.Lexer; +import com.jetbrains.python.codeInsight.regexp.PythonRegexpParserDefinition; +import com.jetbrains.python.fixtures.PyLexerTestCase; import com.jetbrains.python.fixtures.PyLightFixtureTestCase; /** @@ -10,6 +13,11 @@ public class PyRegexpTest extends PyLightFixtureTestCase { doTest(); } + public void testNestedCharacterClassesLexer() { + Lexer lexer = new PythonRegexpParserDefinition().createLexer(myFixture.getProject()); + PyLexerTestCase.doLexerTest("[][]", lexer, "CLASS_BEGIN", "CHARACTER", "CHARACTER", "CLASS_END"); + } + public void testNestedCharacterClasses2() { // PY-2908 doTest(); } @@ -18,6 +26,10 @@ public class PyRegexpTest extends PyLightFixtureTestCase { doTest(); } + public void testBraceInPythonCharacterClass() { // PY-1929 + doTest(); + } + private void doTest() { myFixture.testHighlighting(true, false, false, "regexp/" + getTestName(true) + ".py"); } diff --git a/python/testSrc/com/jetbrains/python/fixtures/PyLexerTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/PyLexerTestCase.java index 4c9667576185..9e3a0f16e01d 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/PyLexerTestCase.java +++ b/python/testSrc/com/jetbrains/python/fixtures/PyLexerTestCase.java @@ -7,7 +7,7 @@ import junit.framework.TestCase; * @author yole */ public abstract class PyLexerTestCase extends TestCase { - protected static void doLexerTest(String text, Lexer lexer, String... expectedTokens) { + public static void doLexerTest(String text, Lexer lexer, String... expectedTokens) { lexer.start(text); int idx = 0; int tokenPos = 0;