tld_ut.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "tld.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <library/cpp/charset/doccodes.h>
  4. using namespace NTld;
  5. Y_UNIT_TEST_SUITE(TTldTest) {
  6. Y_UNIT_TEST(TestFindTld) {
  7. UNIT_ASSERT(FindTld("yandex.ru") == "ru");
  8. UNIT_ASSERT(FindTld("YandeX.Ru") == "Ru");
  9. UNIT_ASSERT(FindTld("yandex.com.tr") == "tr");
  10. UNIT_ASSERT(FindTld("com.tr") == "tr");
  11. UNIT_ASSERT(FindTld("abc.def.ghi") == "ghi");
  12. UNIT_ASSERT(FindTld("abc.def.aaaaaaaaaa") == "aaaaaaaaaa");
  13. UNIT_ASSERT(FindTld("a.b.c.d.e.f.g") == "g");
  14. UNIT_ASSERT(FindTld(".diff") == "diff");
  15. UNIT_ASSERT(FindTld(".") == "");
  16. UNIT_ASSERT(FindTld("ru") == "");
  17. UNIT_ASSERT(FindTld("") == "");
  18. }
  19. Y_UNIT_TEST(TestTLDs) {
  20. UNIT_ASSERT(IsTld("ru"));
  21. UNIT_ASSERT(IsTld("Ru"));
  22. UNIT_ASSERT(IsTld("BMW"));
  23. UNIT_ASSERT(IsTld("TiReS"));
  24. UNIT_ASSERT(IsTld("xn--p1ai"));
  25. UNIT_ASSERT(IsTld("YaHOO"));
  26. UNIT_ASSERT(!IsTld("xn"));
  27. UNIT_ASSERT(InTld("ru.ru"));
  28. UNIT_ASSERT(!InTld("ru"));
  29. UNIT_ASSERT(!InTld("ru."));
  30. UNIT_ASSERT(!InTld("ru.xn"));
  31. }
  32. Y_UNIT_TEST(TestVeryGoodTlds) {
  33. UNIT_ASSERT(IsVeryGoodTld("ru"));
  34. UNIT_ASSERT(IsVeryGoodTld("Ru"));
  35. UNIT_ASSERT(!IsVeryGoodTld("BMW"));
  36. UNIT_ASSERT(!IsVeryGoodTld("TiReS"));
  37. UNIT_ASSERT(IsVeryGoodTld("рф"));
  38. UNIT_ASSERT(!IsVeryGoodTld("РФ")); // note that uppercase non-ascii tlds cannot be found
  39. UNIT_ASSERT(IsVeryGoodTld("xn--p1ai")); // "рф"
  40. UNIT_ASSERT(!IsVeryGoodTld("xn--p1ag")); // "ру"
  41. UNIT_ASSERT(!IsVeryGoodTld("YaHOO"));
  42. UNIT_ASSERT(!IsVeryGoodTld("xn"));
  43. UNIT_ASSERT(InVeryGoodTld("ru.ru"));
  44. UNIT_ASSERT(InVeryGoodTld("яндекс.рф"));
  45. UNIT_ASSERT(InVeryGoodTld("http://xn--d1acpjx3f.xn--p1ai"));
  46. UNIT_ASSERT(!InVeryGoodTld("ru"));
  47. UNIT_ASSERT(!InVeryGoodTld("ru."));
  48. UNIT_ASSERT(!InVeryGoodTld("ru.xn"));
  49. }
  50. }