diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-05-05 11:43:24 -0400 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-05-23 14:24:23 +0200 |
commit | bea8fc8e6a9dc71110a90affc34361e96714631f (patch) | |
tree | 43a686e82f73f71b1f05d81eb655d2afb3db36c1 /tests | |
parent | cadc4b42bacf959258f7d4b19e93d02c02b63449 (diff) | |
download | qt-creator-bea8fc8e6a9dc71110a90affc34361e96714631f.tar.gz |
Cpp{Tools,Editor}: Expect UTF-8 encoded literals
Change-Id: I9843c4163aad3fa3f1bfa33060c76328fc2dc25a
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp | 64 | ||||
-rw-r--r-- | tests/auto/cplusplus/findusages/tst_findusages.cpp | 39 |
2 files changed, 102 insertions, 1 deletions
diff --git a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp index 4f714c6775..b421373b0b 100644 --- a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp +++ b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp @@ -120,7 +120,8 @@ public: // Preprocess source Environment env; Preprocessor preprocess(0, &env); - const QByteArray preprocessedSource = preprocess.run(filePath, QLatin1String(source)); + const QByteArray preprocessedSource = preprocess.run(filePath, source); + document->setUtf8Source(preprocessedSource); QVERIFY(document->parse(parseMode)); document->check(); @@ -207,6 +208,17 @@ private slots: void test_completion_enum_inside_block_inside_function_QTCREATORBUG5456(); void test_completion_enum_inside_function_QTCREATORBUG5456(); void test_completion_using_inside_different_namespace_QTCREATORBUG7978(); + + // + // The following "non-latin1" code points are used in the next tests: + // + // U+00FC - 2 code units in UTF8, 1 in UTF16 - LATIN SMALL LETTER U WITH DIAERESIS + // U+4E8C - 3 code units in UTF8, 1 in UTF16 - CJK UNIFIED IDEOGRAPH-4E8C + // U+10302 - 4 code units in UTF8, 2 in UTF16 - OLD ITALIC LETTER KE + // + + void test_checksymbols_unicodeIdentifier1(); + void test_checksymbols_unicodeIdentifier2(); }; void tst_CheckSymbols::test_checksymbols_TypeUse() @@ -1913,5 +1925,55 @@ void tst_CheckSymbols::test_completion_using_inside_different_namespace_QTCREATO TestData::check(source, expectedUses); } +void tst_CheckSymbols::test_checksymbols_unicodeIdentifier1() +{ + const QByteArray source = + "class My\u00FC\u4E8C\U00010302Type { int \u00FC\u4E8C\U00010302Member; };\n" + "void f(My\u00FC\u4E8C\U00010302Type var\u00FC\u4E8C\U00010302)\n" + "{ var\u00FC\u4E8C\U00010302.\u00FC\u4E8C\U00010302Member = 0; }\n"; + ; + + const QList<Use> expectedUses = QList<Use>() + << Use(1, 7, 10, CppHighlightingSupport::TypeUse) + << Use(1, 24, 10, CppHighlightingSupport::FieldUse) + << Use(2, 6, 1, CppHighlightingSupport::FunctionUse) + << Use(2, 8, 10, CppHighlightingSupport::TypeUse) + << Use(2, 19, 7, CppHighlightingSupport::LocalUse) + << Use(3, 3, 7, CppHighlightingSupport::LocalUse) + << Use(3, 11, 10, CppHighlightingSupport::FieldUse) + ; + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_unicodeIdentifier2() +{ + const QByteArray source = + "class v\u00FC\u4E8C\U00010302\n" + "{\n" + "public:\n" + " v\u00FC\u4E8C\U00010302();\n" + " ~v\u00FC\u4E8C\U00010302();\n" + "};\n" + "\n" + "v\u00FC\u4E8C\U00010302::v\u00FC\u4E8C\U00010302() {}\n" + "v\u00FC\u4E8C\U00010302::~v\u00FC\u4E8C\U00010302() {}\n" + ; + + const QList<Use> expectedUses = QList<Use>() + << Use(1, 7, 5, CppHighlightingSupport::TypeUse) + << Use(4, 5, 5, CppHighlightingSupport::TypeUse) + << Use(5, 6, 5, CppHighlightingSupport::TypeUse) + << Use(5, 6, 5, CppHighlightingSupport::TypeUse) + << Use(8, 1, 5, CppHighlightingSupport::TypeUse) + << Use(8, 8, 5, CppHighlightingSupport::FunctionUse) + << Use(9, 1, 5, CppHighlightingSupport::TypeUse) + << Use(9, 1, 5, CppHighlightingSupport::TypeUse) + << Use(9, 9, 5, CppHighlightingSupport::TypeUse) + ; + + TestData::check(source, expectedUses); +} + QTEST_APPLESS_MAIN(tst_CheckSymbols) #include "tst_checksymbols.moc" diff --git a/tests/auto/cplusplus/findusages/tst_findusages.cpp b/tests/auto/cplusplus/findusages/tst_findusages.cpp index a19351d480..9c55679e09 100644 --- a/tests/auto/cplusplus/findusages/tst_findusages.cpp +++ b/tests/auto/cplusplus/findusages/tst_findusages.cpp @@ -111,6 +111,8 @@ private Q_SLOTS: void templatedFunction_QTCREATORBUG9749(); void usingInDifferentNamespace_QTCREATORBUG7978(); + + void unicodeIdentifier(); }; void tst_FindUsages::dump(const QList<Usage> &usages) const @@ -951,5 +953,42 @@ void tst_FindUsages::usingInDifferentNamespace_QTCREATORBUG7978() QCOMPARE(findUsages.usages().size(), 3); } +void tst_FindUsages::unicodeIdentifier() +{ + // + // The following "non-latin1" code points are used: + // + // U+00FC - 2 code units in UTF8, 1 in UTF16 - LATIN SMALL LETTER U WITH DIAERESIS + // U+4E8C - 3 code units in UTF8, 1 in UTF16 - CJK UNIFIED IDEOGRAPH-4E8C + // U+10302 - 4 code units in UTF8, 2 in UTF16 - OLD ITALIC LETTER KE + // + + const QByteArray src = "\n" + "int var\u00FC\u4E8C\U00010302;\n" + "void f() { var\u00FC\u4E8C\U00010302 = 1; }\n"; + ; + + Document::Ptr doc = Document::create("u"); + doc->setUtf8Source(src); + doc->parse(); + doc->check(); + + QVERIFY(doc->diagnosticMessages().isEmpty()); + QCOMPARE(doc->globalSymbolCount(), 2U); + + Snapshot snapshot; + snapshot.insert(doc); + + Declaration *declaration = doc->globalSymbolAt(0)->asDeclaration(); + QVERIFY(declaration); + + FindUsages findUsages(src, doc, snapshot); + findUsages(declaration); + const QList<Usage> usages = findUsages.usages(); + QCOMPARE(usages.size(), 2); + QCOMPARE(usages.at(0).len, 7); + QCOMPARE(usages.at(1).len, 7); +} + QTEST_APPLESS_MAIN(tst_FindUsages) #include "tst_findusages.moc" |