fixed PY-7962 Doctest: IndentationError: false positives for tests with empty lines

This commit is contained in:
Ekaterina Tuzova
2012-11-09 18:31:41 +04:00
parent 16dd3f0277
commit 94f549ec05
4 changed files with 65 additions and 5 deletions
@@ -42,19 +42,22 @@ public class PyDocstringLexer extends PythonIndentingLexer {
indent = 0;
while (getBaseTokenType() != null && ourIgnoreSet.contains(getBaseTokenType()))
advanceBase();
while (getBaseTokenType() != null && PyTokenTypes.WHITESPACE.contains(getBaseTokenType())) {
while (getBaseTokenType() != null && (PyTokenTypes.WHITESPACE_OR_LINEBREAK.contains(getBaseTokenType()) ||
ourIgnoreSet.contains(getBaseTokenType()))) {
if (getBaseTokenType() == PyTokenTypes.TAB) {
indent = ((indent / 8) + 1) * 8;
}
else if (getBaseTokenType() == PyTokenTypes.SPACE) {
indent++;
}
else if (getBaseTokenType() == PyTokenTypes.LINE_BREAK) {
indent = 0;
super.getNextLineIndent();
}
advanceBase();
}
if (getBaseTokenType() == PyTokenTypes.LINE_BREAK) {
advanceBase();
return 0;
}
if (getBaseTokenType() == null) {
return 0;
+14
View File
@@ -0,0 +1,14 @@
def foo3(x):
'''
>>> class User(Base):
... __tablename__ = 'users'
...
... <caret>id = Column(Integer, primary_key=True)
... name = Column(String)
... fullname = Column(String)
...
... password = Column(String)
'''
pass
+14
View File
@@ -0,0 +1,14 @@
def foo3(x):
'''
>>> class User(Base):
... __tablename__ = 'users'
...
... <caret>id = Column(Integer, primary_key=True)
... name = Column(String)
... fullname = Column(String)
...
... password = Column(String)
'''
pass
@@ -1,9 +1,17 @@
package com.jetbrains.python;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.documentation.doctest.PyDocstringParserDefinition;
import com.jetbrains.python.fixtures.PyTestCase;
import java.util.List;
/**
* User: ktisha
*/
@@ -46,6 +54,27 @@ public class PyDocstringTest extends PyTestCase {
return testName + ".expected.docstring";
}
public void testNoErrors() {
doTestIndentation(false);
}
public void testHasErrors() {
doTestIndentation(true);
}
private void doTestIndentation(boolean hasErrors) {
String inputDataFileName = getTestName(true) + ".py";
myFixture.configureByFile(inputDataFileName);
final InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(myFixture.getProject());
final PsiLanguageInjectionHost host = languageManager.getInjectionHost(myFixture.getElementAtCaret());
assertNotNull(host);
final List<Pair<PsiElement,TextRange>> files = languageManager.getInjectedPsiFiles(host);
assertNotNull(files);
for (Pair<PsiElement,TextRange> pair : files) {
assertEquals(hasErrors, PsiTreeUtil.hasErrorElements(pair.getFirst()));
}
}
private void doTestLexer(final String text, String... expectedTokens) {
Lexer lexer = new PyDocstringParserDefinition().createLexer(myFixture.getProject());