2 * preserve <https://github.com/jonschlinkert/preserve>
4 * Copyright (c) 2014-2015, Jon Schlinkert.
5 * Licensed under the MIT License
10 var should = require('should');
11 var tokens = require('./');
13 var re = /<%=\s*[^>]+%>/g;
14 var pretty = function(str) {
15 return require('js-beautify').html(str, {
21 describe('preserve tokens', function () {
22 var testRe = /__ID.{5}__\n__ID.{5}__\n__ID.{5}__/;
23 var re = /<%=\s*[^>]+%>/g;
25 it('should (e.g. shouldn\'t, but will) mangle tokens in the given string', function () {
26 var html = pretty('<ul><li><%= name %></li></ul>');
27 html.should.equal('<ul>\n <li>\n <%=n ame %>\n </li>\n</ul>');
30 it('should preserve tokens in the given string', function () {
31 var html = tokens.after(pretty(tokens.before('<ul><li><%= name %></li></ul>', re)));
32 html.should.equal('<ul>\n <li><%= name %></li>\n</ul>');
35 describe('.before()', function () {
36 it('should replace matches with placeholder tokens:', function () {
37 tokens.before('<%= a %>\n<%= b %>\n<%= c %>', re).should.match(testRe);
41 describe('tokens.after()', function () {
42 it('should replace placeholder tokens with original values:', function () {
43 var before = tokens.before('<%= a %>\n<%= b %>\n<%= c %>', re);
44 before.should.match(testRe);
45 tokens.after(before).should.equal('<%= a %>\n<%= b %>\n<%= c %>');