type_ut.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "type.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/charset/wide.h>
  4. Y_UNIT_TEST_SUITE(TStringClassify) {
  5. Y_UNIT_TEST(TestIsSpace) {
  6. UNIT_ASSERT_EQUAL(IsSpace(" "), true);
  7. UNIT_ASSERT_EQUAL(IsSpace("\t\r\n"), true);
  8. UNIT_ASSERT_EQUAL(IsSpace(""), false);
  9. UNIT_ASSERT_EQUAL(IsSpace(" a"), false);
  10. }
  11. Y_UNIT_TEST(TestIsTrue) {
  12. UNIT_ASSERT(IsTrue("1"));
  13. UNIT_ASSERT(IsTrue("yes"));
  14. UNIT_ASSERT(IsTrue("YeS"));
  15. UNIT_ASSERT(IsTrue("on"));
  16. UNIT_ASSERT(IsTrue("true"));
  17. UNIT_ASSERT(IsTrue("t"));
  18. UNIT_ASSERT(IsTrue("da"));
  19. UNIT_ASSERT(!IsTrue(""));
  20. UNIT_ASSERT(!IsTrue("tr"));
  21. UNIT_ASSERT(!IsTrue("foobar"));
  22. }
  23. Y_UNIT_TEST(TestIsFalse) {
  24. UNIT_ASSERT(IsFalse("0"));
  25. UNIT_ASSERT(IsFalse("no"));
  26. UNIT_ASSERT(IsFalse("off"));
  27. UNIT_ASSERT(IsFalse("false"));
  28. UNIT_ASSERT(IsFalse("f"));
  29. UNIT_ASSERT(IsFalse("net"));
  30. UNIT_ASSERT(!IsFalse(""));
  31. UNIT_ASSERT(!IsFalse("fa"));
  32. UNIT_ASSERT(!IsFalse("foobar"));
  33. }
  34. Y_UNIT_TEST(TestIsNumber) {
  35. UNIT_ASSERT(IsNumber("0"));
  36. UNIT_ASSERT(IsNumber("12345678901234567890"));
  37. UNIT_ASSERT(!IsNumber("1234567890a"));
  38. UNIT_ASSERT(!IsNumber("12345xx67890a"));
  39. UNIT_ASSERT(!IsNumber("foobar"));
  40. UNIT_ASSERT(!IsNumber(""));
  41. UNIT_ASSERT(IsNumber(u"0"));
  42. UNIT_ASSERT(IsNumber(u"12345678901234567890"));
  43. UNIT_ASSERT(!IsNumber(u"1234567890a"));
  44. UNIT_ASSERT(!IsNumber(u"12345xx67890a"));
  45. UNIT_ASSERT(!IsNumber(u"foobar"));
  46. }
  47. Y_UNIT_TEST(TestIsHexNumber) {
  48. UNIT_ASSERT(IsHexNumber("0"));
  49. UNIT_ASSERT(IsHexNumber("aaaadddAAAAA"));
  50. UNIT_ASSERT(IsHexNumber("0123456789ABCDEFabcdef"));
  51. UNIT_ASSERT(IsHexNumber("12345678901234567890"));
  52. UNIT_ASSERT(IsHexNumber("1234567890a"));
  53. UNIT_ASSERT(!IsHexNumber("12345xx67890a"));
  54. UNIT_ASSERT(!IsHexNumber("foobar"));
  55. UNIT_ASSERT(!IsHexNumber(TString()));
  56. UNIT_ASSERT(IsHexNumber(u"0"));
  57. UNIT_ASSERT(IsHexNumber(u"aaaadddAAAAA"));
  58. UNIT_ASSERT(IsHexNumber(u"0123456789ABCDEFabcdef"));
  59. UNIT_ASSERT(IsHexNumber(u"12345678901234567890"));
  60. UNIT_ASSERT(IsHexNumber(u"1234567890a"));
  61. UNIT_ASSERT(!IsHexNumber(u"12345xx67890a"));
  62. UNIT_ASSERT(!IsHexNumber(u"foobar"));
  63. UNIT_ASSERT(!IsHexNumber(TUtf16String()));
  64. }
  65. }