git.iko.soy/rowtype-yoga/purescript-yoga-fetch-om
on main help sign in
32 lines 932 B history raw
1module StreamDecode.Spec where
3import Prelude
5import Data.ArrayBuffer.Types (Uint8Array)
6import Data.String as String
7import Effect.Aff (Aff)
8import Effect.Class (liftEffect)
9import Effect.Exception (throwException)
10import Test.Spec (Spec, describe, it)
11import Test.Spec.Assertions (shouldEqual)
12import Yoga.Fetch.Om.StreamDecode (decodeStream)
13import Yoga.Om (Om)
14import Yoga.Om as Om
15import Yoga.Om.Strom as Strom
17foreign import uint8Array :: Array Int -> Uint8Array
19runOm :: forall a. Om {} () a -> Aff a
20runOm om = Om.runOm {} { exception: \err -> liftEffect (throwException err) } om
22spec :: Spec Unit
23spec = describe "StreamDecode" do
24 it "preserves UTF-8 code points split across chunks" do
25 chunks <- runOm $
26 Strom.fromArray
27 [ uint8Array [ 0xe2 ]
28 , uint8Array [ 0x82, 0xac ]
29 ]
30 # decodeStream @String
31 # Strom.runCollect
32 String.joinWith "" chunks `shouldEqual` "€"