* Add bower package.

* Fixed JSHint warnings.
* Add travis.
* Add coveralls.
This commit is contained in:
emn178
2015-01-07 15:26:09 +08:00
parent 7c0300fae5
commit c8da6f6851
13 changed files with 188 additions and 104 deletions
-12
View File
@@ -1,12 +0,0 @@
(function(root){
var assert = function (title, expect, actual) {
if(expect == actual)
console.log(title + ': true');
else
console.log(title + ': false', 'Except:' + expect, 'Actual: ' + actual);
};
if(typeof(module) != 'undefined')
global.assert = assert;
else if(root)
root.assert = assert;
})(this);
+12 -2
View File
@@ -3,10 +3,20 @@
<head>
<meta charset="UTF-8">
<title>SHA1</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/expect.js/0.2.0/expect.min.js"></script>
<script src="../src/sha1.js"></script>
<script src="debug.js"></script>
<script src="test.js"></script>
</head>
<body>
<div id="mocha"></div>
<script>
mocha.setup('bdd');
</script>
<script src="test.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
</body>
</html>
+1 -1
View File
@@ -1,3 +1,3 @@
sha1 = require('../src/sha1.js');
require('./debug.js');
expect = require('expect.js');
require('./test.js');
+30 -5
View File
@@ -1,5 +1,30 @@
assert('sha1 1', 'da39a3ee5e6b4b0d3255bfef95601890afd80709', sha1(''));
assert('sha1 2', '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12', sha1('The quick brown fox jumps over the lazy dog'));
assert('sha1 3', '408d94384216f890ff7a0c3528e8bed1e0b01621', sha1('The quick brown fox jumps over the lazy dog.'));
assert('sha1 4', '7be2d2d20c106eee0836c9bc2b939890a78e8fb3', sha1('中文'));
assert('sha1 5', '9e4e5d978deced901d621475b03f1ded19e945bf', sha1('aécio'));
describe('ascii', function() {
describe('less than 64 bytes', function() {
it('should be successful', function() {
expect(sha1('')).to.be('da39a3ee5e6b4b0d3255bfef95601890afd80709');
expect(sha1('The quick brown fox jumps over the lazy dog')).to.be('2fd4e1c67a2d28fced849ee1bb76e7391b93eb12');
expect(sha1('The quick brown fox jumps over the lazy dog.', true)).to.be('408d94384216f890ff7a0c3528e8bed1e0b01621');
});
});
describe('more than 64 bytes', function() {
it('should be successful', function() {
expect(sha1('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('8690faab7755408a03875895176fac318f14a699');
});
});
});
describe('UTF8', function() {
describe('less than 64 bytes', function() {
it('should be successful', function() {
expect(sha1('中文')).to.be('7be2d2d20c106eee0836c9bc2b939890a78e8fb3');
expect(sha1('aécio')).to.be('9e4e5d978deced901d621475b03f1ded19e945bf');
});
});
describe('more than 64 bytes', function() {
it('should be successful', function() {
expect(sha1('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('3a15ad3ce9efdd4bf982eaaaecdeda36a887a3f9');
});
});
});