Skip to content

Commit

Permalink
[uchardet_samples_test] show pass rate
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwillow committed Dec 21, 2024
1 parent c40baa1 commit 9d75c04
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/test/uchardet_samples_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@ TEST(Core, uchardet_sample_test) {
CoreInitOption opt;
Core core(L"temp.json", opt);

int passed = 0;
for (auto [filename, expectedEncoding] : table) {
auto [buf, len] = ReadFileToBuffer(utf8_to_wstring(filename));
auto charsetCode = DetectEncoding(core.GetUCharDet().get(), buf.get(), len);

if (charsetCode == expectedEncoding) {
SetConsoleColor(ConsoleColor::GREEN);
} else {
SetConsoleColor(ConsoleColor::RED);
passed++;
continue;
}

SetConsoleColor(ConsoleColor::RED);
std::cout << std::string(20, '=') << std::endl;
std::cout << "file: " << filename << std::endl;
std::cout << "detect: " << to_utf8(ToViewCharsetName(charsetCode)) << std::endl;
std::cout << "expected: " << to_utf8(ToViewCharsetName(expectedEncoding)) << std::endl;
std::cout << std::endl;
// EXPECT_EQ(charsetCode, expectedEncoding); // not pass now

SetConsoleColor();
// EXPECT_EQ(charsetCode, expectedEncoding); // not pass now
}
SetConsoleColor();

double rate = static_cast<double>(passed) / static_cast<double>(table.size());
std::cout << "PASSED: " << rate * 100.0 << "% \n";
}

0 comments on commit 9d75c04

Please sign in to comment.