alter-tests.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. var test = require("tap").test;
  3. var alter = require("../");
  4. test("simple", function(t) {
  5. t.equal(alter("0123456789", [
  6. {start: 1, end: 3, str: "first"},
  7. {start: 5, end: 9, str: "second"},
  8. ]), "0first34second9");
  9. t.end();
  10. });
  11. test("not-sorted-order", function(t) {
  12. t.equal(alter("0123456789", [
  13. {start: 5, end: 9, str: "second"},
  14. {start: 1, end: 3, str: "first"},
  15. ]), "0first34second9");
  16. t.end();
  17. });
  18. test("insert", function(t) {
  19. t.equal(alter("0123456789", [
  20. {start: 5, end: 5, str: "xyz"},
  21. ]), "01234xyz56789");
  22. t.end();
  23. });
  24. test("delete", function(t) {
  25. t.equal(alter("0123456789", [
  26. {start: 5, end: 6, str: ""},
  27. ]), "012346789");
  28. t.end();
  29. });
  30. test("nop1", function(t) {
  31. t.equal(alter("0123456789", [
  32. ]), "0123456789");
  33. t.end();
  34. });
  35. test("nop2", function(t) {
  36. t.equal(alter("0123456789", [
  37. {start: 5, end: 5, str: ""},
  38. ]), "0123456789");
  39. t.end();
  40. });
  41. test("orderedinsert-stable", function(t) {
  42. t.equal(alter("0123456789", [
  43. {start: 5, end: 5, str: "a"},
  44. {start: 5, end: 5, str: "b"},
  45. {start: 5, end: 5, str: "c"},
  46. {start: 5, end: 6, str: "d"},
  47. ]), "01234abcd6789");
  48. t.end();
  49. });