forked from janl/mustache.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
259 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require('./helper'); | ||
var Context = Mustache.Context; | ||
|
||
describe('A new Mustache.Context', function () { | ||
var context; | ||
beforeEach(function () { | ||
context = new Context({ name: 'parent', message: 'hi', a: { b: 'b' } }); | ||
}); | ||
|
||
it('is able to lookup properties of its own view', function () { | ||
assert.equal(context.lookup('name'), 'parent'); | ||
}); | ||
|
||
it('is able to lookup nested properties of its own view', function () { | ||
assert.equal(context.lookup('a.b'), 'b'); | ||
}); | ||
|
||
describe('when pushed', function () { | ||
beforeEach(function () { | ||
context = context.push({ name: 'child', c: { d: 'd' } }); | ||
}); | ||
|
||
it('returns the child context', function () { | ||
assert.equal(context.view.name, 'child'); | ||
assert.equal(context.parent.view.name, 'parent'); | ||
}); | ||
|
||
it('is able to lookup properties of its own view', function () { | ||
assert.equal(context.lookup('name'), 'child'); | ||
}); | ||
|
||
it("is able to lookup properties of the parent context's view", function () { | ||
assert.equal(context.lookup('message'), 'hi'); | ||
}); | ||
|
||
it('is able to lookup nested properties of its own view', function () { | ||
assert.equal(context.lookup('c.d'), 'd'); | ||
}); | ||
|
||
it('is able to lookup nested properties of its parent view', function () { | ||
assert.equal(context.lookup('a.b'), 'b'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Mustache.Context.make', function () { | ||
it('returns the same object when given a Context', function () { | ||
var context = new Context; | ||
assert.strictEqual(Context.make(context), context); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
assert = require('assert'); | ||
Mustache = require('../mustache'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require('./helper'); | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var _files = path.join(__dirname, '_files'); | ||
|
||
function getContents(testName, ext) { | ||
return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8'); | ||
} | ||
|
||
function getView(testName) { | ||
var view = getContents(testName, 'js'); | ||
if (!view) throw new Error('Cannot find view for test "' + testName + '"'); | ||
return eval(view); | ||
} | ||
|
||
function getPartial(testName) { | ||
try { | ||
return getContents(testName, 'partial'); | ||
} catch (e) { | ||
// No big deal. Not all tests need to test partial support. | ||
} | ||
} | ||
|
||
function getTest(testName) { | ||
var test = {}; | ||
test.view = getView(testName); | ||
test.template = getContents(testName, 'mustache'); | ||
test.partial = getPartial(testName); | ||
test.expect = getContents(testName, 'txt'); | ||
return test; | ||
} | ||
|
||
// You can put the name of a specific test to run in the TEST environment | ||
// variable (e.g. TEST=backslashes vows test/render-test.js) | ||
var testToRun = process.env.TEST; | ||
|
||
var testNames; | ||
if (testToRun) { | ||
testNames = [testToRun]; | ||
} else { | ||
testNames = fs.readdirSync(_files).filter(function (file) { | ||
return (/\.js$/).test(file); | ||
}).map(function (file) { | ||
return path.basename(file).replace(/\.js$/, ''); | ||
}); | ||
} | ||
|
||
describe('Mustache.render', function () { | ||
beforeEach(function () { | ||
Mustache.clearCache(); | ||
}); | ||
|
||
testNames.forEach(function (testName) { | ||
var test = getTest(testName); | ||
|
||
it('knows how to render ' + testName, function () { | ||
var output; | ||
if (test.partial) { | ||
output = Mustache.render(test.template, test.view, { partial: test.partial }); | ||
} else { | ||
output = Mustache.render(test.template, test.view); | ||
} | ||
|
||
assert.equal(output, test.expect); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require('./helper'); | ||
var Scanner = Mustache.Scanner; | ||
|
||
describe('A new Mustache.Scanner', function () { | ||
describe('for an empty string', function () { | ||
it('is at the end', function () { | ||
var scanner = new Scanner(''); | ||
assert(scanner.eos()); | ||
}); | ||
}); | ||
|
||
describe('for a non-empty string', function () { | ||
var scanner; | ||
beforeEach(function () { | ||
scanner = new Scanner('a b c'); | ||
}); | ||
|
||
describe('scan', function () { | ||
describe('when the RegExp matches the entire string', function () { | ||
it('returns the entire string', function () { | ||
var match = scanner.scan(/a b c/); | ||
assert.equal(match, scanner.string); | ||
assert(scanner.eos()); | ||
}); | ||
}); | ||
|
||
describe('when the RegExp matches at index 0', function () { | ||
it('returns the portion of the string that matched', function () { | ||
var match = scanner.scan(/a/); | ||
assert.equal(match, 'a'); | ||
assert.equal(scanner.pos, 1); | ||
}); | ||
}); | ||
|
||
describe('when the RegExp matches at some index other than 0', function () { | ||
it('returns the empty string', function () { | ||
var match = scanner.scan(/b/); | ||
assert.equal(match, ''); | ||
assert.equal(scanner.pos, 0); | ||
}); | ||
}); | ||
|
||
describe('when the RegExp does not match', function () { | ||
it('returns the empty string', function () { | ||
var match = scanner.scan(/z/); | ||
assert.equal(match, ''); | ||
assert.equal(scanner.pos, 0); | ||
}); | ||
}); | ||
}); // scan | ||
|
||
describe('scanUntil', function () { | ||
describe('when the RegExp matches at index 0', function () { | ||
it('returns the empty string', function () { | ||
var match = scanner.scanUntil(/a/); | ||
assert.equal(match, ''); | ||
assert.equal(scanner.pos, 0); | ||
}); | ||
}); | ||
|
||
describe('when the RegExp matches at some index other than 0', function () { | ||
it('returns the string up to that index', function () { | ||
var match = scanner.scanUntil(/b/); | ||
assert.equal(match, 'a '); | ||
assert.equal(scanner.pos, 2); | ||
}); | ||
}); | ||
|
||
describe('when the RegExp does not match', function () { | ||
it('returns the entire string', function () { | ||
var match = scanner.scanUntil(/z/); | ||
assert.equal(match, scanner.string); | ||
assert(scanner.eos()); | ||
}); | ||
}); | ||
}); // scanUntil | ||
}); // for a non-empty string | ||
}); |
Oops, something went wrong.