Str.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. #include "../ForceAssert.h"
  4. #include <Urho3D/Container/Str.h>
  5. #include <Urho3D/DebugNew.h>
  6. using namespace Urho3D;
  7. void Test_Container_Str()
  8. {
  9. {
  10. String str;
  11. assert(str.Length() == 0);
  12. assert(str.IsShort());
  13. str.Resize(9);
  14. assert(str.Length() == 9);
  15. assert(str.IsShort());
  16. str.Resize(1024);
  17. assert(str.Length() == 1024);
  18. assert(!str.IsShort());
  19. str = "0123456789";
  20. assert(str.Length() == 10);
  21. assert(!str.IsShort());
  22. str.Resize(5);
  23. assert(!str.IsShort());
  24. assert(str == "01234");
  25. str.Compact();
  26. assert(str.IsShort());
  27. assert(str == "01234");
  28. assert(str.Length() == 5);
  29. }
  30. {
  31. String str = String::Joined({"aa", "bb", "CC"}, "!");
  32. assert(str == "aa!bb!CC");
  33. assert(str.IsShort());
  34. }
  35. {
  36. String str = "bool Swap(T[]&)";
  37. str.Replace(10, 3, "Array<T>");
  38. assert(str == "bool Swap(Array<T>&)");
  39. }
  40. {
  41. const char* str = "aa bb CC";
  42. Vector<String> substrings = String::Split(str, ' ');
  43. assert(substrings.Size() == 3);
  44. assert(substrings[0] == "aa");
  45. assert(substrings[1] == "bb");
  46. assert(substrings[2] == "CC");
  47. }
  48. }