-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent runtime error for partial functions for ST arrays (#111)
* prevent runtime error for partial functions for ST arrays * add Data.Array.ST.Partial tests
- Loading branch information
Showing
4 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Test.Data.Array.ST.Partial (testArraySTPartial) where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff (Eff) | ||
import Control.Monad.Eff.Console (log, CONSOLE) | ||
import Control.Monad.ST (pureST) | ||
|
||
import Data.Array.ST (thaw, unsafeFreeze) | ||
import Data.Array.ST.Partial (peekSTArray, pokeSTArray) | ||
|
||
import Partial.Unsafe (unsafePartial) | ||
|
||
import Test.Assert (assert, ASSERT) | ||
|
||
testArraySTPartial :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit | ||
testArraySTPartial = do | ||
|
||
log "peekSTArray should return the value at the specified index" | ||
assert $ 2 == pureST do | ||
a <- thaw [1, 2, 3] | ||
unsafePartial $ peekSTArray a 1 | ||
|
||
log "pokeSTArray should modify the value at the specified index" | ||
assert $ [1, 4, 3] == pureST do | ||
a <- thaw [1, 2, 3] | ||
unsafePartial $ pokeSTArray a 1 4 | ||
unsafeFreeze a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters