[Libreoffice-commits] core.git: 3 commits - comphelper/qa comphelper/source
Stephan Bergmann
sbergman at redhat.com
Mon Oct 28 02:47:43 PDT 2013
comphelper/qa/unit/syntaxhighlighttest.cxx | 89 +++++++++++++++++++++++++++--
comphelper/source/misc/syntaxhighlight.cxx | 19 +++---
2 files changed, 95 insertions(+), 13 deletions(-)
New commits:
commit 0827aba84e1adec902c4d704651a1027b01c5335
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Oct 28 10:44:28 2013 +0100
Correctly fix "Terminating NUL" fix
1cbe2313edda8a04f0fe233b4a29ef4e2485f557 "Terminating NUL at end of its buffer
is not considered part of OUString" was a thinko that cut the last character off
the last reported HighlightPortion on a line.
Change-Id: Idbe74676e85749cd93854293c6f49c7581414562
diff --git a/comphelper/qa/unit/syntaxhighlighttest.cxx b/comphelper/qa/unit/syntaxhighlighttest.cxx
index c576f7b..294db3e 100644
--- a/comphelper/qa/unit/syntaxhighlighttest.cxx
+++ b/comphelper/qa/unit/syntaxhighlighttest.cxx
@@ -21,13 +21,94 @@ class SyntaxHighlightTest : public CppUnit::TestFixture
{
public:
void testBasicString();
+ void testBasicComment();
+ void testBasicCommentNewline();
+ void testBasicEmptyComment();
+ void testBasicEmptyCommentNewline();
+ void testBasic();
CPPUNIT_TEST_SUITE(SyntaxHighlightTest);
CPPUNIT_TEST(testBasicString);
+ CPPUNIT_TEST(testBasicComment);
+ CPPUNIT_TEST(testBasicCommentNewline);
+ CPPUNIT_TEST(testBasicEmptyComment);
+ CPPUNIT_TEST(testBasicEmptyCommentNewline);
+ CPPUNIT_TEST(testBasic);
CPPUNIT_TEST_SUITE_END();
};
-void SyntaxHighlightTest::testBasicString()
+void SyntaxHighlightTest::testBasicString() {
+ SyntaxHighlighter h;
+ h.initialize(HIGHLIGHT_BASIC);
+ OUString s("\"foo\"");
+ std::vector<HighlightPortion> ps;
+ h.getHighlightPortions(0, s, ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
+ CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(5, ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TT_STRING, ps[0].tokenType);
+}
+
+void SyntaxHighlightTest::testBasicComment() {
+ SyntaxHighlighter h;
+ h.initialize(HIGHLIGHT_BASIC);
+ OUString s("' foo");
+ std::vector<HighlightPortion> ps;
+ h.getHighlightPortions(0, s, ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
+ CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(5, ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType);
+}
+
+void SyntaxHighlightTest::testBasicCommentNewline() {
+ SyntaxHighlighter h;
+ h.initialize(HIGHLIGHT_BASIC);
+ OUString s("' foo\n");
+ std::vector<HighlightPortion> ps;
+ h.getHighlightPortions(0, s, ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size());
+ CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(5, ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(5, ps[1].nBegin);
+ CPPUNIT_ASSERT_EQUAL(6, ps[1].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TT_EOL, ps[1].tokenType);
+}
+
+void SyntaxHighlightTest::testBasicEmptyComment() {
+ SyntaxHighlighter h;
+ h.initialize(HIGHLIGHT_BASIC);
+ OUString s("'");
+ std::vector<HighlightPortion> ps;
+ h.getHighlightPortions(0, s, ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
+ CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(1, ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType);
+}
+
+void SyntaxHighlightTest::testBasicEmptyCommentNewline() {
+ SyntaxHighlighter h;
+ h.initialize(HIGHLIGHT_BASIC);
+ OUString s("'\n");
+ std::vector<HighlightPortion> ps;
+ h.getHighlightPortions(0, s, ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size());
+ CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(1, ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(1, ps[1].nBegin);
+ CPPUNIT_ASSERT_EQUAL(2, ps[1].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TT_EOL, ps[1].tokenType);
+}
+
+void SyntaxHighlightTest::testBasic()
{
OUString aBasicString(" if Mid(sText,iRun,1 )<> \" \" then Mid( sText ,iRun, 1, Chr( 1 + Asc( Mid(sText,iRun,1 )) ) '");
@@ -46,13 +127,6 @@ void SyntaxHighlightTest::testBasicString()
prevEnd = itr->nEnd;
}
CPPUNIT_ASSERT_EQUAL(aBasicString.getLength(), prevEnd);
-
- // The last portion is an empty comment consisting just of the leading
- // apostrophe:
- assert(!aPortions.empty());
- CPPUNIT_ASSERT_EQUAL(98, aPortions.back().nBegin);
- CPPUNIT_ASSERT_EQUAL(99, aPortions.back().nEnd);
- CPPUNIT_ASSERT_EQUAL(TT_COMMENT, aPortions.back().tokenType);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SyntaxHighlightTest);
diff --git a/comphelper/source/misc/syntaxhighlight.cxx b/comphelper/source/misc/syntaxhighlight.cxx
index 83bcb59..ca3207d 100644
--- a/comphelper/source/misc/syntaxhighlight.cxx
+++ b/comphelper/source/misc/syntaxhighlight.cxx
@@ -399,14 +399,13 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType,
// Comment?
if ( c == '\'' )
{
- c = getChar();
-
- // Remove all characters until end of line or EOF
- sal_Unicode cPeek = c;
- while( cPeek != 0 && testCharFlags( cPeek, CHAR_EOL ) == sal_False )
- {
+ // Skip all characters until end of input or end of line:
+ for (;;) {
+ c = peekChar();
+ if (c == 0 || testCharFlags(c, CHAR_EOL)) {
+ break;
+ }
getChar();
- cPeek = peekChar();
}
reType = TT_COMMENT;
@@ -540,7 +539,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType,
// All other will remain TT_UNKNOWN
// Save end position
- rpEndPos = *mpActualPos == 0 ? mpActualPos - 1 : mpActualPos;
+ rpEndPos = mpActualPos;
return sal_True;
}
commit 2733bc38f08c96552e31bda5e3fc34017c81b1c2
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Oct 28 09:19:42 2013 +0100
Demonstrate that empty comments are handled just fine
...see preceding revert of a79cb836b951eb2492e43aadd2ee672b9b67b914 "COMPHELPER:
Allow empty comments in SyntaxHighlight."
Change-Id: Ib0a8c46c19dd7f0697b95a1c28398073a1183281
diff --git a/comphelper/qa/unit/syntaxhighlighttest.cxx b/comphelper/qa/unit/syntaxhighlighttest.cxx
index 8fab067..c576f7b 100644
--- a/comphelper/qa/unit/syntaxhighlighttest.cxx
+++ b/comphelper/qa/unit/syntaxhighlighttest.cxx
@@ -14,6 +14,7 @@
#include "cppunit/plugin/TestPlugIn.h"
#include "rtl/ustring.hxx"
+#include <cassert>
#include <vector>
class SyntaxHighlightTest : public CppUnit::TestFixture
@@ -45,6 +46,13 @@ void SyntaxHighlightTest::testBasicString()
prevEnd = itr->nEnd;
}
CPPUNIT_ASSERT_EQUAL(aBasicString.getLength(), prevEnd);
+
+ // The last portion is an empty comment consisting just of the leading
+ // apostrophe:
+ assert(!aPortions.empty());
+ CPPUNIT_ASSERT_EQUAL(98, aPortions.back().nBegin);
+ CPPUNIT_ASSERT_EQUAL(99, aPortions.back().nEnd);
+ CPPUNIT_ASSERT_EQUAL(TT_COMMENT, aPortions.back().tokenType);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SyntaxHighlightTest);
commit a699e7c70d312c96d0dbb8eb4c31b81129dcf7b2
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Oct 28 08:47:22 2013 +0100
Revert "COMPHELPER: Allow empty comments in SyntaxHighlight"
This reverts commit a79cb836b951eb2492e43aadd2ee672b9b67b914, which broke
--with-help builds again, as
strLine.copy(i->nBegin, i->nEnd-i->nBegin)
in BasicCodeTagger::tagParagraph (helpcompiler/source/BasCodeTagger.cxx) depends
on the invariant that a HighlightPortion does not extend past the source string.
Also, I see no reason for that change, as empty comments are handled just fine
already as demonstrated by the following commit...
Change-Id: I384bae9c4cf6a38d0a0a2832fa15bde82126cace
diff --git a/comphelper/qa/unit/syntaxhighlighttest.cxx b/comphelper/qa/unit/syntaxhighlighttest.cxx
index d26b855..8fab067 100644
--- a/comphelper/qa/unit/syntaxhighlighttest.cxx
+++ b/comphelper/qa/unit/syntaxhighlighttest.cxx
@@ -41,11 +41,10 @@ void SyntaxHighlightTest::testBasicString()
aPortions.begin(), itrEnd = aPortions.end(); itr != itrEnd; ++itr)
{
CPPUNIT_ASSERT_EQUAL(prevEnd, itr->nBegin);
- //The comment is empty, so empty zone
- CPPUNIT_ASSERT(itr->nBegin <= itr->nEnd);
+ CPPUNIT_ASSERT(itr->nBegin < itr->nEnd);
prevEnd = itr->nEnd;
}
- CPPUNIT_ASSERT_EQUAL(aBasicString.getLength() - 1, prevEnd);
+ CPPUNIT_ASSERT_EQUAL(aBasicString.getLength(), prevEnd);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SyntaxHighlightTest);
diff --git a/comphelper/source/misc/syntaxhighlight.cxx b/comphelper/source/misc/syntaxhighlight.cxx
index c6340ef..83bcb59 100644
--- a/comphelper/source/misc/syntaxhighlight.cxx
+++ b/comphelper/source/misc/syntaxhighlight.cxx
@@ -399,14 +399,16 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType,
// Comment?
if ( c == '\'' )
{
- c = peekChar();
+ c = getChar();
// Remove all characters until end of line or EOF
sal_Unicode cPeek = c;
while( cPeek != 0 && testCharFlags( cPeek, CHAR_EOL ) == sal_False )
{
- cPeek = getChar();
+ getChar();
+ cPeek = peekChar();
}
+
reType = TT_COMMENT;
}
@@ -672,7 +674,7 @@ void SimpleTokenizer_Impl::getHighlightPortions( sal_uInt32 nParseLine, const OU
const sal_Unicode* pEndPos;
// Loop over all the tokens
- while( getNextToken( eType, pStartPos, pEndPos ) )
+ while( getNextToken( eType, pStartPos, pEndPos ) )
{
portions.push_back(
HighlightPortion(
More information about the Libreoffice-commits
mailing list