forked from jsoverson/preprocess
-
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.
ported nodeunit tests to mocha+chai, fixes jsoverson#69
- Loading branch information
1 parent
93baace
commit 8c5c13d
Showing
34 changed files
with
1,585 additions
and
1,194 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/node_modules/ | ||
/test/tmp | ||
.idea | ||
*.iml | ||
node_modules |
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 |
---|---|---|
|
@@ -9,5 +9,7 @@ | |
"undef": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true | ||
"strict": true, | ||
"node": true, | ||
"mocha": true | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/node_modules/ | ||
/test/tmp | ||
.idea | ||
*.iml |
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,40 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'), | ||
pp = require('../lib/preprocess'); | ||
|
||
chai.should(); | ||
|
||
describe('preprocess context', function () { | ||
var input; | ||
|
||
it('default to env if not provided', function () { | ||
input = "a<!-- @echo FINGERPRINT -->c"; | ||
process.env.FINGERPRINT = '0xDEADBEEF'; | ||
|
||
pp.preprocess(input).should.equal("a0xDEADBEEFc"); | ||
}); | ||
|
||
describe('in nested cases', function () { | ||
var context = {'FOO': {'BAR': 'test'}}; | ||
|
||
it('and resolve path-s and echo content to nested attrs', function () { | ||
input = "// @echo FOO.BAR"; | ||
pp.preprocess(input, context, 'js').should.equal("test"); | ||
}); | ||
|
||
it('and maintain backwards compatibility', function () { | ||
input = "// @echo FOO"; | ||
pp.preprocess(input, context, 'js').should.equal("[object Object]"); | ||
}); | ||
|
||
it('and be able to compare nested context attrs', function () { | ||
input = "a\n" + | ||
"// @if FOO.BAR=='test' \n" + | ||
"b\n" + | ||
"// @endif \n" + | ||
"c"; | ||
pp.preprocess(input, context, 'js').should.equal("a\nb\nc"); | ||
}); | ||
}); | ||
}); |
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,97 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'), | ||
pp = require('../lib/preprocess'); | ||
|
||
chai.should(); | ||
|
||
describe('@extend directive shall be preprocessed', function () { | ||
var input; | ||
|
||
describe('in html', function () { | ||
it('and resolve and echo variables', function () { | ||
input = "a<!-- @echo FINGERPRINT -->c"; | ||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}).should.equal("a0xDEADBEEFc"); | ||
}); | ||
|
||
it('and echo strings', function () { | ||
input = "a<!-- @echo '-FOO*' -->c"; | ||
pp.preprocess(input).should.equal("a-FOO*c"); | ||
}); | ||
}); | ||
|
||
describe('in javascript', function () { | ||
it('and resolve and echo variables (block)', function () { | ||
input = "a/* @echo FINGERPRINT */c"; | ||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'js').should.equal("a0xDEADBEEFc"); | ||
}); | ||
|
||
it('and echo strings (block)', function () { | ||
input = "a/* @echo '-FOO*' */c"; | ||
pp.preprocess(input, {}, 'js').should.equal("a-FOO*c"); | ||
}); | ||
|
||
it('and resolve and echo variables (line)', function () { | ||
input = "a\n// @echo FINGERPRINT\nc"; | ||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'js').should.equal("a\n0xDEADBEEF\nc"); | ||
}); | ||
|
||
it('and echo strings (line)', function () { | ||
input = "a\n// @echo '-FOO*'\nc"; | ||
pp.preprocess(input, {}, 'js').should.equal("a\n-FOO*\nc"); | ||
}); | ||
}); | ||
|
||
describe('in plain text files', function () { | ||
it('and resolve and echo variables', function () { | ||
input = "a\n@echo FINGERPRINT\nc"; | ||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'simple').should.equal("a\n0xDEADBEEF\nc"); | ||
}); | ||
|
||
it('and echo strings', function () { | ||
input = "a\n@echo '-FOO*'\nc"; | ||
pp.preprocess(input, {}, 'simple').should.equal("a\n-FOO*\nc"); | ||
}); | ||
}); | ||
|
||
describe('in coffeescript', function () { | ||
it('and resolve and echo variables', function () { | ||
input = "a\n# @echo FINGERPRINT\nc"; | ||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'coffee').should.equal("a\n0xDEADBEEF\nc"); | ||
}); | ||
|
||
it('and resolve and echo variables (multiple hashes)', function () { | ||
input = "a\n## @echo FINGERPRINT\nc"; | ||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'coffee').should.equal("a\n0xDEADBEEF\nc"); | ||
}); | ||
|
||
it('and echo strings', function () { | ||
input = "a\n# @echo '-FOO*'\nc"; | ||
pp.preprocess(input, {}, 'coffee').should.equal("a\n-FOO*\nc"); | ||
}); | ||
}); | ||
|
||
describe('with multiple @echo directives inline in html/js', function () { | ||
var input; | ||
|
||
it('without overreaching', function () { | ||
input = "a<!-- @echo FOO -->b<!-- @echo BAR -->c"; | ||
pp.preprocess(input, {FOO: 1, BAR: 2}).should.equal("a1b2c"); | ||
}); | ||
|
||
it('without overreaching (js)', function () { | ||
input = "a/* @echo FOO */b/* @echo BAR */c"; | ||
pp.preprocess(input, {FOO: 1, BAR: 2}, 'js').should.equal("a1b2c"); | ||
}); | ||
|
||
it('without overreaching when string param contains `-` and `*` chars ', function () { | ||
input = "a<!-- @echo '-*' -->b<!-- @echo '*-' -->c"; | ||
pp.preprocess(input, {FOO: 1, BAR: 2}).should.equal("a-*b*-c"); | ||
}); | ||
|
||
it('without overreaching when string param contains `-` and `*` chars (js)', function () { | ||
input = "a/* @echo '-*' */b/* @echo '*-' */c"; | ||
pp.preprocess(input, {FOO: 1, BAR: 2}, 'js').should.equal("a-*b*-c"); | ||
}); | ||
}); | ||
}); |
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,56 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'), | ||
pp = require('../lib/preprocess'); | ||
|
||
chai.should(); | ||
|
||
describe('@exclude directive shall be preprocessed', function () { | ||
var input; | ||
|
||
describe('in html', function () { | ||
it('with default notation', function () { | ||
input = "a<!-- @exclude -->b<!-- @endexclude -->c"; | ||
pp.preprocess(input, {}).should.equal("ac"); | ||
}); | ||
|
||
it('multiple excludes in one line', function () { | ||
input = "a<!-- @exclude -->b<!-- @endexclude -->c<!-- @exclude -->d<!-- @endexclude -->e"; | ||
pp.preprocess(input, {}).should.equal("ace"); | ||
}); | ||
|
||
it('with newlines', function () { | ||
input = "a\n<!-- @exclude -->\nb\n<!-- @endexclude -->\nc"; | ||
pp.preprocess(input, {}).should.equal("a\nc"); | ||
}); | ||
}); | ||
|
||
describe('in javascript', function () { | ||
it('with line comments', function () { | ||
input = "a\n// @exclude\nb\n// @endexclude\nc"; | ||
pp.preprocess(input, {}, 'js').should.equal("a\nc"); | ||
}); | ||
|
||
it('with block comments', function () { | ||
input = "a/* @exclude */b/* @endexclude */c"; | ||
pp.preprocess(input, {}, 'js').should.equal("ac"); | ||
}); | ||
|
||
it('multiple excludes in one line', function () { | ||
input = "a\n/* @exclude */\nb\n/* @endexclude */\nc"; | ||
pp.preprocess(input, {}, 'js').should.equal("a\nc"); | ||
}); | ||
}); | ||
|
||
describe('in coffeescript', function () { | ||
it('with default notation', function () { | ||
input = "a\n# @exclude\nb\n# @endexclude\nc"; | ||
pp.preprocess(input, {}, 'coffee').should.equal("a\nc"); | ||
}); | ||
|
||
it('with multiple hashes', function () { | ||
input = "a\n## @exclude\nb\n## @endexclude\nc"; | ||
pp.preprocess(input, {}, 'coffee').should.equal("a\nc"); | ||
}); | ||
}); | ||
}); |
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,121 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'), | ||
pp = require('../lib/preprocess'); | ||
|
||
chai.should(); | ||
|
||
describe('@exec directive shall be preprocessed', function () { | ||
var input; | ||
|
||
function hello(expectedParamNumber) { | ||
(arguments.length - 1).should.equal(expectedParamNumber); | ||
|
||
var names = Array.prototype.slice.call(arguments, 1); | ||
|
||
return 'Hello ' + names.join() + '!'; | ||
} | ||
|
||
describe('in html', function () { | ||
it('and execute function with one parameter', function () { | ||
input = "a<!-- @exec hello('Chuck Norris') -->c"; | ||
pp.preprocess(input, {hello: hello.bind(null, 1)}).should.equal("aHello Chuck Norris!c"); | ||
}); | ||
|
||
it('and execute function with two parameters', function () { | ||
input = "a<!-- @exec hello(\"Chuck Norris\", 'Gandhi') -->c"; | ||
pp.preprocess(input, {hello: hello.bind(null, 2)}).should.equal("aHello Chuck Norris,Gandhi!c"); | ||
}); | ||
|
||
it('and execute function with two parameters: one string and one variable', function () { | ||
input = "a<!-- @exec hello(\"Chuck Norris\", buddy) -->c"; | ||
pp.preprocess(input, { | ||
hello: hello.bind(null, 2), | ||
buddy: 'Michael Jackson' | ||
}).should.equal("aHello Chuck Norris,Michael Jackson!c"); | ||
}); | ||
}); | ||
|
||
describe('in javascript', function () { | ||
it('and execute function with one parameter (block)', function () { | ||
input = "a/* @exec hello('Chuck Norris') */c"; | ||
pp.preprocess(input, {hello: hello.bind(null, 1)}, 'js').should.equal("aHello Chuck Norris!c"); | ||
}); | ||
|
||
it('and execute function with two parameters (block)', function () { | ||
input = "a/* @exec hello(\"Chuck Norris\", 'Gandhi') */c"; | ||
pp.preprocess(input, {hello: hello.bind(null, 2)}, 'js').should.equal("aHello Chuck Norris,Gandhi!c"); | ||
}); | ||
|
||
it('and execute function with two parameters: one string and one variable (block)', function () { | ||
input = "a/* @exec hello(\"Chuck Norris\", buddy) */c"; | ||
pp.preprocess(input, { | ||
hello: hello.bind(null, 2), | ||
buddy: 'Michael Jackson' | ||
}, 'js').should.equal("aHello Chuck Norris,Michael Jackson!c"); | ||
}); | ||
|
||
it('and execute function with one parameter (line)', function () { | ||
input = "a\n// @exec hello('Chuck Norris')\nc"; | ||
pp.preprocess(input, {hello: hello.bind(null, 1)}, 'js').should.equal("a\nHello Chuck Norris!\nc"); | ||
}); | ||
|
||
it('and execute function with two parameters (line)', function () { | ||
input = "a\n// @exec hello(\"Chuck Norris\", 'Gandhi')\nc"; | ||
pp.preprocess(input, {hello: hello.bind(null, 2)}, 'js').should.equal("a\nHello Chuck Norris,Gandhi!\nc"); | ||
}); | ||
|
||
it('and execute function with two parameters: one string and one variable (line)', function () { | ||
input = "a\n// @exec hello(\"Chuck Norris\", buddy)\nc"; | ||
pp.preprocess(input, { | ||
hello: hello.bind(null, 2), | ||
buddy: 'Michael Jackson' | ||
}, 'js').should.equal("a\nHello Chuck Norris,Michael Jackson!\nc"); | ||
}); | ||
}); | ||
|
||
describe('in plain text files', function () { | ||
it('and execute function with one parameter', function () { | ||
input = "a\n@exec hello('Chuck Norris')\nc"; | ||
pp.preprocess(input, {hello: hello.bind(null, 1)}, 'simple').should.equal("a\nHello Chuck Norris!\nc"); | ||
}); | ||
|
||
it('and execute function with two parameters', function () { | ||
input = "a\n@exec hello(\"Chuck Norris\", 'Gandhi')\nc"; | ||
pp.preprocess(input, {hello: hello.bind(null, 2)}, 'simple').should.equal("a\nHello Chuck Norris,Gandhi!\nc"); | ||
}); | ||
|
||
it('and execute function with two parameters: one string and one variable', function () { | ||
input = "a\n@exec hello(\"Chuck Norris\", buddy)\nc"; | ||
pp.preprocess(input, { | ||
hello: hello.bind(null, 2), | ||
buddy: 'Michael Jackson' | ||
}, 'simple').should.equal("a\nHello Chuck Norris,Michael Jackson!\nc"); | ||
}); | ||
}); | ||
|
||
describe('in coffeescript', function () { | ||
it('and execute function with one parameter', function () { | ||
input = "a\n# @exec hello('Chuck Norris')\nc"; | ||
pp.preprocess(input, {hello: hello.bind(null, 1)}, 'coffee').should.equal("a\nHello Chuck Norris!\nc"); | ||
}); | ||
|
||
it('and execute function with two parameters', function () { | ||
input = "a\n# @exec hello(\"Chuck Norris\", 'Gandhi')\nc"; | ||
pp.preprocess(input, {hello: hello.bind(null, 2)}, 'coffee').should.equal("a\nHello Chuck Norris,Gandhi!\nc"); | ||
}); | ||
|
||
it('and execute function with two parameters (multiple hashes)', function () { | ||
input = "a\n## @exec hello(\"Chuck Norris\", 'Gandhi')\nc"; | ||
pp.preprocess(input, {hello: hello.bind(null, 2)}, 'coffee').should.equal("a\nHello Chuck Norris,Gandhi!\nc"); | ||
}); | ||
|
||
it('and execute function with two parameters: one string and one variable', function () { | ||
input = "a\n# @exec hello(\"Chuck Norris\", buddy)\nc"; | ||
pp.preprocess(input, { | ||
hello: hello.bind(null, 2), | ||
buddy: 'Michael Jackson' | ||
}, 'coffee').should.equal("a\nHello Chuck Norris,Michael Jackson!\nc"); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.