aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/ejs/test
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/ejs/test')
-rw-r--r--node_modules/ejs/test/ejs.js213
-rw-r--r--node_modules/ejs/test/fixtures/backslash.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/backslash.html1
-rw-r--r--node_modules/ejs/test/fixtures/comments.ejs5
-rw-r--r--node_modules/ejs/test/fixtures/comments.html4
-rw-r--r--node_modules/ejs/test/fixtures/double-quote.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/double-quote.html1
-rw-r--r--node_modules/ejs/test/fixtures/error.ejs5
-rw-r--r--node_modules/ejs/test/fixtures/error.out8
-rw-r--r--node_modules/ejs/test/fixtures/include.css.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/include.css.html3
-rw-r--r--node_modules/ejs/test/fixtures/include.ejs5
-rw-r--r--node_modules/ejs/test/fixtures/include.html9
-rw-r--r--node_modules/ejs/test/fixtures/includes/menu-item.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/includes/menu/item.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/menu.ejs11
-rw-r--r--node_modules/ejs/test/fixtures/menu.html3
-rw-r--r--node_modules/ejs/test/fixtures/messed.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/messed.html1
-rw-r--r--node_modules/ejs/test/fixtures/newlines.ejs5
-rw-r--r--node_modules/ejs/test/fixtures/newlines.html9
-rw-r--r--node_modules/ejs/test/fixtures/no.newlines.ejs5
-rw-r--r--node_modules/ejs/test/fixtures/no.newlines.html5
-rw-r--r--node_modules/ejs/test/fixtures/para.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/pet.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/single-quote.ejs1
-rw-r--r--node_modules/ejs/test/fixtures/single-quote.html1
-rw-r--r--node_modules/ejs/test/fixtures/style.css3
-rw-r--r--node_modules/ejs/test/fixtures/user.ejs1
29 files changed, 307 insertions, 0 deletions
diff --git a/node_modules/ejs/test/ejs.js b/node_modules/ejs/test/ejs.js
new file mode 100644
index 0000000..6e8bc5c
--- /dev/null
+++ b/node_modules/ejs/test/ejs.js
@@ -0,0 +1,213 @@
+/**
+ * Module dependencies.
+ */
+
+var ejs = require('..')
+ , fs = require('fs')
+ , read = fs.readFileSync
+ , assert = require('assert');
+
+/**
+ * Load fixture `name`.
+ */
+
+function fixture(name) {
+ return read('test/fixtures/' + name, 'utf8');
+}
+
+/**
+ * User fixtures.
+ */
+
+var users = [];
+users.push({ name: 'tobi' });
+users.push({ name: 'loki' });
+users.push({ name: 'jane' });
+
+describe('ejs.compile(str, options)', function(){
+ it('should compile to a function', function(){
+ var fn = ejs.compile('<p>yay</p>');
+ fn().should.equal('<p>yay</p>');
+ })
+
+ it('should allow customizing delimiters', function(){
+ var fn = ejs.compile('<p>{= name }</p>', { open: '{', close: '}' });
+ fn({ name: 'tobi' }).should.equal('<p>tobi</p>');
+
+ var fn = ejs.compile('<p>::= name ::</p>', { open: '::', close: '::' });
+ fn({ name: 'tobi' }).should.equal('<p>tobi</p>');
+
+ var fn = ejs.compile('<p>(= name )</p>', { open: '(', close: ')' });
+ fn({ name: 'tobi' }).should.equal('<p>tobi</p>');
+ })
+
+ it('should default to using ejs.open and ejs.close', function(){
+ ejs.open = '{';
+ ejs.close = '}';
+ var fn = ejs.compile('<p>{= name }</p>');
+ fn({ name: 'tobi' }).should.equal('<p>tobi</p>');
+
+ var fn = ejs.compile('<p>|= name |</p>', { open: '|', close: '|' });
+ fn({ name: 'tobi' }).should.equal('<p>tobi</p>');
+ delete ejs.open;
+ delete ejs.close;
+ })
+
+ it('should have a working client option', function(){
+ var fn = ejs.compile('<p><%= foo %></p>', { client: true });
+ var str = fn.toString();
+ eval('var preFn = ' + str);
+ preFn({ foo: 'bar' }).should.equal('<p>bar</p>');
+ })
+})
+
+describe('ejs.render(str, options)', function(){
+ it('should render the template', function(){
+ ejs.render('<p>yay</p>')
+ .should.equal('<p>yay</p>');
+ })
+
+ it('should accept locals', function(){
+ ejs.render('<p><%= name %></p>', { name: 'tobi' })
+ .should.equal('<p>tobi</p>');
+ })
+})
+
+describe('ejs.renderFile(path, options, fn)', function(){
+ it('should render a file', function(done){
+ ejs.renderFile('test/fixtures/para.ejs', function(err, html){
+ if (err) return done(err);
+ html.should.equal('<p>hey</p>');
+ done();
+ });
+ })
+
+ it('should accept locals', function(done){
+ var options = { name: 'tj', open: '{', close: '}' };
+ ejs.renderFile('test/fixtures/user.ejs', options, function(err, html){
+ if (err) return done(err);
+ html.should.equal('<h1>tj</h1>');
+ done();
+ });
+ })
+})
+
+describe('<%=', function(){
+ it('should escape', function(){
+ ejs.render('<%= name %>', { name: '<script>' })
+ .should.equal('&lt;script&gt;');
+ })
+})
+
+describe('<%-', function(){
+ it('should not escape', function(){
+ ejs.render('<%- name %>', { name: '<script>' })
+ .should.equal('<script>');
+ })
+})
+
+describe('%>', function(){
+ it('should produce newlines', function(){
+ ejs.render(fixture('newlines.ejs'), { users: users })
+ .should.equal(fixture('newlines.html'));
+ })
+})
+
+describe('-%>', function(){
+ it('should not produce newlines', function(){
+ ejs.render(fixture('no.newlines.ejs'), { users: users })
+ .should.equal(fixture('no.newlines.html'));
+ })
+})
+
+describe('single quotes', function(){
+ it('should not mess up the constructed function', function(){
+ ejs.render(fixture('single-quote.ejs'))
+ .should.equal(fixture('single-quote.html'));
+ })
+})
+
+describe('double quotes', function(){
+ it('should not mess up the constructed function', function(){
+ ejs.render(fixture('double-quote.ejs'))
+ .should.equal(fixture('double-quote.html'));
+ })
+})
+
+describe('backslashes', function(){
+ it('should escape', function(){
+ ejs.render(fixture('backslash.ejs'))
+ .should.equal(fixture('backslash.html'));
+ })
+})
+
+describe('messed up whitespace', function(){
+ it('should work', function(){
+ ejs.render(fixture('messed.ejs'), { users: users })
+ .should.equal(fixture('messed.html'));
+ })
+})
+
+describe('filters', function(){
+ it('should work', function(){
+ var items = ['foo', 'bar', 'baz'];
+ ejs.render('<%=: items | reverse | first | reverse | capitalize %>', { items: items })
+ .should.equal('Zab');
+ })
+
+ it('should accept arguments', function(){
+ ejs.render('<%=: users | map:"name" | join:", " %>', { users: users })
+ .should.equal('tobi, loki, jane');
+ })
+})
+
+describe('exceptions', function(){
+ it('should produce useful stack traces', function(done){
+ try {
+ ejs.render(fixture('error.ejs'), { filename: 'error.ejs' });
+ } catch (err) {
+ err.path.should.equal('error.ejs');
+ err.stack.split('\n').slice(0, 8).join('\n').should.equal(fixture('error.out'));
+ done();
+ }
+ })
+
+ it('should not include __stack if compileDebug is false', function() {
+ try {
+ ejs.render(fixture('error.ejs'), {
+ filename: 'error.ejs',
+ compileDebug: false
+ });
+ } catch (err) {
+ err.should.not.have.property('path');
+ err.stack.split('\n').slice(0, 8).join('\n').should.not.equal(fixture('error.out'));
+ }
+ });
+})
+
+describe('includes', function(){
+ it('should include ejs', function(){
+ var file = 'test/fixtures/include.ejs';
+ ejs.render(fixture('include.ejs'), { filename: file, pets: users, open: '[[', close: ']]' })
+ .should.equal(fixture('include.html'));
+ })
+
+ it('should work when nested', function(){
+ var file = 'test/fixtures/menu.ejs';
+ ejs.render(fixture('menu.ejs'), { filename: file, pets: users })
+ .should.equal(fixture('menu.html'));
+ })
+
+ it('should include arbitrary files as-is', function(){
+ var file = 'test/fixtures/include.css.ejs';
+ ejs.render(fixture('include.css.ejs'), { filename: file, pets: users })
+ .should.equal(fixture('include.css.html'));
+ })
+})
+
+describe('comments', function() {
+ it('should fully render with comments removed', function() {
+ ejs.render(fixture('comments.ejs'))
+ .should.equal(fixture('comments.html'));
+ })
+})
diff --git a/node_modules/ejs/test/fixtures/backslash.ejs b/node_modules/ejs/test/fixtures/backslash.ejs
new file mode 100644
index 0000000..eeb4a48
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/backslash.ejs
@@ -0,0 +1 @@
+\foo \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/backslash.html b/node_modules/ejs/test/fixtures/backslash.html
new file mode 100644
index 0000000..eeb4a48
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/backslash.html
@@ -0,0 +1 @@
+\foo \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/comments.ejs b/node_modules/ejs/test/fixtures/comments.ejs
new file mode 100644
index 0000000..ba34b0a
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/comments.ejs
@@ -0,0 +1,5 @@
+<li><a href="foo"><% // double-slash comment %>foo</li>
+<li><a href="bar"><% /* C-style comment */ %>bar</li>
+<li><a href="baz"><% // double-slash comment with newline
+ %>baz</li>
+<li><a href="qux"><% var x = 'qux'; // double-slash comment @ end of line %><%= x %></li> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/comments.html b/node_modules/ejs/test/fixtures/comments.html
new file mode 100644
index 0000000..f728923
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/comments.html
@@ -0,0 +1,4 @@
+<li><a href="foo">foo</li>
+<li><a href="bar">bar</li>
+<li><a href="baz">baz</li>
+<li><a href="qux">qux</li> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/double-quote.ejs b/node_modules/ejs/test/fixtures/double-quote.ejs
new file mode 100644
index 0000000..3bccdcf
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/double-quote.ejs
@@ -0,0 +1 @@
+<p><%= "lo" + 'ki' %>'s "wheelchair"</p> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/double-quote.html b/node_modules/ejs/test/fixtures/double-quote.html
new file mode 100644
index 0000000..6473979
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/double-quote.html
@@ -0,0 +1 @@
+<p>loki's "wheelchair"</p> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/error.ejs b/node_modules/ejs/test/fixtures/error.ejs
new file mode 100644
index 0000000..f032730
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/error.ejs
@@ -0,0 +1,5 @@
+<ul>
+ <% if (users) { %>
+ <p>Has users</p>
+ <% } %>
+</ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/error.out b/node_modules/ejs/test/fixtures/error.out
new file mode 100644
index 0000000..a2c9108
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/error.out
@@ -0,0 +1,8 @@
+ReferenceError: error.ejs:2
+ 1| <ul>
+ >> 2| <% if (users) { %>
+ 3| <p>Has users</p>
+ 4| <% } %>
+ 5| </ul>
+
+users is not defined \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/include.css.ejs b/node_modules/ejs/test/fixtures/include.css.ejs
new file mode 100644
index 0000000..f47358b
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/include.css.ejs
@@ -0,0 +1 @@
+<style><% var value = 'bar' %><% include style.css %></style> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/include.css.html b/node_modules/ejs/test/fixtures/include.css.html
new file mode 100644
index 0000000..43343fe
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/include.css.html
@@ -0,0 +1,3 @@
+<style>body {
+ foo: 'bar';
+}</style> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/include.ejs b/node_modules/ejs/test/fixtures/include.ejs
new file mode 100644
index 0000000..8017337
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/include.ejs
@@ -0,0 +1,5 @@
+<ul>
+ [[ pets.forEach(function(pet){ ]]
+ [[ include pet ]]
+ [[ }) ]]
+</ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/include.html b/node_modules/ejs/test/fixtures/include.html
new file mode 100644
index 0000000..ca3e298
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/include.html
@@ -0,0 +1,9 @@
+<ul>
+
+ <li>tobi</li>
+
+ <li>loki</li>
+
+ <li>jane</li>
+
+</ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/includes/menu-item.ejs b/node_modules/ejs/test/fixtures/includes/menu-item.ejs
new file mode 100644
index 0000000..37cca5f
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/includes/menu-item.ejs
@@ -0,0 +1 @@
+<li><% include menu/item %></li> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/includes/menu/item.ejs b/node_modules/ejs/test/fixtures/includes/menu/item.ejs
new file mode 100644
index 0000000..8abc3fe
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/includes/menu/item.ejs
@@ -0,0 +1 @@
+<a href="/<%= url %>"><%= title %></a> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/menu.ejs b/node_modules/ejs/test/fixtures/menu.ejs
new file mode 100644
index 0000000..61fad41
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/menu.ejs
@@ -0,0 +1,11 @@
+<% var url = '/foo' -%>
+<% var title = 'Foo' -%>
+<% include includes/menu-item -%>
+
+<% var url = '/bar' -%>
+<% var title = 'Bar' -%>
+<% include includes/menu-item -%>
+
+<% var url = '/baz' -%>
+<% var title = 'Baz' -%>
+<% include includes/menu-item -%> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/menu.html b/node_modules/ejs/test/fixtures/menu.html
new file mode 100644
index 0000000..1f9e45f
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/menu.html
@@ -0,0 +1,3 @@
+<li><a href="//foo">Foo</a></li>
+<li><a href="//bar">Bar</a></li>
+<li><a href="//baz">Baz</a></li> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/messed.ejs b/node_modules/ejs/test/fixtures/messed.ejs
new file mode 100644
index 0000000..7d69033
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/messed.ejs
@@ -0,0 +1 @@
+<ul><%users.forEach(function(user){%><li><%=user.name%></li><%})%></ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/messed.html b/node_modules/ejs/test/fixtures/messed.html
new file mode 100644
index 0000000..1e49148
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/messed.html
@@ -0,0 +1 @@
+<ul><li>tobi</li><li>loki</li><li>jane</li></ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/newlines.ejs b/node_modules/ejs/test/fixtures/newlines.ejs
new file mode 100644
index 0000000..47401b2
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/newlines.ejs
@@ -0,0 +1,5 @@
+<ul>
+ <% users.forEach(function(user){ %>
+ <li><%= user.name %></li>
+ <% }) %>
+</ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/newlines.html b/node_modules/ejs/test/fixtures/newlines.html
new file mode 100644
index 0000000..ca3e298
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/newlines.html
@@ -0,0 +1,9 @@
+<ul>
+
+ <li>tobi</li>
+
+ <li>loki</li>
+
+ <li>jane</li>
+
+</ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/no.newlines.ejs b/node_modules/ejs/test/fixtures/no.newlines.ejs
new file mode 100644
index 0000000..029b461
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/no.newlines.ejs
@@ -0,0 +1,5 @@
+<ul>
+ <% users.forEach(function(user){ -%>
+ <li><%= user.name %></li>
+ <% }) -%>
+</ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/no.newlines.html b/node_modules/ejs/test/fixtures/no.newlines.html
new file mode 100644
index 0000000..6efee2c
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/no.newlines.html
@@ -0,0 +1,5 @@
+<ul>
+ <li>tobi</li>
+ <li>loki</li>
+ <li>jane</li>
+ </ul> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/para.ejs b/node_modules/ejs/test/fixtures/para.ejs
new file mode 100644
index 0000000..89da779
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/para.ejs
@@ -0,0 +1 @@
+<p>hey</p> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/pet.ejs b/node_modules/ejs/test/fixtures/pet.ejs
new file mode 100644
index 0000000..5788558
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/pet.ejs
@@ -0,0 +1 @@
+<li>[[= pet.name ]]</li> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/single-quote.ejs b/node_modules/ejs/test/fixtures/single-quote.ejs
new file mode 100644
index 0000000..1e35a95
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/single-quote.ejs
@@ -0,0 +1 @@
+<p><%= 'loki' %>'s wheelchair</p> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/single-quote.html b/node_modules/ejs/test/fixtures/single-quote.html
new file mode 100644
index 0000000..3125173
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/single-quote.html
@@ -0,0 +1 @@
+<p>loki's wheelchair</p> \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/style.css b/node_modules/ejs/test/fixtures/style.css
new file mode 100644
index 0000000..1630b8c
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/style.css
@@ -0,0 +1,3 @@
+body {
+ foo: '<%= value %>';
+} \ No newline at end of file
diff --git a/node_modules/ejs/test/fixtures/user.ejs b/node_modules/ejs/test/fixtures/user.ejs
new file mode 100644
index 0000000..b312b5d
--- /dev/null
+++ b/node_modules/ejs/test/fixtures/user.ejs
@@ -0,0 +1 @@
+<h1>{= name}</h1> \ No newline at end of file