simple-fmt-tests.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. var test = require("tap").test;
  3. var fmt = require("../");
  4. test("fmt", function(t) {
  5. t.equals(fmt("all your {0} are belong to {1}", "base", "us"),
  6. "all your base are belong to us");
  7. var obj = {
  8. toString: function() {
  9. return "yoyoma";
  10. },
  11. };
  12. t.equals(fmt("object is called {0} and is {1} ms old", obj, 1),
  13. "object is called yoyoma and is 1 ms old");
  14. t.equals(fmt("no arguments => no modifs {0} {1}"),
  15. "no arguments => no modifs {0} {1}");
  16. t.end();
  17. });
  18. test("fmt.obj", function(t) {
  19. var obj2 = {
  20. name: "yoyoma",
  21. age: 1,
  22. };
  23. t.equals(fmt.obj("object is called {name} and is {age} ms old", obj2),
  24. "object is called yoyoma and is 1 ms old");
  25. t.equals(fmt.obj("no matching properties => no modifs {0} {1} {name} {age}", {}),
  26. "no matching properties => no modifs {0} {1} {name} {age}");
  27. t.equals(fmt.obj("works for arrays too: [{2}, {1}, {0}]", ["one", "two", "three"]),
  28. "works for arrays too: [three, two, one]");
  29. t.end();
  30. });
  31. test("fmt.repeat", function(t) {
  32. t.equals(fmt.repeat("*", 3), "***");
  33. t.equals(fmt.repeat("*", 0), "");
  34. t.equals(fmt.repeat("", 3), "");
  35. t.end();
  36. });