Ignore multiline literals when detecting code language

This commit is contained in:
evgeny committed 2026-11-02 23:08:37 +01:00
1 parent 6ea6bf20a8
commit 34b71c040e
2 files changed
+8 -1

No files matched your search

@@ -37,6 +37,9 @@ private slots:
QTest::newRow("prose") << "Java and Kotlin have class and function declarations; use CSS for color." << "";
QTest::newRow("comments") << "/* fn main() { println!(\"hello\"); } */\n// std::vector<int> x;" << "";
QTest::newRow("strings") << "\"std::vector<int>\"\n'fun main() {}'" << "";
QTest::newRow("template-string") << "const code = `std::vector<int>\nfn main() {}`;" << "";
QTest::newRow("multiline-string") << "\"\"\"\nfun main() {}\n\"\"\"" << "";
QTest::newRow("incomplete-string") << "\"std::vector<int>" << "";
QTest::newRow("json") << "{\"code\": \"fn main() {}\", \"color\": \"red\"}" << "";
QTest::newRow("conflicting") << "fn test() {}\nfun main() {}" << "";
QTest::newRow("repeated-weak") << QString("const value = 1;\n").repeated(200) << "";
@@ -54,6 +57,7 @@ private slots:
QCOMPARE(error.error, QJsonParseError::NoError); QVERIFY(document.isArray());
const QDir directory = QFileInfo(manifest).absoluteDir();
struct Counts { int correct = 0, unknown = 0, wrong = 0; } full, snippets;
QElapsedTimer elapsed; elapsed.start();
for (const auto& item : document.array()) {
const auto entry = item.toObject(); const QString path = entry["file"].toString();
QFile source(directory.filePath(path)); QVERIFY2(source.open(QIODevice::ReadOnly), qPrintable(path));
@@ -80,6 +84,7 @@ private slots:
}
GUI_INFO("corpus totals: full correct=%d unknown=%d wrong=%d; snippets correct=%d unknown=%d wrong=%d",
full.correct, full.unknown, full.wrong, snippets.correct, snippets.unknown, snippets.wrong);
GUI_INFO("corpus elapsed: %lld ms including input/SHA-256/logging", (long long)elapsed.elapsed());
QVERIFY(full.correct > 0); QCOMPARE(full.wrong, 0); QCOMPARE(snippets.wrong, 0);
}
};