Skip to content

Commit

Permalink
more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
printercu committed Jan 16, 2013
1 parent c6c0976 commit 8fe35e2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
43 changes: 43 additions & 0 deletions test/compile_spec.coffee
@@ -0,0 +1,43 @@
assert = require 'assert'
doT = require '../doT'
compile = require '../compile'
global.doT = doT
doT.autoload = doT.autoloadFail

dir = require('fs').realpathSync __dirname

describe 'compile', ->
beforeEach ->
doT.setCached {}

describe 'basic', ->
it 'should invoke callback with err if there is no file', (done) ->
compile files: ["#{dir}/tmpl/fail"], (err, data) ->
assert.notEqual err, null
done()

it 'should compile file', (done) ->
compile files: ["#{dir}/tmpl/one.tmpl"], (err, data) ->
assert.equal err, null
assert.equal 'one hi', doT.render 'one', val: 'hi'
done()

it 'should compile directory', (done) ->
compile files: ["#{dir}/tmpl/dir"], (err, data) ->
assert.equal err, null
assert.equal 'two hi', doT.render 'two', val: 'hi'
done()

it 'should use `base` parametr', (done) ->
compile files: ["#{dir}/tmpl/dir"], base: "#{dir}/tmpl", (err, data) ->
assert.equal err, null
assert.equal 'two hi', doT.render 'dir.two', val: 'hi'
done()

describe 'prefilters', ->
describe 'haml', ->
it 'should compile use haml', (done)->
compile files: ["#{dir}/tmpl/haml"], (err, data) ->
assert.equal err, null
assert.equal '<html>hi</html>', doT.render 'test', val: 'hi'
done()
14 changes: 8 additions & 6 deletions test/dot_spec.coffee
Expand Up @@ -24,15 +24,17 @@ describe "doT", ->
assert.equal "<div></div>", tmpl {}

describe 'cached', ->
doT.autoload = doT.autoloadFail
doT.addCached 'layout1', doT.compile '<html>{{@@content(it)}}</html>'
doT.addCached 'layout2', doT.compile '<xml>{{@@content(it)}}</xml>'
doT.addCached 'body1', doT.compile 'data1'
doT.addCached 'body2', doT.compile 'data2 {{@partial(it)}}'
doT.addCached 'partial', doT.compile 'partial'
include1 = '_dynamic': 'content': 'name': 'body1'
include2 = '_dynamic': 'content': 'name': 'body2'

beforeEach ->
doT.autoload = doT.autoloadFail
doT.addCached 'layout1', doT.compile '<html>{{@@content(it)}}</html>'
doT.addCached 'layout2', doT.compile '<xml>{{@@content(it)}}</xml>'
doT.addCached 'body1', doT.compile 'data1'
doT.addCached 'body2', doT.compile 'data2 {{@partial(it)}}'
doT.addCached 'partial', doT.compile 'partial'

it "should render partial", ->
assert.equal 'data2 partial', doT.render 'body2', {}

Expand Down
1 change: 1 addition & 0 deletions test/tmpl/dir/two.tmpl
@@ -0,0 +1 @@
two {{= val}}
1 change: 1 addition & 0 deletions test/tmpl/haml/test.tmpl.haml
@@ -0,0 +1 @@
%html {{= val }}
1 change: 1 addition & 0 deletions test/tmpl/one.tmpl
@@ -0,0 +1 @@
one {{= val}}

0 comments on commit 8fe35e2

Please sign in to comment.