Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

85 řádky
2.3 KiB

  1. //
  2. // Lol Engine — Unit tests
  3. //
  4. // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
  5. // © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
  6. //
  7. // Lol Engine is free software. It comes without any warranty, to
  8. // the extent permitted by applicable law. You can redistribute it
  9. // and/or modify it under the terms of the Do What the Fuck You Want
  10. // to Public License, Version 2, as published by the WTFPL Task Force.
  11. // See http://www.wtfpl.net/ for more details.
  12. //
  13. #include <lol/engine-internal.h>
  14. #include <string>
  15. #include <lolunit.h>
  16. namespace lol
  17. {
  18. lolunit_declare_fixture(string_test)
  19. {
  20. lolunit_declare_test(string_format)
  21. {
  22. std::string s1 = "3a";
  23. std::string s2 = format("%d%x", 3, 10);
  24. lolunit_assert(s1 == s2);
  25. std::string s3 = "abc 3";
  26. std::string s4 = format("abc %d", 3);
  27. lolunit_assert(s3 == s4);
  28. }
  29. lolunit_declare_test(starts_ends_with)
  30. {
  31. std::string s = "lolilol";
  32. lolunit_assert(starts_with(s, "loli"));
  33. lolunit_assert(!starts_with(s, "lolo"));
  34. lolunit_assert(!starts_with(s, "lolilolilol"));
  35. lolunit_assert(ends_with(s, "ilol"));
  36. lolunit_assert(!ends_with(s, "olol"));
  37. lolunit_assert(!ends_with(s, "lolilolilol"));
  38. }
  39. lolunit_declare_test(string_split)
  40. {
  41. auto l1 = split(std::string("abc"));
  42. lolunit_assert(l1.count() == 1);
  43. lolunit_assert(l1[0] == "abc");
  44. auto l2 = split(std::string("\nabc"));
  45. lolunit_assert(l2.count() == 2);
  46. lolunit_assert(l2[0] == "");
  47. lolunit_assert(l2[1] == "abc");
  48. auto l3 = split(std::string("abc\n"));
  49. lolunit_assert(l3.count() == 2);
  50. lolunit_assert(l3[0] == "abc");
  51. lolunit_assert(l3[1] == "");
  52. auto l4 = split(std::string("\n\n"));
  53. lolunit_assert(l4.count() == 3);
  54. lolunit_assert(l4[0] == "");
  55. lolunit_assert(l4[1] == "");
  56. lolunit_assert(l4[2] == "");
  57. auto l5 = split(std::string("abc\nde\n\nf\n"));
  58. lolunit_assert(l5.count() == 5);
  59. lolunit_assert(l5[0] == "abc");
  60. lolunit_assert(l5[1] == "de");
  61. lolunit_assert(l5[2] == "");
  62. lolunit_assert(l5[3] == "f");
  63. lolunit_assert(l5[4] == "");
  64. }
  65. };
  66. } /* namespace lol */