update REAMD, config, test cases

pull/3/head
Chen Yi-Cyuan 11 years ago
parent e36b8d13f7
commit 41432a9660

@ -8,3 +8,6 @@ before_install:
- npm install coveralls -g - npm install coveralls -g
- npm install mocha-lcov-reporter -g - npm install mocha-lcov-reporter -g
script: npm run-script coveralls script: npm run-script coveralls
branches:
only:
- master

@ -34,8 +34,8 @@ md5 = require('js-md5');
Code Code
```JavaScript ```JavaScript
md5(''); md5('');
md5('The quick brown fox jumps over the lazy dog', true); md5('The quick brown fox jumps over the lazy dog');
md5('The quick brown fox jumps over the lazy dog.', true); md5('The quick brown fox jumps over the lazy dog.');
``` ```
Output Output

@ -11,7 +11,6 @@
<body> <body>
<div id="mocha"></div> <div id="mocha"></div>
<script> <script>
testName = 'default';
mocha.setup('bdd'); mocha.setup('bdd');
</script> </script>
<script src="test.js"></script> <script src="test.js"></script>

@ -1,6 +1,5 @@
md5 = require('../src/md5.js'); md5 = require('../src/md5.js');
expect = require('expect.js'); expect = require('expect.js');
testName = 'default';
require('./test.js'); require('./test.js');
delete require.cache[require.resolve('../src/md5.js')] delete require.cache[require.resolve('../src/md5.js')]
@ -8,6 +7,5 @@ delete require.cache[require.resolve('./test.js')]
md5 = null md5 = null
JS_MD5_TEST = true; JS_MD5_TEST = true;
testName = 'without ArrayBuffer'; require('../src/md5.js');
base64 = require('../src/md5.js');
require('./test.js'); require('./test.js');

@ -1,23 +1,17 @@
var module = md5; (function(md5) {
describe('md5', function() {
describe(testName, function() {
describe('ascii', function() { describe('ascii', function() {
describe('less than 64 bytes', function() { describe('less than 64 bytes', function() {
it('should be successful', function() { it('should be successful', function() {
expect(module('')).to.be('d41d8cd98f00b204e9800998ecf8427e'); expect(md5('')).to.be('d41d8cd98f00b204e9800998ecf8427e');
expect(module('The quick brown fox jumps over the lazy dog')).to.be('9e107d9d372bb6826bd81d3542a419d6'); expect(md5('The quick brown fox jumps over the lazy dog')).to.be('9e107d9d372bb6826bd81d3542a419d6');
expect(module('The quick brown fox jumps over the lazy dog.')).to.be('e4d909c290d0fb1ca068ffaddf22cbd0'); expect(md5('The quick brown fox jumps over the lazy dog.')).to.be('e4d909c290d0fb1ca068ffaddf22cbd0');
expect(module('0123456780123456780123456780123456780123456780123456780')).to.be('a119de63e4b2398427da06dd780263b3');
expect(module('01234567801234567801234567801234567801234567801234567801')).to.be('ddafd84ebe63aebc4626b037a569d78b');
}); });
}); });
describe('more than 64 bytes', function() { describe('more than 64 bytes', function() {
it('should be successful', function() { it('should be successful', function() {
expect(module('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('f63872ef7bc97a8a8eadba6f0881de53'); expect(md5('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('f63872ef7bc97a8a8eadba6f0881de53');
expect(module('01234567801234567801234567801234567801234567801234567801234567801234567')).to.be('658d914ae42c4938874b2e786ccda479');
expect(module('012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('a083a3710d685793f1f17988bfe3c175');
expect(module('012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('2b21a843cfc31c8026a0d835bc91bc98');
}); });
}); });
}); });
@ -25,17 +19,29 @@ describe(testName, function() {
describe('UTF8', function() { describe('UTF8', function() {
describe('less than 64 bytes', function() { describe('less than 64 bytes', function() {
it('should be successful', function() { it('should be successful', function() {
expect(module('中文')).to.be('a7bac2239fcdcb3a067903d8077c4a07'); expect(md5('中文')).to.be('a7bac2239fcdcb3a067903d8077c4a07');
expect(module('aécio')).to.be('ec3edbf3b05a449fc206a0138c739c3b'); expect(md5('aécio')).to.be('ec3edbf3b05a449fc206a0138c739c3b');
expect(module('𠜎')).to.be('b90869aaf121210f6c563973fa855650'); expect(md5('𠜎')).to.be('b90869aaf121210f6c563973fa855650');
}); });
}); });
describe('more than 64 bytes', function() { describe('more than 64 bytes', function() {
it('should be successful', function() { it('should be successful', function() {
expect(module('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('edce615b179e6e29be23145b77ebbd61'); expect(md5('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('edce615b179e6e29be23145b77ebbd61');
expect(module('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一又譯雜湊演算法、摘要演算法等主流程式語言普遍已有MD5的實作。')).to.be('ad36c9ab669a0ba9ce46d3ce9134de34'); expect(md5('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一又譯雜湊演算法、摘要演算法等主流程式語言普遍已有MD5的實作。')).to.be('ad36c9ab669a0ba9ce46d3ce9134de34');
});
});
});
describe('special length', function() {
it('should be successful', function() {
expect(md5('0123456780123456780123456780123456780123456780123456780')).to.be('a119de63e4b2398427da06dd780263b3');
expect(md5('01234567801234567801234567801234567801234567801234567801')).to.be('ddafd84ebe63aebc4626b037a569d78b');
expect(md5('0123456780123456780123456780123456780123456780123456780123456780')).to.be('9ea04d743618797ce464445b5785a630');
expect(md5('01234567801234567801234567801234567801234567801234567801234567801234567')).to.be('658d914ae42c4938874b2e786ccda479');
expect(md5('012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('a083a3710d685793f1f17988bfe3c175');
expect(md5('012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('2b21a843cfc31c8026a0d835bc91bc98');
}); });
}); });
}); });
}); })(md5);

Loading…
Cancel
Save