Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions copilot-core/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2026-10-11
* Increase test coverage for `Copilot.Core.Type.Array`. (#767)

2026-09-07
* Version bump (4.8.1). (#760)

Expand Down
2 changes: 1 addition & 1 deletion copilot-core/src/Copilot/Core/Type/Array.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ array xs | datalen == typelen = Array xs
| otherwise = error errmsg
where
datalen = length xs
typelen = fromIntegral $ natVal (Proxy :: Proxy n)
typelen = fromIntegral $ natVal $! (Proxy :: Proxy n)
errmsg = "Length of data (" ++ show datalen ++
") does not match length of type (" ++ show typelen ++ ")."

Expand Down
20 changes: 18 additions & 2 deletions copilot-core/tests/Test/Copilot/Core/Type/Array.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import Test.Framework (Test, testGroup)
import Test.Framework.Providers.QuickCheck2 (testProperty)
import Test.QuickCheck (Gen, Property, arbitrary,
chooseInt, expectFailure, forAll,
getNegative, getNonNegative, oneof,
property, vector, vectorOf)
getNegative, getNonNegative,
listOf, oneof, property, vector,
vectorOf)

-- Internal imports: library modules being tested
import Copilot.Core.Type.Array (Array, array, arrayElems, arrayUpdate)
Expand All @@ -31,6 +32,10 @@ tests =
testArrayElemsFail
, testProperty "Show for arrays"
testShowArray
, testProperty "showsPrec for arrays"
testShowsPrecArray
, testProperty "showList for arrays"
testShowListArray
, testProperty "arrayElems (arrayUpdate x i v) !! i == v"
(testArrayUpdateElem (Proxy :: Proxy 5))
, testProperty "arrayUpdate x i ((arrayElems x) !! i) == x"
Expand Down Expand Up @@ -70,6 +75,17 @@ testShowArray :: Property
testShowArray = forAll (vector 3) $ \l -> property $
show (array l :: Array 3 Int64) == show (l :: [Int64])

-- | Test 'Show.showsPrec' for 'Array's.
testShowsPrecArray :: Property
testShowsPrecArray = forAll (getNonNegative <$> arbitrary) $ \prec ->
forAll (vector 3) $ \l -> property $
showsPrec prec (array l :: Array 3 Int64) "" == show (l :: [Int64])

-- | Test 'Show.showList' for 'Array's.
testShowListArray :: Property
testShowListArray = forAll (listOf $ vector 3) $ \l -> property $
showList (map array l :: [Array 3 Int64]) "" == show (l :: [[Int64]])

-- | Test that updating an array updates the element appropriately (if we
-- project that element we get the value we put in).
testArrayUpdateElem :: forall n . KnownNat n => Proxy n -> Property
Expand Down