| 1 |
load("@rules_cc//cc:defs.bzl", "cc_test") |
| 2 |
|
| 3 |
package(default_visibility = ["//visibility:public"]) |
| 4 |
|
| 5 |
# Bazel 10 no longer lets source files inherit package default_visibility; |
| 6 |
# //data references this text dictionary directly for the resources zip. |
| 7 |
exports_files( |
| 8 |
["CJK_Compatibility_Ideographs.txt"], |
| 9 |
visibility = ["//visibility:public"], |
| 10 |
) |
| 11 |
|
| 12 |
[ |
| 13 |
genrule( |
| 14 |
name = "reverse_" + txt, |
| 15 |
srcs = [txt + ".txt"], |
| 16 |
outs = [txt + "Rev.txt"], |
| 17 |
cmd = "$(location //data/scripts:reverse) " + |
| 18 |
"$(SRCS) $(OUTS)", |
| 19 |
tools = ["//data/scripts:reverse"], |
| 20 |
) |
| 21 |
for txt in [ |
| 22 |
"TWVariants", |
| 23 |
"HKVariants", |
| 24 |
"JPShinjitaiCharacters", |
| 25 |
] |
| 26 |
] |
| 27 |
|
| 28 |
genrule( |
| 29 |
name = "generate_TSCharactersExt", |
| 30 |
srcs = ["TSCharacters.txt"], |
| 31 |
outs = ["TSCharactersExt.txt"], |
| 32 |
cmd = "$(location //data/scripts:extract_tofu_risk) " + |
| 33 |
"$(SRCS) $(OUTS)", |
| 34 |
tools = ["//data/scripts:extract_tofu_risk"], |
| 35 |
) |
| 36 |
|
| 37 |
TEXT_DICTS = glob( |
| 38 |
["*.txt"], |
| 39 |
exclude = [ |
| 40 |
"CJK_Compatibility_Ideographs.txt", |
| 41 |
], |
| 42 |
) + [ |
| 43 |
"STPhrases_GeneratedFromRegionalPhrases.txt", |
| 44 |
"TSCharactersExt.txt", |
| 45 |
"TWVariantsRev.txt", |
| 46 |
"HKVariantsRev.txt", |
| 47 |
"JPShinjitaiCharactersRev.txt", |
| 48 |
] |
| 49 |
|
| 50 |
NON_BMP_TEXT_DICTS = [ |
| 51 |
txt |
| 52 |
for txt in TEXT_DICTS |
| 53 |
if txt not in [ |
| 54 |
"STCharacters.txt", |
| 55 |
"TSCharacters.txt", |
| 56 |
"TSCharactersExt.txt", |
| 57 |
] |
| 58 |
] |
| 59 |
|
| 60 |
[ |
| 61 |
genrule( |
| 62 |
name = "generate_bin_" + txt[:-4], |
| 63 |
srcs = [txt], |
| 64 |
outs = [txt.replace(".txt", ".ocd2")], |
| 65 |
cmd = "$(location //src/tools:dict_converter) " + |
| 66 |
"--input $(location " + txt + ") " + |
| 67 |
"--output $(OUTS) " + |
| 68 |
"--from text " + |
| 69 |
"--to ocd2", |
| 70 |
tools = ["//src/tools:dict_converter"], |
| 71 |
) |
| 72 |
for txt in TEXT_DICTS |
| 73 |
] |
| 74 |
|
| 75 |
genrule( |
| 76 |
name = "generate_STPhrases_GeneratedFromRegionalPhrases", |
| 77 |
srcs = [ |
| 78 |
"HKPhrases.txt", |
| 79 |
"TWPhrases.txt", |
| 80 |
"CJK_Compatibility_Ideographs.ocd2", |
| 81 |
"TSCharacters.ocd2", |
| 82 |
"TSCharactersExt.ocd2", |
| 83 |
"TSPhrases.ocd2", |
| 84 |
"//data/config:t2s.json", |
| 85 |
], |
| 86 |
outs = ["STPhrases_GeneratedFromRegionalPhrases.txt"], |
| 87 |
cmd = "$(location //data/scripts:generate_st_phrases_from_regional_phrases) " + |
| 88 |
"--input $(location HKPhrases.txt) " + |
| 89 |
"--input $(location TWPhrases.txt) " + |
| 90 |
"--output $@ " + |
| 91 |
"--opencc $(location //src/tools:command_line) " + |
| 92 |
"--config $(location //data/config:t2s.json) " + |
| 93 |
"--dict-dir $$(dirname $(location TSPhrases.ocd2))", |
| 94 |
tools = [ |
| 95 |
"//data/scripts:generate_st_phrases_from_regional_phrases", |
| 96 |
"//src/tools:command_line", |
| 97 |
], |
| 98 |
) |
| 99 |
|
| 100 |
filegroup( |
| 101 |
name = "text_dictionaries", |
| 102 |
srcs = TEXT_DICTS, |
| 103 |
) |
| 104 |
|
| 105 |
genrule( |
| 106 |
name = "generate_bin_CJK_Compatibility_Ideographs", |
| 107 |
srcs = ["CJK_Compatibility_Ideographs.txt"], |
| 108 |
outs = ["CJK_Compatibility_Ideographs.ocd2"], |
| 109 |
cmd = "$(location //src/tools:dict_converter) " + |
| 110 |
"--input $(location CJK_Compatibility_Ideographs.txt) " + |
| 111 |
"--output $(OUTS) " + |
| 112 |
"--from text " + |
| 113 |
"--to ocd2", |
| 114 |
tools = ["//src/tools:dict_converter"], |
| 115 |
) |
| 116 |
|
| 117 |
filegroup( |
| 118 |
name = "binary_dictionaries", |
| 119 |
srcs = [txt.replace(".txt", ".ocd2") for txt in TEXT_DICTS] + [ |
| 120 |
"CJK_Compatibility_Ideographs.ocd2", |
| 121 |
], |
| 122 |
) |
| 123 |
|
| 124 |
[ |
| 125 |
cc_test( |
| 126 |
name = "dictionary_" + txt[:-4] + "_test", |
| 127 |
size = "small", |
| 128 |
srcs = ["DictionaryTest.cpp"], |
| 129 |
local_defines = [ |
| 130 |
"OPENCC_DICTIONARY_TEST_FILE=\\\"" + txt + "\\\"", |
| 131 |
], |
| 132 |
data = [ |
| 133 |
txt, |
| 134 |
txt.replace(".txt", ".ocd2"), |
| 135 |
], |
| 136 |
deps = [ |
| 137 |
"//src:lexicon_lib", |
| 138 |
"//src:marisa_dict_lib", |
| 139 |
"//src:utf8_util_lib", |
| 140 |
"@bazel_tools//tools/cpp/runfiles", |
| 141 |
"@googletest//:gtest_main", |
| 142 |
], |
| 143 |
) |
| 144 |
for txt in TEXT_DICTS |
| 145 |
] |
| 146 |
|
| 147 |
cc_test( |
| 148 |
name = "dictionary_phrases_reverse_mapping_test", |
| 149 |
size = "small", |
| 150 |
srcs = ["DictionaryReverseMappingTest.cpp"], |
| 151 |
data = [ |
| 152 |
"HKPhrases.txt", |
| 153 |
"HKPhrasesRev.txt", |
| 154 |
"TWPhrases.txt", |
| 155 |
"TWPhrasesRev.txt", |
| 156 |
], |
| 157 |
deps = [ |
| 158 |
"//src:lexicon_lib", |
| 159 |
"//src:utf8_util_lib", |
| 160 |
"@bazel_tools//tools/cpp/runfiles", |
| 161 |
"@googletest//:gtest_main", |
| 162 |
], |
| 163 |
) |
| 164 |
|
| 165 |
cc_test( |
| 166 |
name = "dictionary_phrases_segmentation_test", |
| 167 |
size = "small", |
| 168 |
srcs = ["DictionaryPhraseSegmentationTest.cpp"], |
| 169 |
data = [ |
| 170 |
"HKPhrases.txt", |
| 171 |
"STPhrases.txt", |
| 172 |
"STPhrases_GeneratedFromRegionalPhrases.txt", |
| 173 |
"TWPhrases.txt", |
| 174 |
], |
| 175 |
deps = [ |
| 176 |
"//src:lexicon_lib", |
| 177 |
"//src:utf8_util_lib", |
| 178 |
"@bazel_tools//tools/cpp/runfiles", |
| 179 |
"@googletest//:gtest_main", |
| 180 |
], |
| 181 |
) |
| 182 |
|
| 183 |
cc_test( |
| 184 |
name = "dictionary_phrase_character_dependency_test", |
| 185 |
size = "small", |
| 186 |
srcs = ["DictionaryPhraseCharacterDependencyTest.cpp"], |
| 187 |
data = [ |
| 188 |
"HKVariantsPhrases.txt", |
| 189 |
"HKVariantsRev.txt", |
| 190 |
"HKVariantsRevPhrases.txt", |
| 191 |
"HKVariants.txt", |
| 192 |
"STCharacters.txt", |
| 193 |
"STPhrases.txt", |
| 194 |
"TSCharacters.txt", |
| 195 |
"TSPhrases.txt", |
| 196 |
"TWVariantsRev.txt", |
| 197 |
"TWVariantsRevPhrases.txt", |
| 198 |
"TWVariants.txt", |
| 199 |
"TWVariantsPhrases.txt", |
| 200 |
], |
| 201 |
deps = [ |
| 202 |
"//src:utf8_util_lib", |
| 203 |
"@bazel_tools//tools/cpp/runfiles", |
| 204 |
"@googletest//:gtest_main", |
| 205 |
], |
| 206 |
) |
| 207 |
|
| 208 |
cc_test( |
| 209 |
name = "dictionary_variant_rev_phrases_test", |
| 210 |
size = "small", |
| 211 |
srcs = ["DictionaryVariantRevPhrasesTest.cpp"], |
| 212 |
data = [ |
| 213 |
"HKVariants.txt", |
| 214 |
"HKVariantsRev.txt", |
| 215 |
"HKVariantsRevPhrases.txt", |
| 216 |
"STCharacters.txt", |
| 217 |
"STPhrases.txt", |
| 218 |
"TWVariants.txt", |
| 219 |
"TWVariantsRev.txt", |
| 220 |
"TWVariantsRevPhrases.txt", |
| 221 |
], |
| 222 |
deps = [ |
| 223 |
"//src:utf8_util_lib", |
| 224 |
"@bazel_tools//tools/cpp/runfiles", |
| 225 |
"@googletest//:gtest_main", |
| 226 |
], |
| 227 |
) |
| 228 |
|
| 229 |
cc_test( |
| 230 |
name = "dictionary_compatibility_ideographs_test", |
| 231 |
size = "small", |
| 232 |
srcs = ["DictionaryCompatibilityIdeographsTest.cpp"], |
| 233 |
local_defines = [ |
| 234 |
"OPENCC_COMPATIBILITY_AUDIT_FILES=\\\"" + ",".join(TEXT_DICTS) + "\\\"", |
| 235 |
], |
| 236 |
data = [ |
| 237 |
"CJK_Compatibility_Ideographs.txt", |
| 238 |
] + TEXT_DICTS, |
| 239 |
deps = [ |
| 240 |
"//src:utf8_util_lib", |
| 241 |
"@bazel_tools//tools/cpp/runfiles", |
| 242 |
"@googletest//:gtest_main", |
| 243 |
], |
| 244 |
) |
| 245 |
|
| 246 |
test_suite( |
| 247 |
name = "dictionary_test", |
| 248 |
tests = [ |
| 249 |
":dictionary_" + txt[:-4] + "_test" |
| 250 |
for txt in TEXT_DICTS |
| 251 |
] + [ |
| 252 |
":dictionary_phrases_reverse_mapping_test", |
| 253 |
":dictionary_phrases_segmentation_test", |
| 254 |
":dictionary_compatibility_ideographs_test", |
| 255 |
":dictionary_phrase_character_dependency_test", |
| 256 |
":dictionary_variant_rev_phrases_test", |
| 257 |
], |
| 258 |
) |
| 259 |
|
| 260 |
[ |
| 261 |
cc_test( |
| 262 |
name = "dictionary_non_bmp_" + txt[:-4] + "_test", |
| 263 |
size = "small", |
| 264 |
srcs = ["DictionaryNonBmpTest.cpp"], |
| 265 |
local_defines = [ |
| 266 |
"OPENCC_DICTIONARY_NON_BMP_TEST_FILE=\\\"" + txt + "\\\"", |
| 267 |
], |
| 268 |
data = [txt], |
| 269 |
deps = [ |
| 270 |
"//src:utf8_util_lib", |
| 271 |
"@bazel_tools//tools/cpp/runfiles", |
| 272 |
"@googletest//:gtest_main", |
| 273 |
], |
| 274 |
) |
| 275 |
for txt in NON_BMP_TEXT_DICTS |
| 276 |
] |
| 277 |
|
| 278 |
test_suite( |
| 279 |
name = "dictionary_non_bmp_test", |
| 280 |
tests = [ |
| 281 |
":dictionary_non_bmp_" + txt[:-4] + "_test" |
| 282 |
for txt in NON_BMP_TEXT_DICTS |
| 283 |
], |
| 284 |
) |