Initial commit
[yaffs-website] / node_modules / preserve / test.js
1 /*!
2  * preserve <https://github.com/jonschlinkert/preserve>
3  *
4  * Copyright (c) 2014-2015, Jon Schlinkert.
5  * Licensed under the MIT License
6  */
7
8 'use strict';
9
10 var should = require('should');
11 var tokens = require('./');
12
13 var re = /<%=\s*[^>]+%>/g;
14 var pretty = function(str) {
15   return require('js-beautify').html(str, {
16     indent_char: ' ',
17     indent_size: 2,
18   });
19 };
20
21 describe('preserve tokens', function () {
22   var testRe = /__ID.{5}__\n__ID.{5}__\n__ID.{5}__/;
23   var re = /<%=\s*[^>]+%>/g;
24
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>');
28   });
29
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>');
33   });
34
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);
38     });
39   });
40
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 %>');
46     });
47   });
48 });