@@ -9,7 +9,7 @@ import Control.Monad.Eff.Uncurried (EffFn1, runEffFn1)
99import Data.Newtype (unwrap )
1010import Data.String (length , take )
1111import Hyper.Node.Server (writeString )
12- import Node.Buffer (Buffer )
12+ import Node.Buffer (BUFFER , Buffer , toString )
1313import Node.Encoding (Encoding (UTF8))
1414import Node.Stream (Writable )
1515import Test.Spec (Spec , describe , it )
@@ -46,23 +46,26 @@ buildTestString totalLength = do
4646 | len * 2 < totalLength = go (str <> str) (len * 2 )
4747 | otherwise = str <> take (totalLength - len) str
4848
49- spec :: forall eff . Spec eff Unit
49+ testWriter :: forall eff . String -> Aff ( buffer :: BUFFER | eff ) Unit
50+ testWriter str = do
51+ output ← liftEff $ memoryWritableStream 10
52+ let writer = unwrap $ writeString UTF8 str
53+ writer (toWritable output)
54+ buffer ← liftEff $ streamBuffer output
55+ str' ← liftEff $ toString UTF8 buffer
56+ str' `shouldEqual` str
57+
58+ spec :: forall eff . Spec (buffer ∷ BUFFER | eff ) Unit
5059spec =
5160 describe " Hyper.Node.Server" do
5261 describe " writeString" do
5362 it " handles empty string" do
54- output ← liftEff $ memoryWritableStream 10
55- let writer = unwrap $ writeString UTF8 " "
56- writer (toWritable output)
63+ testWriter " "
5764
5865 it " handles short (< 16 KB) string" do
59- output ← liftEff $ memoryWritableStream 10
6066 str ← buildTestString 3000
61- let writer = unwrap $ writeString UTF8 str
62- writer (toWritable output)
67+ testWriter str
6368
6469 it " handles long (> 64 KB) string" do
6570 str ← buildTestString 65000
66- output ← liftEff $ memoryWritableStream 10
67- let writer = unwrap $ writeString UTF8 str
68- writer (toWritable output)
71+ testWriter str
0 commit comments