dankogai.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * $Id: dankogai.js,v 0.4 2012/08/24 05:23:18 dankogai Exp dankogai $
  3. *
  4. * use mocha to test me
  5. * http://visionmedia.github.com/mocha/
  6. */
  7. var assert, Base64;
  8. if (this['window'] !== this) {
  9. assert = require("assert");
  10. Base64 = require('../base64.js').Base64;
  11. }
  12. var is = function (a, e, m) {
  13. return function () {
  14. assert.equal(a, e, m)
  15. }
  16. };
  17. describe('basic', function () {
  18. it('d', is(Base64.encode('d'), 'ZA=='));
  19. it('da', is(Base64.encode('da'), 'ZGE='));
  20. it('dan', is(Base64.encode('dan'), 'ZGFu'));
  21. it('ZA==', is(Base64.decode('ZA=='), 'd' ));
  22. it('ZGE=', is(Base64.decode('ZGE='), 'da' ));
  23. it('ZGFu', is(Base64.decode('ZGFu'), 'dan' ));
  24. });
  25. describe('whitespace', function () {
  26. it('Z A==', is(Base64.decode('ZA =='), 'd' ));
  27. it('ZG E=', is(Base64.decode('ZG E='), 'da' ));
  28. it('ZGF u', is(Base64.decode('ZGF u'), 'dan' ));
  29. });
  30. describe('null', function () {
  31. it('\\0', is(Base64.encode('\0'), 'AA=='));
  32. it('\\0\\0', is(Base64.encode('\0\0'), 'AAA='));
  33. it('\\0\\0\\0', is(Base64.encode('\0\0\0'), 'AAAA'));
  34. it('AA==', is(Base64.decode('AA=='), '\0' ));
  35. it('AAA=', is(Base64.decode('AAA='), '\0\0' ));
  36. it('AAAA', is(Base64.decode('AAAA'), '\0\0\0'));
  37. });
  38. describe('Base64', function () {
  39. it('.encode', is(Base64.encode('小飼弾'), '5bCP6aO85by+'));
  40. it('.encodeURI', is(Base64.encodeURI('小飼弾'), '5bCP6aO85by-'));
  41. it('.decode', is(Base64.decode('5bCP6aO85by+'), '小飼弾'));
  42. it('.decode', is(Base64.decode('5bCP6aO85by-'), '小飼弾'));
  43. });