From eedad83f7bac53529d2bbce782d7c7ed6139d191 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Sun, 1 Jun 2014 08:44:43 +0200 Subject: [PATCH] Add tests to ensure that the `name` of each error instance is `'InvalidCharacterError'` --- .travis.yml | 4 +- Gruntfile.js | 9 +- README.md | 2 +- package.json | 15 +- tests/tests.js | 677 ++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 692 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0fc50ac..37eb3b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,6 @@ before_script: # If the enviroment stores rt.jar in a different directory, find it and symlink the directory - "PREFIX=/usr/lib/jvm; if [ ! -d $PREFIX/java-6-openjdk ]; then for d in $PREFIX/java-6-openjdk-*; do if [ -e $d/jre/lib/rt.jar ]; then sudo ln -s $d $PREFIX/java-6-openjdk; break; fi; done; fi" script: - "grunt ci" + - "grunt ci" +after_script: + - "grunt shell:cover-coveralls" diff --git a/Gruntfile.js b/Gruntfile.js index 7a7e922..6d3901a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,9 +7,12 @@ module.exports = function(grunt) { 'stderr': true, 'failOnError': true }, - 'cover': { + 'cover-html': { 'command': 'istanbul cover --report "html" --verbose --dir "coverage" "tests/tests.js"' }, + 'cover-coveralls': { + 'command': 'istanbul cover --verbose --dir "coverage" "tests/tests.js" && cat coverage/lcov.info | coveralls; rm -rf coverage/lcov*' + }, 'test-narwhal': { 'command': 'echo "Testing in Narwhal..."; export NARWHAL_OPTIMIZATION=-1; narwhal "tests/tests.js"' }, @@ -54,14 +57,14 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-shell'); grunt.loadNpmTasks('grunt-template'); - grunt.registerTask('cover', 'shell:cover'); + grunt.registerTask('cover', 'shell:cover-html'); grunt.registerTask('ci', [ 'template', 'shell:test-narwhal', 'shell:test-phantomjs', 'shell:test-rhino', 'shell:test-ringo', - 'shell:test-node', + 'shell:test-node' ]); grunt.registerTask('test', [ 'ci', diff --git a/README.md b/README.md index 5b1e557..5d1833d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# base64 [![Build status](https://travis-ci.org/mathiasbynens/base64.svg?branch=master)](https://travis-ci.org/mathiasbynens/base64) [![Dependency status](https://gemnasium.com/mathiasbynens/base64.svg)](https://gemnasium.com/mathiasbynens/base64) +# base64 [![Build status](https://travis-ci.org/mathiasbynens/base64.svg?branch=master)](https://travis-ci.org/mathiasbynens/base64) [![Code coverage status](http://img.shields.io/coveralls/mathiasbynens/base64/master.svg)](https://coveralls.io/r/mathiasbynens/base64) [![Dependency status](https://gemnasium.com/mathiasbynens/base64.svg)](https://gemnasium.com/mathiasbynens/base64) _base64_ is a robust base64 encoder/decoder that is fully compatible with [`atob()` and `btoa()`](http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#atob), written in JavaScript. The base64-encoding and -decoding algorithms it uses are fully [RFC 4648](http://tools.ietf.org/html/rfc4648#section-4) compliant. diff --git a/package.json b/package.json index 5f98c42..14a5913 100644 --- a/package.json +++ b/package.json @@ -40,13 +40,14 @@ "test": "node tests/tests.js" }, "devDependencies": { - "grunt": "~0.4.4", - "grunt-shell": "~0.7.0", - "grunt-template": "~0.2.3", - "istanbul": "~0.2.7", - "qunit-extras": "~1.1.0", + "coveralls": "^2.10.0", + "grunt": "^0.4.5", + "grunt-shell": "^0.7.0", + "grunt-template": "^0.2.3", + "istanbul": "^0.2.10", + "qunit-extras": "^1.2.0", "qunitjs": "~1.11.0", - "regenerate": "^0.6.1", - "requirejs": "~2.1.11" + "regenerate": "^0.6.2", + "requirejs": "^2.1.13" } } diff --git a/tests/tests.js b/tests/tests.js index 439d92d..e14ef02 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -75,6 +75,17 @@ }, 'The string to be encoded contains characters outside of the Latin1 range.' ); + equal( + (function() { + try { + base64.encode('\u05E2\u05D1\u05E8\u05D9\u05EA'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'The string to be encoded contains characters outside of the Latin1 range.' + ); equal( base64.encode('\xFF\xFF\xC0'), '///A' @@ -147,6 +158,17 @@ }, 'The string to be encoded contains characters outside of the Latin1 range.' ); + equal( + (function() { + try { + base64.encode('\uD800\uDC00'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'The string to be encoded contains characters outside of the Latin1 range.' + ); }); test('base64.decode', function() { @@ -167,6 +189,17 @@ 'Invalid character', 'Invalid character' ); + equal( + (function() { + try { + base64.decode('YQ==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'The string to be decoded is not correctly encoded.' + ); equal( base64.decode('YQ=='), 'a', @@ -240,30 +273,85 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode(' abcd==='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode(' abcd==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcd=== '); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd=== '); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcd ==='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd ==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('a'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('a'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode('ab'), 'i' @@ -278,78 +366,221 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcde'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('\uD800\uDC00'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('\uD800\uDC00'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('=='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('=='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('==='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('===='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('===='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('====='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('====='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('a='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('a='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('a=='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('a=='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('a==='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('a==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('a===='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('a===='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('a====='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('a====='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('ab='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('ab='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode('ab=='), 'i' @@ -360,18 +591,51 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('ab==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('ab===='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('ab===='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('ab====='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('ab====='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode('abc='), 'i\xB7' @@ -382,132 +646,374 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abc=='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abc==='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abc==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abc===='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abc===='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abc====='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abc====='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcd='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcd=='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd=='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcd==='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcd===='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd===='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcd====='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd====='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcde='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcde='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcde=='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcde=='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcde==='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcde==='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcde===='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcde===='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcde====='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcde====='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('=a'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('=a'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('=a='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('=a='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('a=b'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('a=b'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('a=b='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('a=b='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('ab=c'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('ab=c'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('ab=c='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('ab=c='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abc=d'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abc=d'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abc=d='); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abc=d='); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode('ab\tcd'), 'i\xB7\x1D' @@ -534,6 +1040,17 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('ab\xA0cd'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode('ab\t\n\f\r cd'), 'i\xB7\x1D' @@ -552,6 +1069,17 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('A'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode('/A'), '\xFC' @@ -570,12 +1098,34 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('////A'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('/'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('/'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode('A/'), '\x03' @@ -590,6 +1140,17 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('AAAA/'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode('AAA/'), '\0\0?' @@ -600,24 +1161,68 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('\0'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('\0nonsense'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('\0nonsense'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode('abcd\0nonsense'); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode('abcd\0nonsense'); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { base64.decode(undefined); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode(undefined); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode(null), '\x9E\xE9e' @@ -628,6 +1233,17 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode(7); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode(12), '\xD7' @@ -638,6 +1254,17 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode(1.5); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode(true), '\xB6\xBB\x9E' @@ -648,12 +1275,23 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode(false); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode(NaN), '5\xA3' ); equal( - base64.decode(Infinity), + base64.decode(+Infinity), '"w\xE2\x9E+r' ); raises( @@ -662,18 +1300,51 @@ }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode(-Infinity); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { - base64.decode(0); + base64.decode(+0); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode(+0); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); raises( function() { - base64.decode(0); + base64.decode(-0); }, 'Invalid character: the string to be decoded is not correctly encoded.' ); + equal( + (function() { + try { + base64.decode(-0); + } catch (exception) { + return exception.name; + } + }()), + 'InvalidCharacterError', + 'Invalid character: the string to be decoded is not correctly encoded.' + ); equal( base64.decode({ 'toString': function() { return 'foo'; }}), '~\x8A'