Skip to content

Commit d218f6f

Browse files
authored
Merge pull request #153 from purescript/run-tests
Use new run function in tests
2 parents 816d8d4 + 7d497e6 commit d218f6f

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

test/Test/Data/Array/ST.purs

+16-20
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@ module Test.Data.Array.ST (testArrayST) where
22

33
import Prelude
44

5-
import Control.Monad.ST (ST)
65
import Control.Monad.ST as ST
7-
import Data.Array.ST (STArray, withArray)
6+
import Data.Array.ST (withArray)
87
import Data.Array.ST as STA
98
import Data.Foldable (all)
109
import Data.Maybe (Maybe(..), isNothing)
1110
import Effect (Effect)
1211
import Effect.Console (log)
1312
import Test.Assert (assert)
1413

15-
run :: forall a. (forall r. ST r (STArray r a)) -> Array a
16-
run act = ST.run (act >>= STA.unsafeFreeze)
17-
1814
testArrayST :: Effect Unit
1915
testArrayST = do
2016

@@ -34,11 +30,11 @@ testArrayST = do
3430

3531
log "empty should produce an empty array"
3632

37-
assert $ run STA.empty == nil
33+
assert $ STA.run STA.empty == nil
3834

3935
log "thaw should produce an STArray from a standard array"
4036

41-
assert $ run (STA.thaw [1, 2, 3]) == [1, 2, 3]
37+
assert $ STA.run (STA.thaw [1, 2, 3]) == [1, 2, 3]
4238

4339
log "freeze should produce a standard array from an STArray"
4440

@@ -48,17 +44,17 @@ testArrayST = do
4844

4945
log "unsafeThaw should produce an STArray from a standard array"
5046

51-
assert $ run (STA.unsafeThaw [1, 2, 3]) == [1, 2, 3]
47+
assert $ STA.run (STA.unsafeThaw [1, 2, 3]) == [1, 2, 3]
5248

5349
log "push should append a value to the end of the array"
5450

55-
assert $ run (do
51+
assert $ STA.run (do
5652
arr <- STA.empty
5753
void $ STA.push 1 arr
5854
void $ STA.push 2 arr
5955
pure arr) == [1, 2]
6056

61-
assert $ run (do
57+
assert $ STA.run (do
6258
arr <- STA.thaw [1, 2, 3]
6359
void $ STA.push 4 arr
6460
pure arr) == [1, 2, 3, 4]
@@ -71,12 +67,12 @@ testArrayST = do
7167

7268
log "pushAll should append multiple values to the end of the array"
7369

74-
assert $ run (do
70+
assert $ STA.run (do
7571
arr <- STA.empty
7672
void $ STA.pushAll [1, 2] arr
7773
pure arr) == [1, 2]
7874

79-
assert $ run (do
75+
assert $ STA.run (do
8076
arr <- STA.thaw [1, 2, 3]
8177
void $ STA.pushAll [4, 5, 6] arr
8278
pure arr) == [1, 2, 3, 4, 5, 6]
@@ -137,36 +133,36 @@ testArrayST = do
137133

138134
log "poke should replace the value at the specified index"
139135

140-
assert $ run (do
136+
assert $ STA.run (do
141137
arr <- STA.thaw [1]
142138
void $ STA.poke 0 10 arr
143139
pure arr) == [10]
144140

145141
log "poke should do nothing when attempting to modify a value outside the array bounds"
146142

147-
assert $ run (do
143+
assert $ STA.run (do
148144
arr <- STA.thaw [1]
149145
void $ STA.poke 1 2 arr
150146
pure arr) == [1]
151147

152148
log "sort should reorder a list into ascending order based on the result of compare"
153-
assert $ run (
149+
assert $ STA.run (
154150
STA.sort =<< STA.unsafeThaw [1, 3, 2, 5, 6, 4]
155151
) == [1, 2, 3, 4, 5, 6]
156152

157153
log "sortBy should reorder a list into ascending order based on the result of a comparison function"
158-
assert $ run (
154+
assert $ STA.run (
159155
STA.sortBy (flip compare) =<< STA.unsafeThaw [1, 3, 2, 5, 6, 4]
160156
) == [6, 5, 4, 3, 2, 1]
161157

162158
log "sortWith should reorder a list into ascending order based on the result of compare over a projection"
163-
assert $ run (
159+
assert $ STA.run (
164160
STA.sortWith identity =<< STA.unsafeThaw [1, 3, 2, 5, 6, 4]
165161
) == [1, 2, 3, 4, 5, 6]
166162

167163
log "splice should be able to delete multiple items at a specified index"
168164

169-
assert $ run (do
165+
assert $ STA.run (do
170166
arr <- STA.thaw [1, 2, 3, 4, 5]
171167
void $ STA.splice 1 3 [] arr
172168
pure arr) == [1, 5]
@@ -179,14 +175,14 @@ testArrayST = do
179175

180176
log "splice should be able to insert multiple items at a specified index"
181177

182-
assert $ run (do
178+
assert $ STA.run (do
183179
arr <- STA.thaw [1, 2, 3, 4, 5]
184180
void $ STA.splice 1 0 [0, 100] arr
185181
pure arr) == [1, 0, 100, 2, 3, 4, 5]
186182

187183
log "splice should be able to delete and insert at the same time"
188184

189-
assert $ run (do
185+
assert $ STA.run (do
190186
arr <- STA.thaw [1, 2, 3, 4, 5]
191187
void $ STA.splice 1 2 [0, 100] arr
192188
pure arr) == [1, 0, 100, 4, 5]

0 commit comments

Comments
 (0)