|
| 1 | +local sha1 = require('opencode.sha1') |
| 2 | + |
| 3 | +describe('sha1', function() |
| 4 | + it('produces correct hash for empty string', function() |
| 5 | + assert.equals('da39a3ee5e6b4b0d3255bfef95601890afd80709', sha1('')) |
| 6 | + end) |
| 7 | + |
| 8 | + it('produces correct hash for "abc"', function() |
| 9 | + assert.equals('a9993e364706816aba3e25717850c26c9cd0d89d', sha1('abc')) |
| 10 | + end) |
| 11 | + |
| 12 | + it('produces correct hash for "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"', function() |
| 13 | + assert.equals('84983e441c3bd26ebaae4aa1f95129e5e54670f1', sha1('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')) |
| 14 | + end) |
| 15 | + |
| 16 | + it('produces correct hash for single character', function() |
| 17 | + assert.equals('86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', sha1('a')) |
| 18 | + end) |
| 19 | + |
| 20 | + it('produces correct hash for "ab"', function() |
| 21 | + assert.equals('da23614e02469a0d7c7bd1bdab5c9c474b1904dc', sha1('ab')) |
| 22 | + end) |
| 23 | + |
| 24 | + it('produces correct hash for numbers', function() |
| 25 | + assert.equals('01b307acba4f54f55aafc33bb06bbbf6ca803e9a', sha1('1234567890')) |
| 26 | + end) |
| 27 | + |
| 28 | + it('produces correct hash for special characters', function() |
| 29 | + assert.equals('bf24d65c9bb05b9b814a966940bcfa50767c8a8d', sha1('!@#$%^&*()')) |
| 30 | + end) |
| 31 | + |
| 32 | + it('produces correct hash for string with spaces', function() |
| 33 | + assert.equals('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', sha1('hello world')) |
| 34 | + end) |
| 35 | + |
| 36 | + it('produces correct hash for newlines', function() |
| 37 | + assert.equals('05eed6236c8bda5ecf7af09bae911f9d5f90998b', sha1('line1\nline2')) |
| 38 | + end) |
| 39 | + |
| 40 | + it('produces correct hash for null byte', function() |
| 41 | + assert.equals('dbdd4f85d8a56500aa5c9c8a0d456f96280c92e5', sha1('ab\0c')) |
| 42 | + end) |
| 43 | + |
| 44 | + it('produces correct hash for 448-bit message (exactly 56 bytes, boundary condition)', function() |
| 45 | + local msg = string.rep('a', 56) |
| 46 | + assert.equals('c2db330f6083854c99d4b5bfb6e8f29f201be699', sha1(msg)) |
| 47 | + end) |
| 48 | + |
| 49 | + it('produces correct hash for 512-bit message (exactly 64 bytes, one full block)', function() |
| 50 | + local msg = string.rep('a', 64) |
| 51 | + assert.equals('0098ba824b5c16427bd7a1122a5a442a25ec644d', sha1(msg)) |
| 52 | + end) |
| 53 | + |
| 54 | + it('produces correct hash for multi-block message (200 bytes)', function() |
| 55 | + local msg = string.rep('a', 200) |
| 56 | + assert.equals('e61cfffe0d9195a525fc6cf06ca2d77119c24a40', sha1(msg)) |
| 57 | + end) |
| 58 | + |
| 59 | + it('produces correct hash for unicode text', function() |
| 60 | + assert.equals('24e9f5c07847ff8a2a9fa77456655792f5bc7f9f', sha1('héllo wörld')) |
| 61 | + end) |
| 62 | +end) |
0 commit comments