git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
36 lines 814 B history raw
1-- @inline export testArrayIndex never
2module Snapshot.InlineArrayIndex where
4import Prelude
6import Assert (assertEqual)
7import Data.Array as Array
8import Data.Maybe (Maybe(..))
9import Effect (Effect)
11testArrayIndex :: forall a. Array a -> Int -> Maybe a
12testArrayIndex arr ix = Array.index arr ix
14main :: Effect Unit
15main = do
16 let array = [ 1, 2, 3 ]
17 assertEqual "index -1"
18 { expected: Nothing
19 , actual: testArrayIndex array (-1)
20 }
21 assertEqual "index 0"
22 { expected: Just 1
23 , actual: testArrayIndex array 0
24 }
25 assertEqual "index 1"
26 { expected: Just 2
27 , actual: testArrayIndex array 1
28 }
29 assertEqual "index 2"
30 { expected: Just 3
31 , actual: testArrayIndex array 2
32 }
33 assertEqual "index 3"
34 { expected: Nothing
35 , actual: testArrayIndex array 3
36 }