diff --git a/__tests__/ReCrypt_test.re b/__tests__/ReCrypt_test.re index d19b398..0ff62ec 100644 --- a/__tests__/ReCrypt_test.re +++ b/__tests__/ReCrypt_test.re @@ -2,29 +2,43 @@ open Jest; open Expect; open ReCrypt; +type test = { + input: string, + output: string, +}; + +let tests = [| + { + input: "unicorn", + output: "e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27", + }, + { + input: "", + output: "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", + }, + { + input: "Some pretty long string which probably exeed the length of one message block (now it really does it...aaaaaaaaaaaaaaaaaaaaaaah)", + output: "f2dc19af2097fba02ce5a3293ae7981ee782a8c2b879e76922a095985168a3f57cb64ba716d7aa905ca6d0a06c21ab0cfd3d103527338b635032369ec3567448", + }, + { + input: "This message is exactly one bit longer than one word: 658f14df49932d6b40a4e4d8424196af7c3477397818e59e748f722186", + output: "384b8be9a3d0d13a73b32806d4087c47f236b0692420a2cd023c52403310f7fcb68c637ce55b9cd12aeafeffa3a94f9e96300238989b4b1d27f98c17491c2321", + }, +|]; + describe("Sha512", () => { - test("make(\"unicorn\")", () => - expect(Sha512.make("unicorn")) - |> toBe( - "e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27", - ) - ); - test("make(\"\")", () => - expect(Sha512.make("")) - |> toBe( - "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", - ) - ); - test( - "make(\"Some pretty long string which probably exeed the length of one message block\")", - () => - expect( - Sha512.make( - "Some pretty long string which probably exeed the length of one message block", - ), - ) - |> toBe( - "080f575bf58758f2e57105307c89628c9e60faa868e18997f8d29736f54521b0f4960dff620c5958158466c767aa20f76c4d4d7ffd0e7287fa300790bfe99dd9", - ) - ); + describe("make()", () => { + test("\"" ++ tests[0].input ++ "\"", () => + expect(Sha512.make(tests[0].input)) |> toBe(tests[0].output) + ); + test("\"" ++ tests[1].input ++ "\"", () => + expect(Sha512.make(tests[1].input)) |> toBe(tests[1].output) + ); + test("\"" ++ tests[2].input ++ "\"", () => + expect(Sha512.make(tests[2].input)) |> toBe(tests[2].output) + ); + test("\"" ++ tests[3].input ++ "\"", () => + expect(Sha512.make(tests[3].input)) |> toBe(tests[3].output) + ); + }) }); \ No newline at end of file diff --git a/lib/js/__tests__/ReCrypt_test.bs.js b/lib/js/__tests__/ReCrypt_test.bs.js index 9209198..8f50b1e 100644 --- a/lib/js/__tests__/ReCrypt_test.bs.js +++ b/lib/js/__tests__/ReCrypt_test.bs.js @@ -2,18 +2,44 @@ 'use strict'; var Jest = require("@glennsl/bs-jest/lib/js/src/jest.js"); +var Caml_array = require("bs-platform/lib/js/caml_array.js"); var ReCrypt_Sha512 = require("../src/ReCrypt/ReCrypt_Sha512.bs.js"); +var tests = [ + { + input: "unicorn", + output: "e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27" + }, + { + input: "", + output: "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + }, + { + input: "Some pretty long string which probably exeed the length of one message block (now it really does it...aaaaaaaaaaaaaaaaaaaaaaah)", + output: "f2dc19af2097fba02ce5a3293ae7981ee782a8c2b879e76922a095985168a3f57cb64ba716d7aa905ca6d0a06c21ab0cfd3d103527338b635032369ec3567448" + }, + { + input: "This message is exactly one bit longer than one word: 658f14df49932d6b40a4e4d8424196af7c3477397818e59e748f722186", + output: "384b8be9a3d0d13a73b32806d4087c47f236b0692420a2cd023c52403310f7fcb68c637ce55b9cd12aeafeffa3a94f9e96300238989b4b1d27f98c17491c2321" + } +]; + Jest.describe("Sha512", (function (param) { - Jest.test("make(\"unicorn\")", (function (param) { - return Jest.Expect.toBe("e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27", Jest.Expect.expect(ReCrypt_Sha512.make("unicorn"))); - })); - Jest.test("make(\"\")", (function (param) { - return Jest.Expect.toBe("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", Jest.Expect.expect(ReCrypt_Sha512.make(""))); - })); - return Jest.test("make(\"Some pretty long string which probably exeed the length of one message block\")", (function (param) { - return Jest.Expect.toBe("080f575bf58758f2e57105307c89628c9e60faa868e18997f8d29736f54521b0f4960dff620c5958158466c767aa20f76c4d4d7ffd0e7287fa300790bfe99dd9", Jest.Expect.expect(ReCrypt_Sha512.make("Some pretty long string which probably exeed the length of one message block"))); + return Jest.describe("make()", (function (param) { + Jest.test("\"" + (Caml_array.caml_array_get(tests, 0).input + "\""), (function (param) { + return Jest.Expect.toBe(Caml_array.caml_array_get(tests, 0).output, Jest.Expect.expect(ReCrypt_Sha512.make(Caml_array.caml_array_get(tests, 0).input))); + })); + Jest.test("\"" + (Caml_array.caml_array_get(tests, 1).input + "\""), (function (param) { + return Jest.Expect.toBe(Caml_array.caml_array_get(tests, 1).output, Jest.Expect.expect(ReCrypt_Sha512.make(Caml_array.caml_array_get(tests, 1).input))); + })); + Jest.test("\"" + (Caml_array.caml_array_get(tests, 2).input + "\""), (function (param) { + return Jest.Expect.toBe(Caml_array.caml_array_get(tests, 2).output, Jest.Expect.expect(ReCrypt_Sha512.make(Caml_array.caml_array_get(tests, 2).input))); + })); + return Jest.test("\"" + (Caml_array.caml_array_get(tests, 3).input + "\""), (function (param) { + return Jest.Expect.toBe(Caml_array.caml_array_get(tests, 3).output, Jest.Expect.expect(ReCrypt_Sha512.make(Caml_array.caml_array_get(tests, 3).input))); + })); })); })); +exports.tests = tests; /* Not a pure module */