MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / TEST_F

Function TEST_F

test/CommandLineConvertTest.cpp:347–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345}
346
347TEST_F(CommandLineConvertTest, ConvertFromJson) {
348#ifdef BAZEL
349 const std::string casesPath =
350 runfiles_->Rlocation("_main/test/testcases/testcases.json");
351#else
352 const std::string casesPath = PROJECT_SOURCE_DIR "/test/testcases/testcases.json";
353#endif
354 const CasesByConfig cases = LoadCases(casesPath);
355
356 for (const auto& entry : cases) {
357 const std::string& config = entry.first;
358 const std::string inputFile = InputFile(config.c_str());
359 const std::string outputFile = OutputFile(config.c_str());
360
361 // Write inputs into a temp file (one per line).
362 {
363 std::ofstream ofs(inputFile, std::ios::binary);
364 ASSERT_TRUE(ofs.is_open()) << "Failed to open input file for writing: "
365 << inputFile;
366 for (const auto& item : entry.second) {
367 ofs << item.input << "\n";
368 }
369 }
370
371 ASSERT_EQ(0,
372 system(TestCommandWithFlags(
373 config, inputFile, outputFile,
374 "--include-tofu-risk-dictionaries")
375 .c_str()));
376
377 // Read outputs and compare line by line.
378 std::ifstream ifs(outputFile, std::ios::binary);
379 ASSERT_TRUE(ifs.is_open());
380 std::string line;
381 size_t idx = 0;
382 while (std::getline(ifs, line)) {
383 if (!line.empty() && line.back() == '\r') {
384 line.pop_back(); // normalize Windows CRLF
385 }
386 ASSERT_LT(idx, entry.second.size());
387 EXPECT_EQ(entry.second[idx].expected, line)
388 << "config=" << config << " index=" << idx;
389 idx++;
390 }
391 EXPECT_EQ(idx, entry.second.size()) << "config=" << config;
392 }
393}
394
395TEST_F(CommandLineConvertTest, SkipsTofuRiskDictionariesByDefault) {
396 const std::string inputFile = InputFile("tofu_risk_default");

Callers

nothing calls this directly

Calls 15

LoadCasesFunction · 0.85
QuotePathFunction · 0.85
removeFunction · 0.85
findMethod · 0.80
HasMemberMethod · 0.80
GetStringMethod · 0.80
statClass · 0.70
is_openMethod · 0.45
emptyMethod · 0.45
pop_backMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected