Skip to content
Browse files

Added tests for `selectFormatter` engine function.

  • Loading branch information...
1 parent c4dfcc5 commit 9dbabd81d6b9a718a2aaae6391d9e2091cb2c499 @mindeavor mindeavor committed Feb 14, 2012
Showing with 43 additions and 0 deletions.
  1. +31 −0 test/template_engine.coffee
  2. +1 −0 test/testdata_files/template.const
  3. +11 −0 test/testdata_stubs/formatter_const.coffee
View
31 test/template_engine.coffee
@@ -6,12 +6,15 @@ defaultEngine = require('../lib/client_asset_manager/template_engines/default').
formatters =
html: require('./testdata_stubs/formatter_html').init()
+ const: require('./testdata_stubs/formatter_const').init()
+
root = __dirname
dir = 'testdata_files'
testTmpl = fs.readFileSync("#{root}/#{dir}/template.html")
testTmpl_2 = fs.readFileSync("#{root}/#{dir}/foo/template2.html")
testTmpl_3 = fs.readFileSync("#{root}/#{dir}/template.foo")
+testTmpl_4 = fs.readFileSync("#{root}/#{dir}/template.const")
describe 'wrapTemplate', ->
@@ -59,13 +62,41 @@ describe 'wrapTemplate', ->
processWithWrap(engine_2, testTmpl, null, 'template')
output.should.equal expected
+ lib.generate root, dir, ['foo/template2.html', 'template.const'], formatters, (output) ->
+ expected = processWithWrap(engine, testTmpl_2, null, 'foo-template2') +
+ processWithWrap(engine_2, 'CONST', null, 'template')
+ output.should.equal expected
+
it 'should not modify template content for unrecognized file extensions', ->
lib = EngineLib.init()
lib.generate root, dir, ['template.foo'], formatters, (output) ->
output.should.equal defaultEngine.process(testTmpl_3, null, 'template')
+ it 'should allow the use of a formatter specified by the engine', ->
+ engine = EngineStub.init 'X'
+ engine.selectFormatter = -> formatters.const
+
+ lib = EngineLib.init()
+ lib.use(init: -> engine)
+ lib.generate root, dir, ['template.html'], formatters, (output) ->
+ # The const formatter always outputs 'CONST'
+ output.should.equal processWithWrap(engine, 'CONST', null, 'template')
+
+
+ it 'should allow the engine to specify no formatting of the template file', ->
+ engine = EngineStub.init 'X'
+ engine.selectFormatter = -> false
+
+ lib = EngineLib.init()
+ lib.use(init: -> engine)
+ lib.generate root, dir, ['template.const'], formatters, (output) ->
+ # The const formatter always outputs 'CONST' In this case it should
+ # not equal 'CONST' because it should not be using any formatter.
+ output.should.equal processWithWrap(engine, testTmpl_4, null, 'template')
+
+
processWithWrap = (engine, tmpl, path, id) ->
engine.prefix() +
View
1 test/testdata_files/template.const
@@ -0,0 +1 @@
+Some more random content.
View
11 test/testdata_stubs/formatter_const.coffee
@@ -0,0 +1,11 @@
+# Plain HTML Formatter
+
+fs = require('fs')
+
+exports.init = ->
+
+ extensions: ['const']
+ assetType: 'html'
+ contentType: 'text/html'
+
+ compile: (path, options, cb) -> cb 'CONST'

0 comments on commit 9dbabd8

Please sign in to comment.
Something went wrong with that request. Please try again.