dankogai.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 = assert || require("assert");
  8. var Base64 = Base64 || require('../base64.js').Base64;
  9. var is = function (a, e, m) {
  10. return function () {
  11. assert.equal(a, e, m)
  12. }
  13. };
  14. describe('basic', function () {
  15. it('d', is(Base64.encode('d'), 'ZA=='));
  16. it('da', is(Base64.encode('da'), 'ZGE='));
  17. it('dan', is(Base64.encode('dan'), 'ZGFu'));
  18. it('ZA==', is(Base64.decode('ZA=='), 'd' ));
  19. it('ZGE=', is(Base64.decode('ZGE='), 'da' ));
  20. it('ZGFu', is(Base64.decode('ZGFu'), 'dan' ));
  21. });
  22. describe('whitespace', function () {
  23. it('Z A==', is(Base64.decode('ZA =='), 'd' ));
  24. it('ZG E=', is(Base64.decode('ZG E='), 'da' ));
  25. it('ZGF u', is(Base64.decode('ZGF u'), 'dan' ));
  26. });
  27. describe('null', function () {
  28. it('\\0', is(Base64.encode('\0'), 'AA=='));
  29. it('\\0\\0', is(Base64.encode('\0\0'), 'AAA='));
  30. it('\\0\\0\\0', is(Base64.encode('\0\0\0'), 'AAAA'));
  31. it('AA==', is(Base64.decode('AA=='), '\0' ));
  32. it('AAA=', is(Base64.decode('AAA='), '\0\0' ));
  33. it('AAAA', is(Base64.decode('AAAA'), '\0\0\0'));
  34. });
  35. describe('Base64', function () {
  36. it('.encode', is(Base64.encode('小飼弾'), '5bCP6aO85by+'));
  37. it('.encodeURI', is(Base64.encodeURI('小飼弾'), '5bCP6aO85by-'));
  38. it('.decode', is(Base64.decode('5bCP6aO85by+'), '小飼弾'));
  39. it('.decode', is(Base64.decode('5bCP6aO85by-'), '小飼弾'));
  40. });