load("@rules_cc//cc:defs.bzl", "cc_test") package(default_visibility = ["//visibility:public"]) # Bazel 10 no longer lets source files inherit package default_visibility; # //data references this text dictionary directly for the resources zip. exports_files( ["CJK_Compatibility_Ideographs.txt"], visibility = ["//visibility:public"], ) [ genrule( name = "reverse_" + txt, srcs = [txt + ".txt"], outs = [txt + "Rev.txt"], cmd = "$(location //data/scripts:reverse) " + "$(SRCS) $(OUTS)", tools = ["//data/scripts:reverse"], ) for txt in [ "TWVariants", "HKVariants", "JPShinjitaiCharacters", ] ] genrule( name = "generate_TSCharactersExt", srcs = ["TSCharacters.txt"], outs = ["TSCharactersExt.txt"], cmd = "$(location //data/scripts:extract_tofu_risk) " + "$(SRCS) $(OUTS)", tools = ["//data/scripts:extract_tofu_risk"], ) TEXT_DICTS = glob( ["*.txt"], exclude = [ "CJK_Compatibility_Ideographs.txt", ], ) + [ "STPhrases_GeneratedFromRegionalPhrases.txt", "TSCharactersExt.txt", "TWVariantsRev.txt", "HKVariantsRev.txt", "JPShinjitaiCharactersRev.txt", ] NON_BMP_TEXT_DICTS = [ txt for txt in TEXT_DICTS if txt not in [ "STCharacters.txt", "TSCharacters.txt", "TSCharactersExt.txt", ] ] [ genrule( name = "generate_bin_" + txt[:-4], srcs = [txt], outs = [txt.replace(".txt", ".ocd2")], cmd = "$(location //src/tools:dict_converter) " + "--input $(location " + txt + ") " + "--output $(OUTS) " + "--from text " + "--to ocd2", tools = ["//src/tools:dict_converter"], ) for txt in TEXT_DICTS ] genrule( name = "generate_STPhrases_GeneratedFromRegionalPhrases", srcs = [ "HKPhrases.txt", "TWPhrases.txt", "CJK_Compatibility_Ideographs.ocd2", "TSCharacters.ocd2", "TSCharactersExt.ocd2", "TSPhrases.ocd2", "//data/config:t2s.json", ], outs = ["STPhrases_GeneratedFromRegionalPhrases.txt"], cmd = "$(location //data/scripts:generate_st_phrases_from_regional_phrases) " + "--input $(location HKPhrases.txt) " + "--input $(location TWPhrases.txt) " + "--output $@ " + "--opencc $(location //src/tools:command_line) " + "--config $(location //data/config:t2s.json) " + "--dict-dir $$(dirname $(location TSPhrases.ocd2))", tools = [ "//data/scripts:generate_st_phrases_from_regional_phrases", "//src/tools:command_line", ], ) filegroup( name = "text_dictionaries", srcs = TEXT_DICTS, ) genrule( name = "generate_bin_CJK_Compatibility_Ideographs", srcs = ["CJK_Compatibility_Ideographs.txt"], outs = ["CJK_Compatibility_Ideographs.ocd2"], cmd = "$(location //src/tools:dict_converter) " + "--input $(location CJK_Compatibility_Ideographs.txt) " + "--output $(OUTS) " + "--from text " + "--to ocd2", tools = ["//src/tools:dict_converter"], ) filegroup( name = "binary_dictionaries", srcs = [txt.replace(".txt", ".ocd2") for txt in TEXT_DICTS] + [ "CJK_Compatibility_Ideographs.ocd2", ], ) [ cc_test( name = "dictionary_" + txt[:-4] + "_test", size = "small", srcs = ["DictionaryTest.cpp"], local_defines = [ "OPENCC_DICTIONARY_TEST_FILE=\\\"" + txt + "\\\"", ], data = [ txt, txt.replace(".txt", ".ocd2"), ], deps = [ "//src:lexicon_lib", "//src:marisa_dict_lib", "//src:utf8_util_lib", "@bazel_tools//tools/cpp/runfiles", "@googletest//:gtest_main", ], ) for txt in TEXT_DICTS ] cc_test( name = "dictionary_phrases_reverse_mapping_test", size = "small", srcs = ["DictionaryReverseMappingTest.cpp"], data = [ "HKPhrases.txt", "HKPhrasesRev.txt", "TWPhrases.txt", "TWPhrasesRev.txt", ], deps = [ "//src:lexicon_lib", "//src:utf8_util_lib", "@bazel_tools//tools/cpp/runfiles", "@googletest//:gtest_main", ], ) cc_test( name = "dictionary_phrases_segmentation_test", size = "small", srcs = ["DictionaryPhraseSegmentationTest.cpp"], data = [ "HKPhrases.txt", "STPhrases.txt", "STPhrases_GeneratedFromRegionalPhrases.txt", "TWPhrases.txt", ], deps = [ "//src:lexicon_lib", "//src:utf8_util_lib", "@bazel_tools//tools/cpp/runfiles", "@googletest//:gtest_main", ], ) cc_test( name = "dictionary_phrase_character_dependency_test", size = "small", srcs = ["DictionaryPhraseCharacterDependencyTest.cpp"], data = [ "HKVariantsPhrases.txt", "HKVariantsRev.txt", "HKVariantsRevPhrases.txt", "HKVariants.txt", "STCharacters.txt", "STPhrases.txt", "TSCharacters.txt", "TSPhrases.txt", "TWVariantsRev.txt", "TWVariantsRevPhrases.txt", "TWVariants.txt", "TWVariantsPhrases.txt", ], deps = [ "//src:utf8_util_lib", "@bazel_tools//tools/cpp/runfiles", "@googletest//:gtest_main", ], ) cc_test( name = "dictionary_variant_rev_phrases_test", size = "small", srcs = ["DictionaryVariantRevPhrasesTest.cpp"], data = [ "HKVariants.txt", "HKVariantsRev.txt", "HKVariantsRevPhrases.txt", "STCharacters.txt", "STPhrases.txt", "TWVariants.txt", "TWVariantsRev.txt", "TWVariantsRevPhrases.txt", ], deps = [ "//src:utf8_util_lib", "@bazel_tools//tools/cpp/runfiles", "@googletest//:gtest_main", ], ) cc_test( name = "dictionary_compatibility_ideographs_test", size = "small", srcs = ["DictionaryCompatibilityIdeographsTest.cpp"], local_defines = [ "OPENCC_COMPATIBILITY_AUDIT_FILES=\\\"" + ",".join(TEXT_DICTS) + "\\\"", ], data = [ "CJK_Compatibility_Ideographs.txt", ] + TEXT_DICTS, deps = [ "//src:utf8_util_lib", "@bazel_tools//tools/cpp/runfiles", "@googletest//:gtest_main", ], ) test_suite( name = "dictionary_test", tests = [ ":dictionary_" + txt[:-4] + "_test" for txt in TEXT_DICTS ] + [ ":dictionary_phrases_reverse_mapping_test", ":dictionary_phrases_segmentation_test", ":dictionary_compatibility_ideographs_test", ":dictionary_phrase_character_dependency_test", ":dictionary_variant_rev_phrases_test", ], ) [ cc_test( name = "dictionary_non_bmp_" + txt[:-4] + "_test", size = "small", srcs = ["DictionaryNonBmpTest.cpp"], local_defines = [ "OPENCC_DICTIONARY_NON_BMP_TEST_FILE=\\\"" + txt + "\\\"", ], data = [txt], deps = [ "//src:utf8_util_lib", "@bazel_tools//tools/cpp/runfiles", "@googletest//:gtest_main", ], ) for txt in NON_BMP_TEXT_DICTS ] test_suite( name = "dictionary_non_bmp_test", tests = [ ":dictionary_non_bmp_" + txt[:-4] + "_test" for txt in NON_BMP_TEXT_DICTS ], )