From cbd86c9ccf880f85045b8cc5ecc2ab7f719bccab Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Fri, 26 Oct 2012 17:24:52 +0400 Subject: [PATCH] fixed PY-7864 Dostest: Statement expected: false positive for empty doctest --- .../python/documentation/doctest/PyDocstringLexer.java | 7 ++----- .../documentation/doctest/PyDocstringParsingContext.java | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/documentation/doctest/PyDocstringLexer.java b/python/src/com/jetbrains/python/documentation/doctest/PyDocstringLexer.java index fdf8adb4ddb2..e76d00aadf96 100644 --- a/python/src/com/jetbrains/python/documentation/doctest/PyDocstringLexer.java +++ b/python/src/com/jetbrains/python/documentation/doctest/PyDocstringLexer.java @@ -42,21 +42,18 @@ public class PyDocstringLexer extends PythonIndentingLexer { indent = 0; while (getBaseTokenType() != null && ourIgnoreSet.contains(getBaseTokenType())) advanceBase(); - while (getBaseTokenType() != null && PyTokenTypes.WHITESPACE_OR_LINEBREAK.contains(getBaseTokenType())) { + while (getBaseTokenType() != null && PyTokenTypes.WHITESPACE.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; - } advanceBase(); } if (getBaseTokenType() == null) { return 0; } - return indent - 1; + return indent > 0? indent - 1 : indent; } } diff --git a/python/src/com/jetbrains/python/documentation/doctest/PyDocstringParsingContext.java b/python/src/com/jetbrains/python/documentation/doctest/PyDocstringParsingContext.java index 3eaace6768d2..6f196d41855c 100644 --- a/python/src/com/jetbrains/python/documentation/doctest/PyDocstringParsingContext.java +++ b/python/src/com/jetbrains/python/documentation/doctest/PyDocstringParsingContext.java @@ -58,6 +58,11 @@ public class PyDocstringParsingContext extends ParsingContext { IElementType type = myBuilder.getTokenType(); if (type == PyDocstringTokenTypes.WELCOME) { // >>> case myBuilder.advanceLexer(); + while (myBuilder.getTokenType() == PyTokenTypes.STATEMENT_BREAK || myBuilder.getTokenType() == PyDocstringTokenTypes.WELCOME) { + myBuilder.advanceLexer(); + } + if (myBuilder.getTokenType() == PyTokenTypes.INDENT) + myBuilder.advanceLexer(); } super.parseStatement(scope); }