diff --git a/Gruntfile.js b/Gruntfile.js index 3782698dbe..ed99cbdea1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -13,13 +13,6 @@ * served from the /reference/ folder of the p5js * website (https://github.com/processing/p5.js-website). * - * grunt yui:dev - This will build the inline documentation but linking to - * remote JS/CSS and assets so pages look correct in local - * testing. The generated documentation is assumed - * to be served from a development web server running - * at the root of the repository. "grunt yui" should - * be run to build docs ready for production. - * * grunt test - This rebuilds the source and runs the automated tests on * both the minified and unminified code. If you need to debug * a test suite in a browser, `grunt test --keepalive` will @@ -64,6 +57,8 @@ function getYuidocOptions() { } }; + // note dev is no longer used, prod is used to build both testing and production ready docs + var o = { prod: JSON.parse(JSON.stringify(BASE_YUIDOC_OPTIONS)), dev: JSON.parse(JSON.stringify(BASE_YUIDOC_OPTIONS)) @@ -212,7 +207,7 @@ module.exports = function(grunt) { run: true, log: true, logErrors: true, - timeout: 5000 + timeout: 100000 } } }, @@ -358,11 +353,10 @@ module.exports = function(grunt) { // Create the multitasks. grunt.registerTask('build', ['browserify', 'uglify', 'requirejs']); - grunt.registerTask('test', ['jshint', 'jscs', 'build', 'yuidoc:dev', 'connect', 'mocha', 'mochaTest']); + grunt.registerTask('test', ['jshint', 'jscs', 'yuidoc:prod', 'build', 'connect', 'mocha', 'mochaTest']); grunt.registerTask('test:nobuild', ['jshint:test', 'jscs:test', 'connect', 'mocha']); grunt.registerTask('yui', ['yuidoc:prod', 'minjson']); - grunt.registerTask('yui:dev', ['yuidoc:dev', 'minjson']); - grunt.registerTask('yui:test', ['yuidoc:dev', 'connect', 'mocha:yui']); + grunt.registerTask('yui:test', ['yuidoc:prod', 'connect', 'mocha:yui']); grunt.registerTask('default', ['test']); grunt.registerTask('saucetest', ['connect', 'saucelabs-mocha']); }; diff --git a/docs/preprocessor.js b/docs/preprocessor.js index 80e7134052..cc3a8e343d 100644 --- a/docs/preprocessor.js +++ b/docs/preprocessor.js @@ -143,7 +143,7 @@ module.exports.register = function(Handlebars, options) { // } else { // return '/'+this.language; // } - return window.location.pathname+' hi' + return window.location.pathname }); }; diff --git a/docs/yuidoc-p5-theme/layouts/main.handlebars b/docs/yuidoc-p5-theme/layouts/main.handlebars index ef16db28ed..47f8a00e67 100755 --- a/docs/yuidoc-p5-theme/layouts/main.handlebars +++ b/docs/yuidoc-p5-theme/layouts/main.handlebars @@ -6,23 +6,23 @@ p5.js | reference - + - - - - + + + + - - - - - + + + + + @@ -42,7 +42,7 @@
- +

Processing Intuition times JavaScript power

@@ -57,7 +57,7 @@
  • Start
  • Reference
  • Libraries
  • -
  • Tutorials
  • +
  • Learn
  • Examples
  • Books
  • Community
  • @@ -96,7 +96,7 @@

     

    - + * @@ -120,8 +120,8 @@ - - + + + diff --git a/test/unit/color/color_conversion.js b/test/unit/color/color_conversion.js index ffe92d8417..86741f3f82 100644 --- a/test/unit/color/color_conversion.js +++ b/test/unit/color/color_conversion.js @@ -1,4 +1,4 @@ -suite('p5.ColorConversion', function() { +suite('color/p5.ColorConversion', function() { var rgba = [1, 0, 0.4, 0.8]; var rgbaWithHighLightness = [0.969, 0.753, 0.122, 0.8]; var hsla = [336/360, 1, 0.5, 0.8]; diff --git a/test/unit/color/creating_reading.js b/test/unit/color/creating_reading.js index b2f608fa47..44401848f9 100644 --- a/test/unit/color/creating_reading.js +++ b/test/unit/color/creating_reading.js @@ -1,4 +1,4 @@ -suite('CreatingReading', function() { +suite('color/CreatingReading', function() { var myp5 = new p5(function( sketch ) { sketch.setup = function() {}; sketch.draw = function() {}; @@ -6,6 +6,107 @@ suite('CreatingReading', function() { var fromColor; var toColor; + var c; + var val; + + suite('p5.prototype.alpha', function() { + setup(function() { + myp5.colorMode(myp5.RGB); + }); + test('alpha(): no friendly-err-msg I', function() { + assert.doesNotThrow(function() { + var string = 'magenta'; + c = myp5.color(string); + val = myp5.alpha(c); + assert.equal(val, 255); + }, + Error, 'got unwanted exception'); + }); + test('alpha(): no friendly-err-msg II', function() { + assert.doesNotThrow(function() { + c = myp5.color('hsba(160, 100%, 50%, 0.5)'); + val = myp5.alpha(c); + assert.equal(val, 127.5); + }, + Error, 'got unwanted exception'); + }); + test('alpha(): wrong param type at #0', function() { + assert.doesNotThrow(function() { + c = 20; + val = myp5.alpha(c); + }, + Error, 'got unwanted exception'); + }); + }); + + suite('p5.prototype.red, green, blue', function() { + setup(function() { + myp5.colorMode(myp5.RGB); + }); + test('red(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + c = myp5.color('hsl(126, 100%, 60%)'); + val = myp5.red(c); + expect(Math.abs(val-51)).to.be.at.most(2); // max approx err 2 + }, + Error, 'got unwanted exception'); + }); + test('green(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + c = myp5.color('hsl(126, 100%, 60%)'); + val = myp5.green(c); + assert.equal(val, 255); + }, + Error, 'got unwanted exception'); + }); + test('blue(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + c = myp5.color('hsl(126, 100%, 60%)'); + val = myp5.blue(c); + expect(Math.abs(val-70)).to.be.at.most(2); // max approx err 2 + }, + Error, 'got unwanted exception'); + }); + }); + + suite('p5.prototype.hue, brightness, lightness, saturation', function() { + setup(function() { + myp5.colorMode(myp5.HSL); + }); + test('hue(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + c = myp5.color('#7fffd4'); + val = myp5.hue(c); + expect(Math.abs(val-160)).to.be.at.most(2); // max approx err 2 + }, + Error, 'got unwanted exception'); + }); + test('brightness(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + c = myp5.color('#7fffd4'); + val = myp5.brightness(c); + assert.equal(val, 100); + }, + Error, 'got unwanted exception'); + }); + test('lightness(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + c = myp5.color('#7fffd4'); + val = myp5.lightness(c); + expect(Math.abs(val-75)).to.be.at.most(2); // max approx err 2 + }, + Error, 'got unwanted exception'); + }); + test('saturation(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + c = myp5.color('#7fffd4'); + val = myp5.saturation(c); + assert.equal(val, 100); + }, + Error, 'got unwanted exception'); + }); + }); + suite('p5.prototype.lerpColor', function() { setup(function() { myp5.colorMode(myp5.RGB); @@ -38,6 +139,12 @@ suite('CreatingReading', function() { assert.deepEqual(interA.levels, [218, 165, 32, 255]); assert.deepEqual(interB.levels, [72, 61, 139, 255]); }); + test('lerpColor(): missing param #2', function() { + assert.doesNotThrow(function() { + myp5.lerpColor(fromColor, toColor); + }, + Error, 'got unwanted exception'); + }); }); suite('p5.prototype.lerpColor with alpha', function() { setup(function() { diff --git a/test/unit/color/p5.Color.js b/test/unit/color/p5.Color.js index eb409fc99a..25e00e9615 100644 --- a/test/unit/color/p5.Color.js +++ b/test/unit/color/p5.Color.js @@ -24,6 +24,12 @@ suite('p5.Color', function() { test('shouldn\'t set HSLA property before hsb access func is called', function() { assert.equal(c.hsla, undefined); }); + + test('color(): missing param #0 + throws error', function() { + expect(function() { + c = myp5.color(); + }).to.throw(); + }); }); suite('p5.prototype.color("#rgb")', function() { diff --git a/test/unit/color/setting.js b/test/unit/color/setting.js index f1e6036562..7bc8b6c07a 100644 --- a/test/unit/color/setting.js +++ b/test/unit/color/setting.js @@ -1,4 +1,4 @@ -suite('Color', function() { +suite('color/Setting', function() { // p5 instance var myp5 = new p5(function( p ) { diff --git a/test/unit/core/2d_primitives.js b/test/unit/core/2d_primitives.js index 24d22ebc07..e821a3bdd4 100644 --- a/test/unit/core/2d_primitives.js +++ b/test/unit/core/2d_primitives.js @@ -5,10 +5,38 @@ suite('2D Primitives', function() { p.draw = function() {}; }); - teardown(function(){ + teardown(function() { myp5.clear(); }); + suite('p5.prototype.arc', function() { + var arc = p5.prototype.arc; + suite('arc()', function() { + test('should be a function', function() { + assert.ok(arc); + assert.typeOf(arc, 'function'); + }); + test('arc(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + myp5.arc(1, 1, 10.5, 10, 0, Math.PI, 'pie'); + }, + Error, 'got unwanted exception'); + }); + test('arc(): missing param #4, #5', function() { + assert.doesNotThrow(function() { + myp5.arc(1, 1, 10.5, 10); + }, + Error, 'got unwanted exception'); + }); + test('arc(): wrong param type at #0', function() { + assert.doesNotThrow(function() { + myp5.arc('1', 1, 10.5, 10, 0, Math.PI, 'pie'); + }, + Error, 'got unwanted exception'); + }); + }); + }); + suite('p5.prototype.ellipse', function() { var ellipse = p5.prototype.ellipse; suite('ellipse()', function() { @@ -16,6 +44,31 @@ suite('2D Primitives', function() { assert.ok(ellipse); assert.typeOf(ellipse, 'function'); }); + test('ellipse(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + myp5.ellipse(0, 0, 100); + }, + Error, 'got unwanted exception'); + }); + test('ellipse(): missing param #2', function() { + assert.doesNotThrow(function() { + myp5.ellipse(0, 0); + }, + Error, 'got unwanted exception'); + }); + test('ellipse(): missing param #2', function() { + assert.doesNotThrow(function() { + var size; + myp5.ellipse(0, 0, size); + }, + Error, 'got unwanted exception'); + }); + test('ellipse(): wrong param type at #0', function() { + assert.doesNotThrow(function() { + myp5.ellipse('0', 0, 100, 100); + }, + Error, 'got unwanted exception'); + }); }); }); @@ -26,6 +79,175 @@ suite('2D Primitives', function() { assert.ok(line); assert.typeOf(line, 'function'); }); + test('line(): no friendly-err-msg, 2D', function() { + assert.doesNotThrow(function() { + myp5.line(0, 0, 100, 100); + }, + Error, 'got unwanted exception'); + }); + test('line(): no friendly-err-msg, 3D', function() { + assert.doesNotThrow(function() { + myp5.line(0, 0, 100, 100, 20, Math.PI); + }, + Error, 'got unwanted exception'); + }); + test('line(): missing param #3', function() { + assert.doesNotThrow(function() { + myp5.line(0, 0, Math.PI); + }, + Error, 'got unwanted exception'); + }); + test('line(): missing param #4 ', function() { // this err case escapes + assert.doesNotThrow(function() { + var x3; + myp5.line(0, 0, 100, 100, x3, Math.PI); + }, + Error, 'got unwanted exception'); + }); + test('line(): wrong param type at #1', function() { + assert.doesNotThrow(function() { + myp5.line(0, '0', 100, 100); + }, + Error, 'got unwanted exception'); + }); + }); + }); + + suite('p5.prototype.point', function() { + var point = p5.prototype.point; + suite('point()', function() { + test('should be a function', function() { + assert.ok(point); + assert.typeOf(point, 'function'); + }); + test('point(): no friendly-err-msg, 2D', function() { + assert.doesNotThrow(function() { + myp5.point(Math.PI, 0); + }, + Error, 'got unwanted exception'); + }); + test('point(): no friendly-err-msg, 3D', function() { + assert.doesNotThrow(function() { + myp5.point(Math.PI, 0, 100); + }, + Error, 'got unwanted exception'); + }); + test('point(): missing param #1', function() { + assert.doesNotThrow(function() { + myp5.point(0); + }, + Error, 'got unwanted exception'); + }); + test('point(): missing param #3', function() { // this err case escapes + assert.doesNotThrow(function() { + var z; + myp5.point(0, Math.PI, z); + }, + Error, 'got unwanted exception'); + }); + test('point(): wrong param type at #1', function() { + assert.doesNotThrow(function() { + myp5.point(Math.PI, '0'); + }, + Error, 'got unwanted exception'); + }); + }); + }); + + suite('p5.prototype.quad', function() { + var quad = p5.prototype.quad; + suite('quad()', function() { + test('should be a function', function() { + assert.ok(quad); + assert.typeOf(quad, 'function'); + }); + test('quad(): no friendly-err-msg, 2D', function() { + assert.doesNotThrow(function() { + myp5.quad(Math.PI, 0, Math.PI, 5.1, 10, 5.1, 10, 0); + }, + Error, 'got unwanted exception'); + }); + test('quad(): missing param #7', function() { + assert.doesNotThrow(function() { + myp5.quad(Math.PI, 0, Math.PI, 5.1, 10, 5.1, 10); + }, + Error, 'got unwanted exception'); + }); + test('quad(): wrong param type at #1', function() { + assert.doesNotThrow(function() { + myp5.quad(Math.PI, '0', Math.PI, 5.1, 10, 5.1, 10, 0); + }, + Error, 'got unwanted exception'); + }); + }); + }); + + suite('p5.prototype.rect', function() { + var rect = p5.prototype.rect; + suite('rect()', function() { + test('should be a function', function() { + assert.ok(rect); + assert.typeOf(rect, 'function'); + }); + test('rect(): no friendly-err-msg, format I', function() { + assert.doesNotThrow(function() { + myp5.rect(0, 0, 100, 100); + }, + Error, 'got unwanted exception'); + }); + test('rect(): no friendly-err-msg, format II', function() { + assert.doesNotThrow(function() { + myp5.rect(0, 0, 100, 100, 1, Math.PI, 1, Math.PI); + }, + Error, 'got unwanted exception'); + }); + test('rect(): missing param #3', function() { + assert.doesNotThrow(function() { + myp5.rect(0, 0, Math.PI); + }, + Error, 'got unwanted exception'); + }); + test('rect(): missing param #4', function() { // this err case escapes + assert.doesNotThrow(function() { + var r1; + myp5.rect(0, 0, 100, 100, r1, Math.PI, 1, Math.PI); + }, + Error, 'got unwanted exception'); + }); + test('rect(): wrong param type at #1', function() { + assert.doesNotThrow(function() { + myp5.rect(0, '0', 100, 100); + }, + Error, 'got unwanted exception'); + }); + }); + }); + + suite('p5.prototype.triangle', function() { + var triangle = p5.prototype.triangle; + suite('triangle()', function() { + test('should be a function', function() { + assert.ok(triangle); + assert.typeOf(triangle, 'function'); + }); + test('triangle(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + myp5.triangle(Math.PI, 0, Math.PI, 5.1, 10, 5.1); + }, + Error, 'got unwanted exception'); + }); + test('triangle(): missing param #5', function() { + assert.doesNotThrow(function() { + myp5.triangle(Math.PI, 0, Math.PI, 5.1, 10); + }, + Error, 'got unwanted exception'); + }); + test('triangle(): wrong param type at #1', function() { + assert.doesNotThrow(function() { + myp5.triangle(Math.PI, '0', Math.PI, 5.1, 10, 5.1); + }, + Error, 'got unwanted exception'); + }); }); }); diff --git a/test/unit/core/curves.js b/test/unit/core/curves.js index c112d715cf..a3f42f0a95 100644 --- a/test/unit/core/curves.js +++ b/test/unit/core/curves.js @@ -1,4 +1,36 @@ suite('Curves', function() { + var myp5 = new p5(function( p ) { + p.setup = function() {}; + p.draw = function() {}; + }); + + suite('p5.prototype.bezier', function() { + var bezier = p5.prototype.bezier; + suite('bezier()', function() { + test('should be a function', function() { + assert.ok(bezier); + assert.typeOf(bezier, 'function'); + }); + test('bezier(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + myp5.bezier(85, 20, 10, 10, 90, 90, 15, 80); + }, + Error, 'got unwanted exception'); + }); + test('bezier(): no friendly-err-msg. missing param #6, #7', function() { + assert.doesNotThrow(function() { + myp5.bezier(85, 20, 10, 10, 90, 90); + }, + Error, 'got unwanted exception'); + }); + test('bezier(): wrong param type at #0', function() { + assert.doesNotThrow(function() { + myp5.bezier('85', 20, 10, 10, 90, 90, 15, 80); + }, + Error, 'got unwanted exception'); + }); + }); + }); suite('p5.prototype.bezierPoint', function() { var bezierPoint = p5.prototype.bezierPoint; @@ -8,12 +40,12 @@ suite('Curves', function() { assert.ok(bezierPoint); assert.typeOf(bezierPoint, 'function'); }); - test('should return a number', function() { - result = bezierPoint(); + test('should return a number: missing param #0~4', function() { + result = myp5.bezierPoint(); assert.typeOf(result, 'number'); }); test('should return the correct point on a Bezier Curve', function() { - result = bezierPoint(85, 10, 90, 15, 0.5); + result = myp5.bezierPoint(85, 10, 90, 15, 0.5); assert.equal(result, 50); assert.notEqual(result, -1); }); @@ -23,22 +55,50 @@ suite('Curves', function() { suite('p5.prototype.bezierTangent', function() { var bezierTangent = p5.prototype.bezierTangent; var result; - suite('curveTangent()', function() { + suite('bezierTangent()', function() { test('should be a function', function() { assert.ok(bezierTangent); assert.typeOf(bezierTangent, 'function'); }); - test('should return a number', function() { - result = bezierTangent(95, 73, 73, 15, 0.5); + test('should return a number: missing param #0~4', function() { + result = myp5.bezierTangent(); assert.typeOf(result, 'number'); }); test('should return the correct point on a Bezier Curve', function() { - result = bezierTangent(95, 73, 73, 15, 0.5); + result = myp5.bezierTangent(95, 73, 73, 15, 0.5); assert.equal(result, -60); }); }); }); + suite('p5.prototype.curve', function() { + var curve = p5.prototype.curve; + suite('curve()', function() { + test('should be a function', function() { + assert.ok(curve); + assert.typeOf(curve, 'function'); + }); + test('curve(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + myp5.curve(5, 26, 5, 26, 73, 24, 73, 61); + }, + Error, 'got unwanted exception'); + }); + test('curve(): no friendly-err-msg. missing param #6, #7', function() { + assert.doesNotThrow(function() { + myp5.curve(5, 26, 5, 26, 73, 24); + }, + Error, 'got unwanted exception'); + }); + test('curve(): wrong param type at #0', function() { + assert.doesNotThrow(function() { + myp5.curve('5', 26, 5, 26, 73, 24, 73, 61); + }, + Error, 'got unwanted exception'); + }); + }); + }); + suite('p5.prototype.curvePoint', function() { var curvePoint = p5.prototype.curvePoint; var result; @@ -47,12 +107,12 @@ suite('Curves', function() { assert.ok(curvePoint); assert.typeOf(curvePoint, 'function'); }); - test('should return a number', function() { - result = curvePoint(5, 5, 73, 73, 0.5); + test('should return a number: missing param #0~4', function() { + result = myp5.curvePoint(); assert.typeOf(result, 'number'); }); test('should return the correct point on a Catmull-Rom Curve', function() { - result = curvePoint(5, 5, 73, 73, 0.5); + result = myp5.curvePoint(5, 5, 73, 73, 0.5); assert.equal(result, 39); assert.notEqual(result, -1); }); @@ -67,12 +127,12 @@ suite('Curves', function() { assert.ok(curveTangent); assert.typeOf(curveTangent, 'function'); }); - test('should return a number', function() { - result = curveTangent(95, 73, 73, 15, 0.5); + test('should return a number: missing param #0~4', function() { + result = myp5.curveTangent(); assert.typeOf(result, 'number'); }); test('should return the correct point on a Catmull-Rom Curve', function() { - result = curveTangent(95, 73, 73, 15, 0.5); + result = myp5.curveTangent(95, 73, 73, 15, 0.5); assert.equal(result, 10); assert.notEqual(result, -1); }); diff --git a/test/unit/core/error_helpers.js b/test/unit/core/error_helpers.js index 1e2ef29fd6..a1a49364b3 100644 --- a/test/unit/core/error_helpers.js +++ b/test/unit/core/error_helpers.js @@ -1,4 +1,89 @@ suite('Error Helpers', function() { + var myp5 = new p5(function( sketch ) { + sketch.setup = function() {}; + sketch.draw = function() {}; + }); + + // unit tests for validateParameters + suite('validateParameters: Numbers + optional Constant', function(){ + test('arc(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + p5._validateParameters('arc', + [1, 1, 10.5, 10, 0, Math.PI, 'pie']); + }, + Error, 'got unwanted exception'); + }); + test('arc(): missing param #4, #5', function() { + assert.doesNotThrow(function() { + p5._validateParameters('arc', + [1, 1, 10.5, 10]); + }, + Error, 'got unwanted exception'); + }); + test('arc(): wrong param type at #0', function() { + assert.doesNotThrow(function() { + p5._validateParameters('arc', + ['1', 1, 10.5, 10, 0, Math.PI, 'pie']); + }, + Error, 'got unwanted exception'); + }); + }); + + suite('validateParameters: Numbers + optional Constant', function(){ + test('rect(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + p5._validateParameters('rect', + [1, 1, 10.5, 10]); + }, + Error, 'got unwanted exception'); + }); + test('rect(): missing param #3', function() { + assert.doesNotThrow(function() { + p5._validateParameters('rect', + [1, 1, 10.5]); + }, + Error, 'got unwanted exception'); + }); + test('rect(): wrong param type at #0', function() { + assert.doesNotThrow(function() { + p5._validateParameters('rect', + ['1', 1, 10.5, 10, 0, Math.PI]); + }, + Error, 'got unwanted exception'); + }); + }); + + suite('validateParameters: class, multi-types + optional Numbers', function(){ + test('ambientLight(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + var c = myp5.color(255, 204, 0); + p5._validateParameters('ambientLight', [c]); + }, + Error, 'got unwanted exception'); + }); + }); + + suite('validateParameters: multi-format', function(){ + test('color(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + p5._validateParameters('color', [65]); + }, + Error, 'got unwanted exception'); + }); + test('color(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + p5._validateParameters('color', [65, 0.5]); + }, + Error, 'got unwanted exception'); + }); + test('color(): no friendly-err-msg', function() { + assert.doesNotThrow(function() { + p5._validateParameters('color', [255, 204, 0]); + }, + Error, 'got unwanted exception'); + }); + }); + suite('helpForMisusedAtTopLevelCode', function() { var help = function(msg) { var log = []; diff --git a/test/unit/utilities/string_functions.js b/test/unit/utilities/string_functions.js new file mode 100644 index 0000000000..2be59206bb --- /dev/null +++ b/test/unit/utilities/string_functions.js @@ -0,0 +1,174 @@ +suite('String functions', function() { + var myp5 = new p5(function( p ) { + p.setup = function() {}; + p.draw = function() {}; + }); + + var result; + + suite('p5.prototype.join', function() { + var join = p5.prototype.join; + suite('join()', function() { + test('should be a function', function() { + assert.ok(join); + }); + test('should return joined string', function() { + var arr = ['foo', 'bar']; + var sep = '-'; + result = myp5.join(arr, sep); + assert.equal(result, 'foo-bar'); + }); + }); + }); + + suite('p5.prototype.match', function() { + var match = p5.prototype.match; + suite('match()', function() { + test('should be a function', function() { + assert.ok(match); + }); + test('should return correct index of match strings', function() { + var str = 'Where is the duckling in this ducky duck string?'; + var regexp = 'duck'; + result = myp5.match(str, regexp); + assert.equal(result.index, 13); + }); + }); + }); + + suite('p5.prototype.matchAll', function() { + var matchAll = p5.prototype.matchAll; + suite('matchAll()', function() { + test('should be a function', function() { + assert.ok(matchAll); + }); + test('should return correct array of strings', function() { + var str = 'Where is the duckling in this ducky duck string?'; + var regexp = 'duck'; + result = myp5.matchAll(str, regexp); + assert.equal(result.length, 3); + }); + }); + }); + + suite('p5.prototype.nf', function() { + var nf = p5.prototype.nf; + suite('nf()', function() { + test('should be a function', function() { + assert.ok(nf); + }); + test('should return correct string', function() { + var num = 3.141516; + result = myp5.nf(num, 2); + assert.equal(result, '03.141516'); + }); + test('should return correct string', function() { + var num = 3.141516; + result = myp5.nf(num, '2', '2'); // automatic conversion? + assert.equal(result, '03.14'); + }); + }); + }); + + suite('p5.prototype.nfc', function() { + var nfc = p5.prototype.nfc; + suite('nfc()', function() { + test('should be a function', function() { + assert.ok(nfc); + }); + test('should return correct string', function() { + var num = 32000; + result = myp5.nfc(num, 3); + assert.equal(result, '32,000.000'); + }); + test('should return correct string', function() { + var num = 32000; + result = myp5.nfc(num, '3'); // automatic conversion? + assert.equal(result, '32,000.000'); + }); + }); + }); + + suite('p5.prototype.nfp', function() { + var nfp = p5.prototype.nfp; + suite('nfp()', function() { + test('should be a function', function() { + assert.ok(nfp); + }); + test('should return correct string', function() { + var num = -32000; + result = myp5.nfp(num, 3); + assert.equal(result, '-32000'); + }); + test('should return correct string', function() { + var num = 32000; + result = myp5.nfp(num, 3); // automatic conversion? + assert.equal(result, '+32000'); + }); + }); + }); + + suite('p5.prototype.nfs', function() { + var nfs = p5.prototype.nfs; + suite('nfs()', function() { + test('should be a function', function() { + assert.ok(nfs); + }); + test('should return correct string', function() { + var num = -32000; + result = myp5.nfs(num, 3); + assert.equal(result, '-32000'); + }); + test('should return correct string', function() { + var num = 32000; + result = myp5.nfs(num, 3); // automatic conversion? + assert.equal(result, ' 32000'); + }); + }); + }); + + suite('p5.prototype.split', function() { + var split = p5.prototype.split; + suite('split()', function() { + test('should be a function', function() { + assert.ok(split); + }); + test('should return correct index of match strings', function() { + var str = 'parsely, sage, rosemary, thyme'; + var regexp = ','; + result = myp5.split(str, regexp); + assert.equal(result.length, 4); + }); + }); + }); + + suite('p5.prototype.splitTokens', function() { + var splitTokens = p5.prototype.splitTokens; + suite('splitTokens()', function() { + test('should be a function', function() { + assert.ok(splitTokens); + }); + test('should return correct index of match strings', function() { + var str = 'parsely, sage, rosemary, thyme'; + var regexp = ','; + result = myp5.splitTokens(str, regexp); + assert.equal(result.length, 4); + }); + }); + }); + + suite('p5.prototype.trim', function() { + var trim = p5.prototype.trim; + suite('trim()', function() { + test('should be a function', function() { + assert.ok(trim); + }); + test('should return correct strings', function() { + var str = ' oh so roomy '; + result = myp5.trim(str); + assert.equal(result, 'oh so roomy'); + }); + }); + }); + +});