From 1b80a0e2d1ad474db56da0c6f79868dc1f0c207e Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Thu, 21 Mar 2024 04:41:27 -0400 Subject: [PATCH 1/2] Update for new multiline string requirement. Contents of a multiline string must start on new line. --- tests/src/Test/Json.gren | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/src/Test/Json.gren b/tests/src/Test/Json.gren index 0ea79592..9ff5e41c 100644 --- a/tests/src/Test/Json.gren +++ b/tests/src/Test/Json.gren @@ -58,7 +58,9 @@ customTests : Test customTests = let jsonString = - """{ "foo": "bar" }""" + """ + { "foo": "bar" } + """ customErrorMessage = "I want to see this message!" From 109ae0beefc7ee70692985f8fec164dd9977f1f6 Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Sun, 17 Mar 2024 06:35:22 -0400 Subject: [PATCH 2/2] Fix equality check for bytes. Should fix https://github.com/gren-lang/core/issues/48 Using suggested fix from https://github.com/elm/core/pull/1092/files --- src/Gren/Kernel/Utils.js | 14 ++++++++++++++ tests/src/Main.gren | 2 ++ tests/src/Test/Bytes.gren | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/src/Test/Bytes.gren diff --git a/src/Gren/Kernel/Utils.js b/src/Gren/Kernel/Utils.js index ea44dc4b..d23cf749 100644 --- a/src/Gren/Kernel/Utils.js +++ b/src/Gren/Kernel/Utils.js @@ -55,6 +55,20 @@ function _Utils_eqHelp(x, y, depth, stack) { } //*/ + if (typeof DataView === "function" && x instanceof DataView) { + var length = x.byteLength; + + if (y.byteLength !== length) { + return false; + } + + for (var i = 0; i < length; ++i) { + if (x.getUint8(i) !== y.getUint8(i)) { + return false; + } + } + } + if (Array.isArray(x) && x.length !== y.length) { return false; } diff --git a/tests/src/Main.gren b/tests/src/Main.gren index 656b9631..6d2690d2 100644 --- a/tests/src/Main.gren +++ b/tests/src/Main.gren @@ -8,6 +8,7 @@ import Test exposing (..) import Test.Array as Array import Test.Basics as Basics import Test.Bitwise as Bitwise +import Test.Bytes as Bytes import Test.Char as Char import Test.CodeGen as CodeGen import Test.Dict as Dict @@ -28,6 +29,7 @@ main = [ Array.tests , Basics.tests , Bitwise.tests + , Bytes.tests , Char.tests , CodeGen.tests , Dict.tests diff --git a/tests/src/Test/Bytes.gren b/tests/src/Test/Bytes.gren new file mode 100644 index 00000000..69a8c3bb --- /dev/null +++ b/tests/src/Test/Bytes.gren @@ -0,0 +1,35 @@ +module Test.Bytes exposing (tests) + +import Bytes exposing (Bytes) +import Bytes.Encode +import Expect +import Fuzz +import Test exposing (..) + + +encodeString : String -> Bytes +encodeString s = + Bytes.Encode.encode <| + Bytes.Encode.string s + + +encodeInt : Int -> Bytes +encodeInt i = + Bytes.Encode.encode <| + Bytes.Encode.signedInt8 i + + +tests : Test +tests = + describe "Byte comparison" + [ fuzz Fuzz.string "same strings are equal" <| \s -> + Expect.equal (encodeString s) (encodeString s) + , fuzz (Fuzz.intRange -128 127) "same ints are equal" <| \i -> + Expect.equal (encodeInt i) (encodeInt i) + , fuzz Fuzz.string "different strings are not equal" <| \s -> + Expect.notEqual (encodeString s) (encodeString (s ++ "a")) + , fuzz (Fuzz.intRange -100 100) "different ints are not equal" <| \i -> + Expect.notEqual (encodeInt i) (encodeInt (i + 1)) + , fuzz2 Fuzz.string (Fuzz.intRange 1 127) "string and int are not equal" <| \s i -> + Expect.notEqual (encodeString s) (encodeInt i) + ]