summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjkobus <jaroslaw.kobus@digia.com>2013-08-13 12:57:31 +0200
committerJarek Kobus <jaroslaw.kobus@digia.com>2013-08-26 13:39:40 +0200
commite8801167aa7a0047c9c9be0942ed0b368e5b5aa4 (patch)
treeeb1dcf7998b0457518681126ddf9b49f198dd2d4 /tests
parent760aa0f8bce34e094abecdd99c77c359fb96bb67 (diff)
downloadqt-creator-e8801167aa7a0047c9c9be0942ed0b368e5b5aa4.tar.gz
Add common interface for text formats inside syntax highlighter
Change-Id: I87f64446161a57aea0896f68e4eafacef791969b Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/generichighlighter/highlighterengine/highlighterengine.pro1
-rw-r--r--tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.cpp56
-rw-r--r--tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.h5
-rw-r--r--tests/auto/generichighlighter/highlighterengine/tst_highlighterengine.cpp18
4 files changed, 64 insertions, 16 deletions
diff --git a/tests/auto/generichighlighter/highlighterengine/highlighterengine.pro b/tests/auto/generichighlighter/highlighterengine/highlighterengine.pro
index d2302a9b03..667ab9070f 100644
--- a/tests/auto/generichighlighter/highlighterengine/highlighterengine.pro
+++ b/tests/auto/generichighlighter/highlighterengine/highlighterengine.pro
@@ -8,6 +8,7 @@ SOURCES += \
tst_highlighterengine.cpp \
highlightermock.cpp \
formats.cpp \
+ syntaxhighlighter.cpp \
$$GENERICHIGHLIGHTERDIR/highlighter.cpp \
$$GENERICHIGHLIGHTERDIR/context.cpp \
$$GENERICHIGHLIGHTERDIR/dynamicrule.cpp \
diff --git a/tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.cpp b/tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.cpp
new file mode 100644
index 0000000000..5d5c6c9abd
--- /dev/null
+++ b/tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "syntaxhighlighter.h"
+#include "highlighter.h"
+#include "formats.h"
+
+using namespace TextEditor;
+using namespace Internal;
+
+QTextCharFormat SyntaxHighlighter::formatForCategory(int categoryIndex) const
+{
+ switch (categoryIndex) {
+ case Highlighter::Keyword: return Formats::instance().keywordFormat();
+ case Highlighter::DataType: return Formats::instance().dataTypeFormat();
+ case Highlighter::Decimal: return Formats::instance().decimalFormat();
+ case Highlighter::BaseN: return Formats::instance().baseNFormat();
+ case Highlighter::Float: return Formats::instance().floatFormat();
+ case Highlighter::Char: return Formats::instance().charFormat();
+ case Highlighter::String: return Formats::instance().stringFormat();
+ case Highlighter::Comment: return Formats::instance().commentFormat();
+ case Highlighter::Alert: return Formats::instance().alertFormat();
+ case Highlighter::Error: return Formats::instance().errorFormat();
+ case Highlighter::Function: return Formats::instance().functionFormat();
+ case Highlighter::RegionMarker: return Formats::instance().regionMarketFormat();
+ case Highlighter::Others: return Formats::instance().othersFormat();
+ default: return QTextCharFormat();
+ }
+}
+
diff --git a/tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.h b/tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.h
index ac22e00e1a..5caa7f9368 100644
--- a/tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.h
+++ b/tests/auto/generichighlighter/highlighterengine/syntaxhighlighter.h
@@ -35,6 +35,7 @@
// base instead of the real TextEditor::SyntaxHighlighter should not affect it.
#include <QSyntaxHighlighter>
+#include <texteditor/texteditorconstants.h>
namespace TextEditor {
@@ -47,6 +48,10 @@ public:
protected:
void applyFormatToSpaces(const QString &, const QTextCharFormat &)
{}
+ void setTextFormatCategories(const QVector<TextEditor::TextStyle> &)
+ {}
+ QTextCharFormat formatForCategory(int categoryIndex) const;
+
};
}
diff --git a/tests/auto/generichighlighter/highlighterengine/tst_highlighterengine.cpp b/tests/auto/generichighlighter/highlighterengine/tst_highlighterengine.cpp
index 9ce100a678..6d18ea18bc 100644
--- a/tests/auto/generichighlighter/highlighterengine/tst_highlighterengine.cpp
+++ b/tests/auto/generichighlighter/highlighterengine/tst_highlighterengine.cpp
@@ -57,7 +57,7 @@ class tst_HighlighterEngine : public QObject
public:
tst_HighlighterEngine();
-private slots:
+private slots:
void initTestCase();
void init();
@@ -130,20 +130,6 @@ void tst_HighlighterEngine::initTestCase()
m_highlighterMock.reset(new HighlighterMock());
m_highlighterMock->setDefaultContext(m_definition->initialContext());
m_highlighterMock->setDocument(m_text.document());
- m_highlighterMock->configureFormat(Highlighter::Keyword, Formats::instance().keywordFormat());
- m_highlighterMock->configureFormat(Highlighter::DataType, Formats::instance().dataTypeFormat());
- m_highlighterMock->configureFormat(Highlighter::Decimal, Formats::instance().decimalFormat());
- m_highlighterMock->configureFormat(Highlighter::BaseN, Formats::instance().baseNFormat());
- m_highlighterMock->configureFormat(Highlighter::Float, Formats::instance().floatFormat());
- m_highlighterMock->configureFormat(Highlighter::Char, Formats::instance().charFormat());
- m_highlighterMock->configureFormat(Highlighter::String, Formats::instance().stringFormat());
- m_highlighterMock->configureFormat(Highlighter::Comment, Formats::instance().commentFormat());
- m_highlighterMock->configureFormat(Highlighter::Alert, Formats::instance().alertFormat());
- m_highlighterMock->configureFormat(Highlighter::Error, Formats::instance().errorFormat());
- m_highlighterMock->configureFormat(Highlighter::Function, Formats::instance().functionFormat());
- m_highlighterMock->configureFormat(Highlighter::RegionMarker,
- Formats::instance().regionMarketFormat());
- m_highlighterMock->configureFormat(Highlighter::Others, Formats::instance().othersFormat());
}
void tst_HighlighterEngine::init()
@@ -605,7 +591,7 @@ void tst_HighlighterEngine::testSimpleLine_data()
HighlightSequence seqi(seqd);
seqi.add(9, 17, Formats::instance().commentFormat());
HighlightSequence seqj(seqd);
- seqj.add(9, 11, Formats::instance().commentFormat());
+ seqj.add(9, 11, Formats::instance().commentFormat());
HighlightSequence seqk(0, 3);
HighlightSequence seql(0, 3, Formats::instance().keywordFormat());
HighlightSequence seqm(0, 2);