Skip to content

Commit 971eceb

Browse files
committed
Improve writeString related tests
1 parent 6c871e1 commit 971eceb

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

test/Hyper/Node/ServerSpec.purs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Control.Monad.Eff.Uncurried (EffFn1, runEffFn1)
99
import Data.Newtype (unwrap)
1010
import Data.String (length, take)
1111
import Hyper.Node.Server (writeString)
12-
import Node.Buffer (Buffer)
12+
import Node.Buffer (BUFFER, Buffer, toString)
1313
import Node.Encoding (Encoding(UTF8))
1414
import Node.Stream (Writable)
1515
import 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
5059
spec =
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

Comments
 (0)