<commit_before>/* -*- 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();

    CPPUNIT_TEST_SUITE(SyntaxHighlightTest);
    CPPUNIT_TEST(testBasicString);
    CPPUNIT_TEST_SUITE_END();
};

void SyntaxHighlightTest::testBasicString()
{
    OUString aBasicString("        if Mid(sText,iRun,1 )<> \" \" then Mid( sText ,iRun, 1, Chr( 1 + Asc( Mid(sText,iRun,1 )) ) '");

    SyntaxHighlighter aHighlighter;
    aHighlighter.initialize( HIGHLIGHT_BASIC );

    std::vector<HighlightPortion> aPortions;
    aHighlighter.getHighlightPortions( 0, aBasicString, aPortions );

    sal_Int32 prevEnd = 0;
    for(std::vector<HighlightPortion>::const_iterator itr =
            aPortions.begin(), itrEnd = aPortions.end(); itr != itrEnd; ++itr)
    {
        CPPUNIT_ASSERT_EQUAL(prevEnd, itr->nBegin);
        CPPUNIT_ASSERT(itr->nBegin < itr->nEnd);
        prevEnd = itr->nEnd;
    }
    CPPUNIT_ASSERT_EQUAL(aBasicString.getLength(), prevEnd);
}

CPPUNIT_TEST_SUITE_REGISTRATION(SyntaxHighlightTest);

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */<commit_msg>Demonstrate that empty comments are handled just fine<commit_after>/* -*- 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 <cassert>
#include <vector>

class SyntaxHighlightTest : public CppUnit::TestFixture
{
public:
    void testBasicString();

    CPPUNIT_TEST_SUITE(SyntaxHighlightTest);
    CPPUNIT_TEST(testBasicString);
    CPPUNIT_TEST_SUITE_END();
};

void SyntaxHighlightTest::testBasicString()
{
    OUString aBasicString("        if Mid(sText,iRun,1 )<> \" \" then Mid( sText ,iRun, 1, Chr( 1 + Asc( Mid(sText,iRun,1 )) ) '");

    SyntaxHighlighter aHighlighter;
    aHighlighter.initialize( HIGHLIGHT_BASIC );

    std::vector<HighlightPortion> aPortions;
    aHighlighter.getHighlightPortions( 0, aBasicString, aPortions );

    sal_Int32 prevEnd = 0;
    for(std::vector<HighlightPortion>::const_iterator itr =
            aPortions.begin(), itrEnd = aPortions.end(); itr != itrEnd; ++itr)
    {
        CPPUNIT_ASSERT_EQUAL(prevEnd, itr->nBegin);
        CPPUNIT_ASSERT(itr->nBegin < itr->nEnd);
        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);

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
{'fraction_non_alphanumeric': 0.12832093517534537, 'fraction_numerical': 0.009564293304994687, 'mean_word_length': 4.229166666666667, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '662195', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1280, 'n_words': 279}