summaryrefslogtreecommitdiffstats
path: root/comphelper/qa/unit/syntaxhighlighttest.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /comphelper/qa/unit/syntaxhighlighttest.cxx
parentInitial commit. (diff)
downloadlibreoffice-upstream/4%7.4.7.tar.xz
libreoffice-upstream/4%7.4.7.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--comphelper/qa/unit/syntaxhighlighttest.cxx117
1 files changed, 117 insertions, 0 deletions
diff --git a/comphelper/qa/unit/syntaxhighlighttest.cxx b/comphelper/qa/unit/syntaxhighlighttest.cxx
new file mode 100644
index 000000000..eab382b85
--- /dev/null
+++ b/comphelper/qa/unit/syntaxhighlighttest.cxx
@@ -0,0 +1,117 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <comphelper/syntaxhighlight.hxx>
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <rtl/ustring.hxx>
+
+#include <vector>
+
+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() {
+ std::vector<HighlightPortion> ps;
+ SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"\"foo\"", ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TokenType::String, ps[0].tokenType);
+}
+
+void SyntaxHighlightTest::testBasicComment() {
+ std::vector<HighlightPortion> ps;
+ SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"' foo", ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
+}
+
+void SyntaxHighlightTest::testBasicCommentNewline() {
+ std::vector<HighlightPortion> ps;
+ SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"' foo\n", ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[1].nBegin);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(6), ps[1].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TokenType::EOL, ps[1].tokenType);
+}
+
+void SyntaxHighlightTest::testBasicEmptyComment() {
+ std::vector<HighlightPortion> ps;
+ SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"'", ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
+}
+
+void SyntaxHighlightTest::testBasicEmptyCommentNewline() {
+ std::vector<HighlightPortion> ps;
+ SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"'\n", ps);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[0].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[1].nBegin);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), ps[1].nEnd);
+ CPPUNIT_ASSERT_EQUAL(TokenType::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 )) ) '");
+
+ std::vector<HighlightPortion> aPortions;
+ SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(
+ aBasicString, aPortions );
+
+ sal_Int32 prevEnd = 0;
+ for (auto const& portion : aPortions)
+ {
+ CPPUNIT_ASSERT_EQUAL(prevEnd, portion.nBegin);
+ CPPUNIT_ASSERT(portion.nBegin < portion.nEnd);
+ prevEnd = portion.nEnd;
+ }
+ CPPUNIT_ASSERT_EQUAL(aBasicString.getLength(), prevEnd);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SyntaxHighlightTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */