test.base64.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. // requires local modules: base64
  2. var assert = chai.assert;
  3. var expect = chai.expect;
  4. describe('Base64 Tools', function() {
  5. "use strict";
  6. var BIN_ARR = new Array(256);
  7. for (var i = 0; i < 256; i++) {
  8. BIN_ARR[i] = i;
  9. }
  10. var B64_STR = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
  11. describe('encode', function() {
  12. it('should encode a binary string into Base64', function() {
  13. var encoded = Base64.encode(BIN_ARR);
  14. expect(encoded).to.equal(B64_STR);
  15. });
  16. });
  17. describe('decode', function() {
  18. it('should decode a Base64 string into a normal string', function() {
  19. var decoded = Base64.decode(B64_STR);
  20. expect(decoded).to.deep.equal(BIN_ARR);
  21. });
  22. it('should throw an error if we have extra characters at the end of the string', function() {
  23. expect(function () { Base64.decode(B64_STR+'abcdef'); }).to.throw(Error);
  24. });
  25. });
  26. });