Browse files

README updated and old test files deleted.

  • Loading branch information...
1 parent c16d4e8 commit 300d32ea451e80de6bc56b42fbe56e3414fdf137 Jairo de Morais committed Mar 13, 2012
Showing with 25 additions and 544 deletions.
  1. +25 −1 README.md
  2. +0 −3 TODO
  3. +0 −83 test/core.js
  4. +0 −318 test/examples.js
  5. +0 −35 test/server.js
  6. +0 −104 test/uutest.js
View
26 README.md
@@ -48,4 +48,28 @@ To render compiled templates in the browser:
Demo & Guide
------------
-Extensive docs and a full demo are available at <http://akdubya.github.com/dustjs>
+Extensive docs and a full demo are available at <http://akdubya.github.com/dustjs>
+
+------------
+
+How to run the unit-tests?
+
+I this project we have the distributions of dust, the client and the nodejs version.
+If you want to run the client version just open the html page called specRunner.html located on "test/client/specRunner.html".
+
+In order to run the server distribution of dust, run this command in the terminal: "node test/server/specRunner.js"
+
+pre-requisites for server version:
+----------------------------------
+* install nodejs 0.6 or greater
+* install npm
+* install jasmin test framework (npm install -g jasmine-node)
+
+
+
+
+
+
+
+
+
View
3 TODO
@@ -1,3 +0,0 @@
-- Optimize static strings
-- Improve interface to compile options (formatting, etc.)
-- Refactor compiler
View
83 test/core.js
@@ -1,83 +0,0 @@
-(function(exports){
-
-exports.coreSetup = function(suite, auto) {
- auto.forEach(function(test) {
- suite.test(test.name, function(){
- testRender(this, test.source, test.context, test.expected);
- });
- });
-
- suite.test("base context", function() {
- var base = dust.makeBase({
- sayHello: function() { return "Hello!" }
- });
- testRender(this, "{sayHello} {foo}", base.push({foo: "bar"}), "Hello! bar");
- });
-
- suite.test("valid keys", function() {
- testRender(this, "{_foo}{$bar}{baz1}", {_foo: 1, $bar: 2, baz1: 3}, "123");
- });
-
- suite.test("onLoad callback", function() {
- var unit = this;
- dust.onLoad = function(name, cb) {
- cb(null, "Loaded: " + name);
- };
- dust.render("onLoad", {}, function(err, out) {
- try {
- unit.ifError(err);
- unit.equals(out, "Loaded: onLoad");
- } catch(err) {
- unit.fail(err);
- return;
- }
- unit.pass();
- });
- });
-
- suite.test("renderSource (callback)", function() {
- var unit = this;
- dust.renderSource('Hello World', {}, function(err, out) {
- try {
- unit.ifError(err);
- unit.equals(out, "Hello World");
- } catch(err) {
- unit.fail(err);
- return;
- }
- unit.pass();
- });
- });
-
- suite.test("renderSource (stream)", function() {
- var unit = this;
- dust.renderSource('Hello World', {}).on('data', function(data) {
- try {
- unit.equals('Hello World', data);
- } catch(err) {
- unit.fail(err);
- return;
- }
- unit.pass();
- }).on('error', function(err) {
- unit.fail(err);
- });
- });
-}
-
-function testRender(unit, source, context, expected) {
- var name = unit.id;
- dust.loadSource(dust.compile(source, name));
- dust.render(name, context, function(err, output) {
- try {
- unit.ifError(err);
- unit.equals(output, expected);
- } catch(err) {
- unit.fail(err);
- return;
- }
- unit.pass();
- });
-}
-
-})(typeof exports !== "undefined" ? exports : window);
View
318 test/examples.js
@@ -1,318 +0,0 @@
-(function(exports){
-
-exports.dustExamples = [
- {
- name: "intro",
- source: "{#stream}{#delay}{.}{/delay}{/stream}",
- context: (function(){
- var d = 1;
- return {
- stream: function() {
- return "asynchronous templates for the browser and node.js".split('');
- },
- delay: function(chunk, context, bodies) {
- return chunk.map(function(chunk) {
- setTimeout(function() {
- chunk.render(bodies.block, context).end();
- }, d++ * 15);
- });
- }
- }
- })
- },
- {
- name: "plain",
- source: "Hello World!",
- context: {},
- expected: "Hello World!"
- },
- {
- name: "replace",
- source: "Hello {name}! You have {count} new messages.",
- context: { name: "Mick", count: 30 },
- expected: "Hello Mick! You have 30 new messages."
- },
- {
- name: "zero",
- source: "{#zero}{.}{/zero}",
- context: { zero: 0 },
- expected: "0"
- },
- {
- name: "array",
- source: "{#names}{title} {name}{~n}{/names}",
- context: { title: "Sir", names: [ { name: "Moe" }, { name: "Larry" }, { name: "Curly" } ] },
- expected: "Sir Moe\nSir Larry\nSir Curly\n"
- },
- {
- name: "empty_array",
- source: "{#names}{title} {name}{~n}{/names}",
- context: { title: "Sir", names: [] },
- expected: ""
- },
- {
- name: "implicit",
- source: "{#names}{.}{~n}{/names}",
- context: { names: ["Moe", "Larry", "Curly"] },
- expected: "Moe\nLarry\nCurly\n"
- },
- {
- name: "object",
- source: "{#person}{root}: {name}, {age}{/person}",
- context: { root: "Subject", person: { name: "Larry", age: 45 } },
- expected: "Subject: Larry, 45"
- },
- {
- name: "rename_key",
- source: "{#person foo=root}{foo}: {name}, {age}{/person}",
- context: { root: "Subject", person: { name: "Larry", age: 45 } },
- expected: "Subject: Larry, 45"
- },
- {
- name: "force_current",
- source: "{#person}{.root}: {name}, {age}{/person}",
- context: { root: "Subject", person: { name: "Larry", age: 45 } },
- expected: ": Larry, 45"
- },
- {
- name: "path",
- source: "{foo.bar}",
- context: { foo: {bar: "Hello!"} },
- expected: "Hello!"
- },
- {
- name: "escaped",
- source: "{safe|s}{~n}{unsafe}",
- context: { safe: "<script>alert('Hello!')</script>", unsafe: "<script>alert('Goodbye!')</script>" },
- expected: "<script>alert('Hello!')</script>\n&lt;script&gt;alert('Goodbye!')&lt;/script&gt;"
- },
- {
- name: "escape_pragma",
- source: "{%esc:s}\n {unsafe}{~n}\n {%esc:h}\n {unsafe}\n {/esc}\n{/esc}",
- context: { unsafe: "<script>alert('Goodbye!')</script>" },
- expected: "<script>alert('Goodbye!')</script>\n&lt;script&gt;alert('Goodbye!')&lt;/script&gt;"
- },
- {
- name: "else_block",
- source: "{#foo}\n" +
- " foo,{~s}\n" +
- "{:else}\n" +
- " not foo,{~s}\n" +
- "{/foo}\n" +
- "{#bar}\n" +
- " bar!\n" +
- "{:else}\n" +
- " not bar!\n" +
- "{/bar}",
- context: { foo: true, bar: false },
- expected: "foo, not bar!"
- },
- {
- name: "conditional",
- source: "{?tags}\n" +
- " <ul>{~n}\n" +
- " {#tags}\n" +
- " {~s} <li>{.}</li>{~n}\n" +
- " {/tags}\n" +
- " </ul>\n" +
- "{:else}\n" +
- " No Tags!\n" +
- "{/tags}\n" +
- "{~n}\n" +
- "{^likes}\n" +
- " No Likes!\n" +
- "{:else}\n" +
- " <ul>{~n}\n" +
- " {#likes}\n" +
- " {~s} <li>{.}</li>{~n}\n" +
- " {/likes}\n" +
- " </ul>\n" +
- "{/likes}",
- context: { tags: [], likes: ["moe", "larry", "curly", "shemp"] },
- expected: "No Tags!\n" +
- "<ul>\n" +
- " <li>moe</li>\n" +
- " <li>larry</li>\n" +
- " <li>curly</li>\n" +
- " <li>shemp</li>\n" +
- "</ul>"
- },
- {
- name: "sync_key",
- source: "Hello {type} World!",
- context: {
- type: function(chunk) {
- return "Sync";
- }
- },
- expected: "Hello Sync World!"
- },
- {
- name: "async_key",
- source: "Hello {type} World!",
- context: {
- type: function(chunk) {
- return chunk.map(function(chunk) {
- dust.nextTick(function() {
- chunk.end("Async");
- });
- });
- }
- },
- expected: "Hello Async World!"
- },
- {
- name: "sync_chunk",
- source: "Hello {type} World!",
- context: {
- type: function(chunk) {
- return chunk.write("Chunky");
- }
- },
- expected: "Hello Chunky World!"
- },
- {
- name: "async_iterator",
- source: "{#numbers}{#delay}{.}{/delay}{@sep}, {/sep}{/numbers}",
- context: {
- numbers: [3, 2, 1],
- delay: function(chunk, context, bodies) {
- return chunk.map(function(chunk) {
- setTimeout(function() {
- chunk.render(bodies.block, context).end();
- }, Math.ceil(Math.random()*10));
- });
- }
- },
- expected: "3, 2, 1"
- },
- {
- name: "filter",
- source: "{#filter}foo {bar}{/filter}",
- context: {
- filter: function(chunk, context, bodies) {
- return chunk.tap(function(data) {
- return data.toUpperCase();
- }).render(bodies.block, context).untap();
- },
-
- bar: "bar"
- },
- expected: "FOO BAR"
- },
- {
- name: "context",
- source: "{#list:projects}{name}{:else}No Projects!{/list}",
- context: {
- list: function(chunk, context, bodies) {
- var items = context.current(),
- len = items.length;
-
- if (len) {
- chunk.write("<ul>\n");
- for (var i=0; i<len; i++) {
- chunk = chunk.write("<li>")
- .render(bodies.block, context.push(items[i]))
- .write("</li>\n");
- }
- return chunk.write("</ul>");
- } else if (bodies['else']) {
- return chunk.render(bodies['else'], context);
- }
- return chunk;
- },
-
- projects: [
- {name: "Mayhem"},
- {name: "Flash"},
- {name: "Thunder"}
- ]
- },
- expected: "<ul>\n" +
- "<li>Mayhem</li>\n" +
- "<li>Flash</li>\n" +
- "<li>Thunder</li>\n" +
- "</ul>"
- },
- {
- name: "params",
- source: "{#helper foo=\"bar\"/}",
- context: {
- helper: function(chunk, context, bodies, params) {
- return chunk.write(params.foo);
- }
- },
- expected: "bar"
- },
- {
- name: "partials",
- source: '{>replace/} {>"plain"/} {>"{ref}"/}',
- context: { name: "Jim", count: 42, ref: "plain" },
- expected: "Hello Jim! You have 42 new messages. Hello World! Hello World!"
- },
- {
- name: "partial_context",
- source: "{>replace:.profile/}",
- context: { profile: { name: "Mick", count: 30 } },
- expected: "Hello Mick! You have 30 new messages."
- },
- {
- name: "base_template",
- source: "Start{~n}\n" +
- "{+title}\n" +
- " Base Title\n" +
- "{/title}\n" +
- "{~n}\n" +
- "{+main}\n" +
- " Base Content\n" +
- "{/main}\n" +
- "{~n}\n" +
- "End",
- context: {},
- expected: "Start\nBase Title\nBase Content\nEnd"
- },
- {
- name: "child_template",
- source: "{^xhr}\n" +
- " {>base_template/}\n" +
- "{:else}\n" +
- " {+main/}\n" +
- "{/xhr}\n" +
- "{<title}\n" +
- " Child Title\n" +
- "{/title}\n" +
- "{<main}\n" +
- " Child Content\n" +
- "{/main}\n",
- context: {xhr: false},
- expected: "Start\nChild Title\nChild Content\nEnd"
- },
- {
- name: "recursion",
- source: "{name}{~n}{#kids}{>recursion:./}{/kids}",
- context: {
- name: '1',
- kids: [
- {
- name: '1.1',
- kids: [
- {name: '1.1.1'}
- ]
- }
- ]
- },
- expected: "1\n1.1\n1.1.1\n"
- },
- {
- name: "comments",
- source: "{!\n" +
- " Multiline\n" +
- " {#foo}{bar}{/foo}\n" +
- "!}\n" +
- "{!before!}Hello{!after!}",
- context: {},
- expected: "Hello"
- }
-];
-
-})(typeof exports !== "undefined" ? exports : window);
View
35 test/server.js
@@ -1,35 +0,0 @@
-var uutest = require('./uutest'),
- dust = require('../lib/dust'),
- tests = require('./examples').dustExamples,
- coreSetup = require('./core').coreSetup;
-
-function dumpError(err) {
- var out = err.testName + " -> ";
- if (!err.message) {
- err.message = JSON.stringify(err.expected)
- + " " + err.operator + " " + JSON.stringify(err.actual);
- }
- return out + err.stack;
-}
-
-var suite = new uutest.Suite({
- pass: function() {
- process.stdout.write(".");
- },
- fail: function(err) {
- process.stdout.write("F");
- },
- done: function(passed, failed, elapsed) {
- process.stdout.write("\n");
- console.log(passed + " passed " + failed + " failed " + "(" + elapsed + "ms)");
- this.errors.forEach(function(err) {
- console.log(dumpError(err));
- });
- }
-});
-
-global.dust = dust;
-
-coreSetup(suite, tests.slice(1));
-
-suite.run();
View
104 test/uutest.js
@@ -1,104 +0,0 @@
-(function(uutest){
-
-function Test(id, test, timeout, callback) {
- this.id = id;
- this.test = test;
- this.callback = callback;
- this.timeout = timeout;
-}
-
-Test.prototype.run = function() {
- var self = this;
- self.timer = setTimeout(function() {
- self.fail(new Error("TimeoutError"));
- }, self.timeout);
- try {
- self.test.call(self);
- } catch(err) {
- self.fail(err);
- }
-}
-
-Test.prototype.equals = function(actual, expected, message) {
- if (actual !== expected) {
- var err = new Error();
- if (message) err.message = message;
- throw wrapAssertionError(err, actual, expected, "===");
- }
-}
-
-Test.prototype.ifError = function(err) {
- if (err) throw err;
-}
-
-Test.prototype.pass = function() {
- clearTimeout(this.timer);
- this.callback();
-}
-
-Test.prototype.fail = function(err) {
- clearTimeout(this.timer);
- this.callback(err);
-}
-
-uutest.Test = Test;
-
-function Suite(options) {
- this.options = options || {};
- this.timeout = options.timeout || 1000;
- this.tests = [];
-}
-
-Suite.prototype.test = function(name, fn) {
- var self = this;
- self.tests.push(new Test(name, fn, self.timeout, function(err) {
- if (err) {
- err.testName = name;
- self.errors.push(err);
- self.emit("fail", err);
- } else {
- self.emit("pass", name);
- }
- self.pending--;
- self.check();
- }));
-}
-
-Suite.prototype.run = function() {
- if (this.pending) return;
- var self = this, len = self.tests.length;
- self.errors = [];
- self.emit("start", self.tests);
- self.start = new Date().getTime();
- self.pending = len;
- for (var i=0; i<len; i++) {
- self.tests[i].run();
- }
-}
-
-Suite.prototype.check = function() {
- if (this.pending) return;
- var len = this.tests.length,
- passed = len - this.errors.length,
- failed = len - passed;
- this.emit("done", passed, failed, new Date().getTime() - this.start);
-}
-
-Suite.prototype.emit = function(type) {
- var event = this.options[type];
- if (event) {
- event.apply(this, Array.prototype.slice.call(arguments, 1));
- }
-}
-
-uutest.Suite = Suite;
-
-function wrapAssertionError(err, actual, expected, operator) {
- err.name = "AssertionError";
- err.actual = actual;
- err.expected = expected;
- err.operator = operator;
- return err;
-}
-
-})(typeof exports !== 'undefined' ? exports : window.uutest = {});

0 comments on commit 300d32e

Please sign in to comment.