27 static bool file_exists(
const char* filename) {
29 return _access(filename, 0) == 0;
31 return access(filename, 0) == 0;
35 class TatweelTest :
public ::testing::Test {
37 void SetUp()
override {
38 static std::locale system_locale(
"");
39 std::locale::global(system_locale);
43 std::string filename = TestDataNameToPath(
"ara.wordlist");
44 if (file_exists(filename.c_str())) {
51 for (
auto it = text.
begin(); it != text.
end(); ++it) {
53 if (utf8.find(u8
"\u0640") != std::string::npos) ++num_tatweel;
56 LOG(
INFO) <<
"Num tatweels in source data=" << num_tatweel;
57 EXPECT_GT(num_tatweel, 0);
67 TEST_F(TatweelTest, UnicharsetIgnoresTatweel) {
71 EXPECT_EQ(strstr(utf8, u8
"\u0640"),
nullptr);
75 TEST_F(TatweelTest, DictIgnoresTatweel) {
79 std::string filename = TestDataNameToPath(
"ara.wordlist");
80 if (!file_exists(filename.c_str())) {
81 LOG(
INFO) <<
"Skip test because of missing " << filename;
84 EXPECT_TRUE(trie.read_and_add_word_list(
87 EXPECT_EQ(0, trie.check_for_words(filename.c_str(),
unicharset_,
false));
91 TEST_F(TatweelTest, UnicharsetLoadKeepsTatweel) {
94 std::string filename = TestDataNameToPath(
"ara.unicharset");
95 if (!file_exists(filename.c_str())) {
96 LOG(
INFO) <<
"Skip test because of missing " << filename;
103 if (strstr(utf8, u8
"\u0640") !=
nullptr) ++num_tatweel;
105 LOG(
INFO) <<
"Num tatweels in unicharset=" << num_tatweel;
106 EXPECT_EQ(num_tatweel, 4);