Skip to content

Commit

Permalink
Fixed tests for 0.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Oct 24, 2011
1 parent df3d60d commit 6151efa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ignore any vim files:
*.sw[a-z]
vim/.netrwhist
node_modules
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

SRC = $(shell find lib -name "*.js" -type f)
UGLIFY_FLAGS = --no-mangle

test:
@./support/expresso/bin/expresso -I lib test/*.test.js
@./node_modules/.bin/expresso test/*.test.js

ejs.js: $(SRC)
@node support/compile.js $^
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "TJ Holowaychuk <[email protected]>",
"keywords": ["template", "engine", "ejs"],
"devDependencies": {
"expresso" "0.9.2"
}
"expresso": "0.9.2"
},
"main": "./lib/ejs.js"
}
53 changes: 27 additions & 26 deletions test/ejs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,96 @@
* Module dependencies.
*/

var ejs = require('ejs');
var ejs = require('../')
, assert = require('assert');

module.exports = {
'test .version': function(assert){
'test .version': function(){
assert.ok(/^\d+\.\d+\.\d+$/.test(ejs.version), 'Test .version format');
},

'test html': function(assert){
'test html': function(){
assert.equal('<p>yay</p>', ejs.render('<p>yay</p>'));
},

'test buffered code': function(assert){
'test buffered code': function(){
var html = '<p>tj</p>',
str = '<p><%= name %></p>',
locals = { name: 'tj' };
assert.equal(html, ejs.render(str, { locals: locals }));
},

'test unbuffered code': function(assert){
'test unbuffered code': function(){
var html = '<p>tj</p>',
str = '<% if (name) { %><p><%= name %></p><% } %>',
locals = { name: 'tj' };
assert.equal(html, ejs.render(str, { locals: locals }));
},

'test `scope` option': function(assert){
'test `scope` option': function(){
var html = '<p>tj</p>',
str = '<p><%= this %></p>';
assert.equal(html, ejs.render(str, { scope: 'tj' }));
},

'test escaping': function(assert){
'test escaping': function(){
assert.equal('&lt;script&gt;', ejs.render('<%= "<script>" %>'));
assert.equal('<script>', ejs.render('<%- "<script>" %>'));
},

'test newlines': function(assert){
'test newlines': function(){
var html = '\n<p>tj</p>\n<p>[email protected]</p>',
str = '<% if (name) { %>\n<p><%= name %></p>\n<p><%= email %></p><% } %>',
locals = { name: 'tj', email: '[email protected]' };
assert.equal(html, ejs.render(str, { locals: locals }));
},

'test single quotes': function(assert){
'test single quotes': function(){
var html = '<p>WAHOO</p>',
str = "<p><%= up('wahoo') %></p>",
locals = { up: function(str){ return str.toUpperCase(); }};
assert.equal(html, ejs.render(str, { locals: locals }));
},

'test single quotes in the html': function(assert){
'test single quotes in the html': function(){
var html = '<p>WAHOO that\'s cool</p>',
str = '<p><%= up(\'wahoo\') %> that\'s cool</p>',
locals = { up: function(str){ return str.toUpperCase(); }};
assert.equal(html, ejs.render(str, { locals: locals }));
},

'test multiple single quotes': function(assert) {
'test multiple single quotes': function() {
var html = "<p>couldn't shouldn't can't</p>",
str = "<p>couldn't shouldn't can't</p>";
assert.equal(html, ejs.render(str));
},

'test single quotes inside tags': function(assert) {
'test single quotes inside tags': function() {
var html = '<p>string</p>',
str = "<p><%= 'string' %></p>";
assert.equal(html, ejs.render(str));
},

'test back-slashes in the document': function(assert) {
'test back-slashes in the document': function() {
var html = "<p>backslash: '\\'</p>",
str = "<p>backslash: '\\'</p>";
assert.equal(html, ejs.render(str));
},

'test double quotes': function(assert){
'test double quotes': function(){
var html = '<p>WAHOO</p>',
str = '<p><%= up("wahoo") %></p>',
locals = { up: function(str){ return str.toUpperCase(); }};
assert.equal(html, ejs.render(str, { locals: locals }));
},

'test multiple double quotes': function(assert) {
'test multiple double quotes': function() {
var html = '<p>just a "test" wahoo</p>',
str = '<p>just a "test" wahoo</p>';
assert.equal(html, ejs.render(str));
},

'test whitespace': function(assert){
'test whitespace': function(){
var html = '<p>foo</p>',
str = '<p><%="foo"%></p>';
assert.equal(html, ejs.render(str));
Expand All @@ -101,7 +102,7 @@ module.exports = {
assert.equal(html, ejs.render(str, { locals: { bar: 'foo' }}));
},

'test custom tags': function(assert){
'test custom tags': function(){
var html = '<p>foo</p>',
str = '<p>{{= "foo" }}</p>';

Expand All @@ -119,7 +120,7 @@ module.exports = {
}));
},

'test custom tags over 2 chars': function(assert){
'test custom tags over 2 chars': function(){
var html = '<p>foo</p>',
str = '<p>{{{{= "foo" }>>}</p>';

Expand All @@ -137,7 +138,7 @@ module.exports = {
}));
},

'test global custom tags': function(assert){
'test global custom tags': function(){
var html = '<p>foo</p>',
str = '<p>{{= "foo" }}</p>';
ejs.open = '{{';
Expand All @@ -147,7 +148,7 @@ module.exports = {
delete ejs.close;
},

'test iteration': function(assert){
'test iteration': function(){
var html = '<p>foo</p>',
str = '<% for (var key in items) { %>'
+ '<p><%= items[key] %></p>'
Expand All @@ -169,7 +170,7 @@ module.exports = {
}));
},

'test filter support': function(assert){
'test filter support': function(){
var html = 'Zab',
str = '<%=: items | reverse | first | reverse | capitalize %>';
assert.equal(html, ejs.render(str, {
Expand All @@ -179,7 +180,7 @@ module.exports = {
}));
},

'test filter argument support': function(assert){
'test filter argument support': function(){
var html = 'tj, guillermo',
str = '<%=: users | map:"name" | join:", " %>';
assert.equal(html, ejs.render(str, {
Expand All @@ -192,7 +193,7 @@ module.exports = {
}));
},

'test sort_by filter': function(assert){
'test sort_by filter': function(){
var html = 'tj',
str = '<%=: users | sort_by:"name" | last | get:"name" %>';
assert.equal(html, ejs.render(str, {
Expand All @@ -206,7 +207,7 @@ module.exports = {
}));
},

'test custom filters': function(assert){
'test custom filters': function(){
var html = 'Welcome Tj Holowaychuk',
str = '<%=: users | first | greeting %>';

Expand All @@ -223,7 +224,7 @@ module.exports = {
}));
},

'test useful stack traces': function(assert){
'test useful stack traces': function(){
var str = [
"A little somethin'",
"somethin'",
Expand All @@ -243,7 +244,7 @@ module.exports = {
}
},

'test useful stack traces multiline': function(assert){
'test useful stack traces multiline': function(){
var str = [
"A little somethin'",
"somethin'",
Expand Down

0 comments on commit 6151efa

Please sign in to comment.