forked from qt-creator/qt-creator
QmlJS indenter: Fix for expressions starting with numbers or strings.
Reviewed-by: Roberto Raggi
This commit is contained in:
@@ -693,6 +693,8 @@ bool CodeFormatter::tryStatement()
|
|||||||
case List:
|
case List:
|
||||||
case Property:
|
case Property:
|
||||||
case Function:
|
case Function:
|
||||||
|
case Number:
|
||||||
|
case String:
|
||||||
enter(expression);
|
enter(expression);
|
||||||
// look at the token again
|
// look at the token again
|
||||||
m_tokenIndex -= 1;
|
m_tokenIndex -= 1;
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ include($$SRCDIR/libs/utils/utils-lib.pri)
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
tst_qmlcodeformatter.cpp \
|
tst_qmlcodeformatter.cpp \
|
||||||
$$SRCDIR/plugins/qmljseditor/qmljseditorcodeformatter.cpp \
|
$$SRCDIR/plugins/qmljstools/qmljsqtstylecodeformatter.cpp \
|
||||||
$$SRCDIR/plugins/texteditor/basetextdocumentlayout.cpp
|
$$SRCDIR/plugins/texteditor/basetextdocumentlayout.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$SRCDIR/plugins/qmljseditor/qmljseditorcodeformatter.h \
|
$$SRCDIR/plugins/qmljstools/qmljseditorcodeformatter.h \
|
||||||
$$SRCDIR/plugins/texteditor/basetextdocumentlayout.h \
|
$$SRCDIR/plugins/texteditor/basetextdocumentlayout.h
|
||||||
|
|
||||||
INCLUDEPATH += $$SRCDIR/plugins $$SRCDIR/libs
|
INCLUDEPATH += $$SRCDIR/plugins $$SRCDIR/libs
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
|
|
||||||
#include <qmljseditor/qmljseditorcodeformatter.h>
|
#include <qmljstools/qmljsqtstylecodeformatter.h>
|
||||||
|
|
||||||
using namespace QmlJSEditor;
|
using namespace QmlJSTools;
|
||||||
|
|
||||||
class tst_QMLCodeFormatter: public QObject
|
class tst_QMLCodeFormatter: public QObject
|
||||||
{
|
{
|
||||||
@@ -27,6 +27,7 @@ private Q_SLOTS:
|
|||||||
void signalDeclarations();
|
void signalDeclarations();
|
||||||
void ifBinding1();
|
void ifBinding1();
|
||||||
void ifBinding2();
|
void ifBinding2();
|
||||||
|
void ifBinding3();
|
||||||
void ifStatementWithoutBraces1();
|
void ifStatementWithoutBraces1();
|
||||||
void ifStatementWithoutBraces2();
|
void ifStatementWithoutBraces2();
|
||||||
void ifStatementWithBraces1();
|
void ifStatementWithBraces1();
|
||||||
@@ -431,6 +432,36 @@ void tst_QMLCodeFormatter::ifBinding2()
|
|||||||
checkIndent(data);
|
checkIndent(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QMLCodeFormatter::ifBinding3()
|
||||||
|
{
|
||||||
|
QList<Line> data;
|
||||||
|
data << Line("A.Rectangle {")
|
||||||
|
<< Line(" foo: bar")
|
||||||
|
<< Line(" x: if (a) 1")
|
||||||
|
<< Line(" x: if (a)")
|
||||||
|
<< Line(" 1")
|
||||||
|
<< Line(" x: if (a) 1;")
|
||||||
|
<< Line(" x: if (a)")
|
||||||
|
<< Line(" 1;")
|
||||||
|
<< Line(" x: if (a) 1; else 2")
|
||||||
|
<< Line(" x: if (a) 1")
|
||||||
|
<< Line(" else 2")
|
||||||
|
<< Line(" x: if (a) 1;")
|
||||||
|
<< Line(" else 2")
|
||||||
|
<< Line(" x: if (a) 1;")
|
||||||
|
<< Line(" else")
|
||||||
|
<< Line(" 2")
|
||||||
|
<< Line(" x: if (a)")
|
||||||
|
<< Line(" 1")
|
||||||
|
<< Line(" else")
|
||||||
|
<< Line(" 2")
|
||||||
|
<< Line(" x: if (a) 1; else 2;")
|
||||||
|
<< Line(" x: 1")
|
||||||
|
<< Line("}")
|
||||||
|
;
|
||||||
|
checkIndent(data);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QMLCodeFormatter::ifStatementWithoutBraces1()
|
void tst_QMLCodeFormatter::ifStatementWithoutBraces1()
|
||||||
{
|
{
|
||||||
QList<Line> data;
|
QList<Line> data;
|
||||||
|
|||||||
Reference in New Issue
Block a user