@@ -10,6 +10,7 @@ module Streamly.Test.Data.Array.Foreign (main) where
1010
1111#include "Streamly/Test/Data/Array/CommonImports.hs"
1212
13+import Data.Char (isLower)
1314import Data.Word(Word8)
1415
1516import qualified Streamly.Internal.Data.Fold as Fold
@@ -72,6 +73,48 @@ testLastN_LN len n = do
7273 let l2 = lastN n list
7374 return $ l1 == l2
7475
76+testStrip :: IO Bool
77+testStrip = do
78+ dt <- MA.fromList "abcDEFgeh"
79+ dt' <- MA.strip isLower dt
80+ x <- MA.toList dt'
81+ return $ x == "DEF"
82+
83+testStripLeft :: IO Bool
84+testStripLeft = do
85+ dt <- MA.fromList "abcDEF"
86+ dt' <- MA.strip isLower dt
87+ x <- MA.toList dt'
88+ return $ x == "DEF"
89+
90+testStripRight :: IO Bool
91+testStripRight = do
92+ dt <- MA.fromList "DEFgeh"
93+ dt' <- MA.strip isLower dt
94+ x <- MA.toList dt'
95+ return $ x == "DEF"
96+
97+testStripZero :: IO Bool
98+testStripZero = do
99+ dt <- MA.fromList "DEF"
100+ dt' <- MA.strip isLower dt
101+ x <- MA.toList dt'
102+ return $ x == "DEF"
103+
104+testStripEmpty :: IO Bool
105+testStripEmpty = do
106+ dt <- MA.fromList "abc"
107+ dt' <- MA.strip isLower dt
108+ x <- MA.toList dt'
109+ return $ x == ""
110+
111+testStripNull :: IO Bool
112+testStripNull = do
113+ dt <- MA.fromList ""
114+ dt' <- MA.strip isLower dt
115+ x <- MA.toList dt'
116+ return $ x == ""
117+
75118-- Instead of hard coding 10000 here we can have maxStreamLength for operations
76119-- that use stream of arrays.
77120concatArrayW8 :: Property
@@ -118,3 +161,10 @@ main =
118161 it "writeLastN 0" (testLastN_LN 10 0 `shouldReturn` True)
119162 it "writeLastN length" (testLastN_LN 10 10 `shouldReturn` True)
120163 it "writeLastN (length + 1)" (testLastN_LN 10 11 `shouldReturn` True)
164+ describe "Strip" $ do
165+ it "strip" (testStrip `shouldReturn` True)
166+ it "stripLeft" (testStripLeft `shouldReturn` True)
167+ it "stripRight" (testStripRight `shouldReturn` True)
168+ it "stripZero" (testStripZero `shouldReturn` True)
169+ it "stripEmpty" (testStripEmpty `shouldReturn` True)
170+ it "stripNull" (testStripNull `shouldReturn` True)