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) + ]