Permalink
Browse files

test code

  • Loading branch information...
1 parent 3297664 commit 09736d2e0b8f6c13f1b3eb4af472c09cc599a181 @leizongmin committed Mar 16, 2013
Showing with 39 additions and 4 deletions.
  1. +4 −2 index.js
  2. +1 −1 lib/opcode.js
  3. +3 −0 test/common.js
  4. +1 −1 test/filters.js
  5. +30 −0 test/module_exports.js
View
@@ -84,10 +84,12 @@ exports.run = function (astList, context, callback) {
* @param {Object} options
* @return {Function}
*/
-exports.comiple = function (tpl, options) {
+exports.compile = function (tpl, options) {
var ast = exports.parse(tpl, options);
return function (context, callback) {
- exports.run(ast, context, callback);
+ exports.run(ast, context, function (err) {
+ callback(err, context.getBuffer());
+ });
};
};
View
@@ -1,5 +1,5 @@
/**
- * define OPCODE
+ * Define OPCODE
*
* @author Lei Zongmin<leizongmin@gmail.com>
*/
View
@@ -7,6 +7,9 @@ if (/1/.test(process.env.DEBUG)) debug1 = console.log;
if (/2/.test(process.env.DEBUG)) debug2 = console.log;
+// The TinyLiquid
+exports.me = liquid;
+
/**
* Create a new Context
*
View
@@ -1,5 +1,5 @@
var assert = require('assert');
-var filters = require('../').filters;
+var filters = require('./common').me.filters;
describe('filters', function () {
View
@@ -0,0 +1,30 @@
+var assert = require('assert');
+var common = require('./common');
+var me = common.me;
+
+describe('Module exports', function () {
+
+ it('#parse & run & newContext', function (done) {
+ var ast = me.parse('value={{a}}');
+ assert.equal(Array.isArray(ast), true);
+ var c = me.newContext();
+ c.setLocals('a', 123);
+ me.run(ast, c, function (err) {
+ assert.equal(err, null);
+ assert.equal(c.clearBuffer(), 'value=123');
+ done();
+ });
+ });
+
+ it('#compile', function (done) {
+ var render = me.compile('value={{a}}');
+ var c = me.newContext();
+ c.setLocals('a', 789);
+ render(c, function (err, text) {
+ assert.equal(err, null);
+ assert.equal(text, 'value=789');
+ done();
+ });
+ });
+
+});

0 comments on commit 09736d2

Please sign in to comment.