46e0293ce75e3af40f18ad44b77bd8ee7cbac739.svn-base 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. if (!dojo._hasResource["dojox.string.tests.Builder"]) { // _hasResource checks
  2. // added by build. Do
  3. // not use _hasResource
  4. // directly in your
  5. // code.
  6. dojo._hasResource["dojox.string.tests.Builder"] = true;
  7. dojo.provide("dojox.string.tests.Builder");
  8. dojo.require("dojox.string.Builder");
  9. tests.register("dojox.string.tests.Builder", [{
  10. name : "Append",
  11. runTest : function(t) {
  12. var b = new dojox.string.Builder();
  13. b.append("foo");
  14. t.is("foo", b.toString());
  15. b.append("bar", "baz");
  16. t.is("foobarbaz", b.toString());
  17. b.append("ben").append("zoo");
  18. t.is("foobarbazbenzoo", b.toString());
  19. b.append(5);
  20. t.is("foobarbazbenzoo5", b.toString());
  21. }
  22. }, {
  23. name : "Construction",
  24. runTest : function(t) {
  25. var b = new dojox.string.Builder();
  26. t.is("", b.toString());
  27. b = new dojox.string.Builder("foo");
  28. t.is("foo", b.toString());
  29. }
  30. }, {
  31. name : "Replace",
  32. runTest : function(t) {
  33. var b = new dojox.string.Builder("foobar");
  34. t.is("foobar", b.toString());
  35. b.replace("foo", "baz");
  36. t.is("bazbar", b.toString());
  37. b.replace("baz", "ben");
  38. t.is("benbar", b.toString());
  39. b.replace("foo", "moo");
  40. t.is("benbar", b.toString());
  41. b.replace("enba", "o");
  42. t.is("bor", b.toString());
  43. b.replace("o", "a").replace("b", "f");
  44. t.is("far", b.toString());
  45. }
  46. }, {
  47. name : "Insert",
  48. runTest : function(t) {
  49. var b = new dojox.string.Builder();
  50. // insert at 0 is prepend
  51. b.insert(0, "foo");
  52. t.is("foo", b.toString());
  53. b.insert(0, "more");
  54. t.is("morefoo", b.toString());
  55. // insert positions stuff after the 4th character
  56. b.insert(4, "fun");
  57. t.is("morefunfoo", b.toString());
  58. // insert at len of string is push_back
  59. b.insert(10, "awesome");
  60. t.is("morefunfooawesome", b.toString());
  61. // insert past len of string is push_back
  62. b.insert(100, "bad");
  63. t.is("morefunfooawesomebad", b.toString());
  64. b = new dojox.string.Builder();
  65. b.insert(0, "foo").insert(3, "bar")
  66. .insert(3, "zoo");
  67. t.is("foozoobar", b.toString());
  68. }
  69. }, {
  70. name : "Remove",
  71. runTest : function(t) {
  72. var b = new dojox.string.Builder("foobarbaz");
  73. b.remove(3, 3);
  74. t.is("foobaz", b.toString());
  75. b.remove(0, 3);
  76. t.is("baz", b.toString());
  77. b.remove(2, 100);
  78. t.is("ba", b.toString());
  79. b.remove(0, 0);
  80. t.is("ba", b.toString())
  81. }
  82. }]);
  83. }