a zip code crypto-currency system good for red ONLY

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*!
  2. * preserve <https://github.com/jonschlinkert/preserve>
  3. *
  4. * Copyright (c) 2014-2015, Jon Schlinkert.
  5. * Licensed under the MIT License
  6. */
  7. 'use strict';
  8. var should = require('should');
  9. var tokens = require('./');
  10. var re = /<%=\s*[^>]+%>/g;
  11. var pretty = function(str) {
  12. return require('js-beautify').html(str, {
  13. indent_char: ' ',
  14. indent_size: 2,
  15. });
  16. };
  17. describe('preserve tokens', function () {
  18. var testRe = /__ID.{5}__\n__ID.{5}__\n__ID.{5}__/;
  19. var re = /<%=\s*[^>]+%>/g;
  20. it('should (e.g. shouldn\'t, but will) mangle tokens in the given string', function () {
  21. var html = pretty('<ul><li><%= name %></li></ul>');
  22. html.should.equal('<ul>\n <li>\n <%=n ame %>\n </li>\n</ul>');
  23. });
  24. it('should preserve tokens in the given string', function () {
  25. var html = tokens.after(pretty(tokens.before('<ul><li><%= name %></li></ul>', re)));
  26. html.should.equal('<ul>\n <li><%= name %></li>\n</ul>');
  27. });
  28. describe('.before()', function () {
  29. it('should replace matches with placeholder tokens:', function () {
  30. tokens.before('<%= a %>\n<%= b %>\n<%= c %>', re).should.match(testRe);
  31. });
  32. });
  33. describe('tokens.after()', function () {
  34. it('should replace placeholder tokens with original values:', function () {
  35. var before = tokens.before('<%= a %>\n<%= b %>\n<%= c %>', re);
  36. before.should.match(testRe);
  37. tokens.after(before).should.equal('<%= a %>\n<%= b %>\n<%= c %>');
  38. });
  39. });
  40. });