Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved tests to mocha using should.js, also fewer tests with a couple …

…rolled up under one (colors...).

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
commit d1535a289ecf2c946715e05c5ec57f4a8b5a0b0b 1 parent 5f4bdcc
@ncb000gt authored
Showing with 92 additions and 246 deletions.
  1. +2 −1  package.json
  2. +90 −245 tests/parse.js
View
3  package.json
@@ -17,6 +17,7 @@
"url" : "http://github.com/ncb000gt/node-bbcode/issues"
},
"dependencies": {
- "nodeunit": ">=0.3.1"
+ "mocha": "1.3.2",
+ "should": "1.1.0"
}
}
View
335 tests/parse.js
@@ -1,253 +1,98 @@
-var bbcode = require('../lib/bbcode'),
- testCase = require('nodeunit').testCase;
+var bbcode = require('../lib/bbcode');
-module.exports = testCase(
- {
- 'test bold': function(assert) {
- assert.expect(1);
- bbcode.parse('[b]Bold[/b]', function(data) {
- assert.equals('<b>Bold</b>', data);
- assert.done();
- });
- },
- 'test italics': function(assert) {
- assert.expect(1);
- bbcode.parse('[i]italics[/i]', function(data) {
- assert.equals('<i>italics</i>', data);
- assert.done();
- });
- },
- 'test underline': function(assert) {
- assert.expect(1);
- bbcode.parse('[u]underline[/u]', function(data) {
- assert.equals('<u>underline</u>', data);
- assert.done();
- });
- },
- 'test samp': function(assert) {
- assert.expect(1);
- bbcode.parse('[samp]samp[/samp]', function(data) {
- assert.equals('<samp>samp</samp>', data);
- assert.done();
- });
- },
+require('should');
- 'test code': function(assert) {
- assert.expect(1);
- bbcode.parse('[code]Code[/code]', function(data) {
- assert.equals('<pre><code>Code</code></pre>', data);
- assert.done();
- });
- },
- 'test pre': function(assert) {
- assert.expect(1);
- bbcode.parse('[pre]Pre[/pre]', function(data) {
- assert.equals('<pre>Pre</pre>', data);
- assert.done();
- });
- },
+describe('bcrypt', function() {
+ describe('#parse', function() {
+ it('should parse [b] to <b>', function() {
+ bbcode.parse('[b]Bold[/b]', function(parse) {
+ parse.should.equal('<b>Bold</b>');
+ });
+ });
- // test all colors: since they are regexed
- 'test color-black': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=black]Black[/color]', function(data) {
- assert.equals('<span style="color: black">Black</span>', data);
- assert.done();
- });
- },
- 'test color-silver': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=silver]silver[/color]', function(data) {
- assert.equals('<span style="color: silver">silver</span>', data);
- assert.done();
- });
- },
- 'test color-gray': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=gray]gray[/color]', function(data) {
- assert.equals('<span style="color: gray">gray</span>', data);
- assert.done();
- });
- },
- 'test color-white': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=white]white[/color]', function(data) {
- assert.equals('<span style="color: white">white</span>', data);
- assert.done();
- });
- },
- 'test color-maroon': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=maroon]maroon[/color]', function(data) {
- assert.equals('<span style="color: maroon">maroon</span>', data);
- assert.done();
- });
- },
- 'test color-red': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=red]red[/color]', function(data) {
- assert.equals('<span style="color: red">red</span>', data);
- assert.done();
- });
- },
- 'test color-purple': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=purple]purple[/color]', function(data) {
- assert.equals('<span style="color: purple">purple</span>', data);
- assert.done();
- });
- },
- 'test color-fuchsia': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=fuchsia]fuchsia[/color]', function(data) {
- assert.equals('<span style="color: fuchsia">fuchsia</span>', data);
- assert.done();
- });
- },
- 'test color-green': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=green]Green[/color]', function(data) {
- assert.equals('<span style="color: green">Green</span>', data);
- assert.done();
- });
- },
- 'test color-lime': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=lime]lime[/color]', function(data) {
- assert.equals('<span style="color: lime">lime</span>', data);
- assert.done();
- });
- },
- 'test color-olive': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=olive]olive[/color]', function(data) {
- assert.equals('<span style="color: olive">olive</span>', data);
- assert.done();
- });
- },
- 'test color-yellow': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=yellow]yellow[/color]', function(data) {
- assert.equals('<span style="color: yellow">yellow</span>', data);
- assert.done();
- });
- },
- 'test color-navy': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=navy]navy[/color]', function(data) {
- assert.equals('<span style="color: navy">navy</span>', data);
- assert.done();
- });
- },
- 'test color-blue': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=blue]blue[/color]', function(data) {
- assert.equals('<span style="color: blue">blue</span>', data);
- assert.done();
- });
- },
- 'test color-teal': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=teal]teal[/color]', function(data) {
- assert.equals('<span style="color: teal">teal</span>', data);
- assert.done();
- });
- },
- 'test color-aqua': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=aqua]aqua[/color]', function(data) {
- assert.equals('<span style="color: aqua">aqua</span>', data);
- assert.done();
- });
- },
- 'test color-#fff': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=#fff]#fff[/color]', function(data) {
- assert.equals('<span style="color: #fff">#fff</span>', data);
- assert.done();
- });
- },
- 'test color-#ffffff': function(assert) {
- assert.expect(1);
- bbcode.parse('[color=#ffffff]#ffffff[/color]', function(data) {
- assert.equals('<span style="color: #ffffff">#ffffff</span>', data);
- assert.done();
- });
- },
+ it('should parse [i] to <i>', function() {
+ bbcode.parse('[i]italics[/i]', function(parse) {
+ parse.should.equal('<i>italics</i>');
+ });
+ });
- 'test size': function(assert) {
- assert.expect(1);
- bbcode.parse('[size=1.5]size[/size]', function(data) {
- assert.equals('<span style="font-size: 1.5em">size</span>', data);
- assert.done();
- });
- },
- 'test size-min': function(assert) {
- assert.expect(1);
- bbcode.parse('[size=0.5]min[/size]', function(data) {
- assert.equals('<span style="font-size: 0.7em">min</span>', data);
- assert.done();
- });
- },
- 'test size-max': function(assert) {
- assert.expect(1);
- bbcode.parse('[size=4]max[/size]', function(data) {
- assert.equals('<span style="font-size: 3em">max</span>', data);
- assert.done();
- });
- },
+ it('should parse [u] to <u>', function() {
+ bbcode.parse('[u]underline[/u]', function(parse) {
+ parse.should.equal('<u>underline</u>');
+ });
+ });
+
+ it('should parse [samp] to <samp>', function() {
+ bbcode.parse('[samp]samp[/samp]', function(parse) {
+ parse.should.equal('<samp>samp</samp>');
+ });
+ });
- 'test strikethrough': function(assert) {
- assert.expect(1);
- bbcode.parse('[s]strikethrough[/s]', function(data) {
- assert.equals('<span style="text-decoration: line-through">strikethrough</span>', data);
- assert.done();
- });
- },
+ it('should parse [code] to <code>', function() {
+ bbcode.parse('[code]Code[/code]', function(parse) {
+ parse.should.equal('<pre><code>Code</code></pre>');
+ });
+ });
- 'test url': function(assert) {
- assert.expect(1);
- bbcode.parse('[url=http://example.com]url[/url]', function(data) {
- assert.equals('<a href="http://example.com">url</a>', data);
- assert.done();
- });
- },
- 'test img with =': function(assert) {
- assert.expect(1);
- bbcode.parse('[img=http://example.com/img.png][/img]', function(data) {
- assert.equals('<img src="http://example.com/img.png" />', data);
- assert.done();
- });
- },
- 'test img as content': function(assert) {
- assert.expect(1);
- bbcode.parse('[img]http://example.com/img.png[/img]', function(data) {
- assert.equals('<img src="http://example.com/img.png" />', data);
- assert.done();
- });
- },
+ it('should parse [color] to <span style="color:<color>"> for all colors', function() {
+ var colors = ['black', 'silver', 'gray', 'maroon', 'white', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', '#fff', '#ffffff', '#ff34ff'];
- 'test quote': function(assert) {
- assert.expect(1);
- bbcode.parse('[q=person]quoted[/q]', function(data) {
- assert.equals('<q cite="person">quoted</q>', data);
- assert.done();
- });
- },
- 'test blockquote': function(assert) {
- assert.expect(1);
- bbcode.parse('[blockquote=person]quoted[/blockquote]', function(data) {
- assert.equals('<blockquote cite="person">quoted</blockquote>', data);
- assert.done();
- });
- },
+ for (var i = 0; i < colors.length; i++) {
+ var color = colors[i];
+ bbcode.parse('[color='+color+']'+color+'[/color]', function(parse) {
+ parse.should.equal('<span style="color: '+color+'">'+color+'</span>');
+ });
+ }
+ });
- 'test broken': function(assert) {
- assert.expect(1);
- bbcode.parse('[b]test', function(data) {
- assert.equals('<b>test</b>', data);
- assert.done();
- });
- }
- }
-);
+ it('should parse [size=#] to <span style="font-size: #em">', function() {
+ bbcode.parse('[size=1.5]size[/size]', function(parse) {
+ parse.should.equal('<span style="font-size: 1.5em">size</span>');
+ });
+ });
+
+ it('should parse [s] to <span style="text-decoration: line-through"', function() {
+ bbcode.parse('[s]strikethrough[/s]', function(parse) {
+ parse.should.equal('<span style="text-decoration: line-through">strikethrough</span>');
+ });
+ });
+
+ it('should parse [url=<url>] to <a href=<url>>', function() {
+ bbcode.parse('[url=http://example.com]url[/url]', function(parse) {
+ parse.should.equal('<a href="http://example.com">url</a>');
+ });
+ });
+
+ describe('should parse [img]', function() {
+ it('as attribute - [img=<img>] to <img src=<img>>', function() {
+ bbcode.parse('[img=http://example.com/img.png][/img]', function(parse) {
+ parse.should.equal('<img src="http://example.com/img.png" />');
+ });
+ });
+
+ it('as content - [img]<img>[/img] to <img src=<img>>', function() {
+ bbcode.parse('[img]http://example.com/img.png[/img]', function(parse) {
+ parse.should.equal('<img src="http://example.com/img.png" />');
+ });
+ });
+ });
+
+ it('should parse [q] as <q>', function() {
+ bbcode.parse('[q=person]quoted[/q]', function(parse) {
+ parse.should.equal('<q cite="person">quoted</q>');
+ });
+ });
+
+ it('should parse [blockquote] as <blockquote>', function() {
+ bbcode.parse('[blockquote=person]quoted[/blockquote]', function(parse) {
+ parse.should.equal('<blockquote cite="person">quoted</blockquote>');
+ });
+ });
+
+ it('should try to fix broken markup', function() {
+ bbcode.parse('[b]test', function(parse) {
+ parse.should.equal('<b>test</b>');
+ });
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.