Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reinier Maas
GHC
Commits
2004e3c8
Commit
2004e3c8
authored
2 years ago
by
Matthew Craven
Committed by
Marge Bot
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add a basic test for ByteArray's Monoid instance
parent
4ccefc6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
testsuite/tests/lib/base/Monoid_ByteArray.hs
+83
-0
83 additions, 0 deletions
testsuite/tests/lib/base/Monoid_ByteArray.hs
testsuite/tests/lib/base/all.T
+1
-0
1 addition, 0 deletions
testsuite/tests/lib/base/all.T
with
84 additions
and
0 deletions
testsuite/tests/lib/base/Monoid_ByteArray.hs
0 → 100644
+
83
−
0
View file @
2004e3c8
{-# LANGUAGE DerivingVia, TypeApplications, OverloadedLists #-}
module
Main
where
import
Control.Exception
import
Control.Monad
import
Data.Array.Byte
import
Data.Bits
import
Data.Either
import
Data.List
(
tails
)
import
Data.Ord
import
Data.Semigroup
import
GHC.Exts
(
IsList
(
..
))
newtype
Tricky
=
Tricky
Int
deriving
(
Eq
,
Num
,
Real
,
Enum
,
Integral
)
via
Int
deriving
Ord
via
Down
Int
smallArrs
::
[
ByteArray
]
-- 40 arrays, of total length 600
smallArrs
=
[
[]
,
[
3
,
8
,
1
],
[
0
],
[
255
],
[
1
,
6
,
1
,
8
,
2
]]
++
map
fromList
(
replicate
29
0
:
tails
[
0
..
32
])
shouldError
::
a
->
IO
()
->
IO
()
shouldError
val
ifNoError
=
do
res
<-
try
@
ErrorCall
(
evaluate
val
)
when
(
isRight
res
)
ifNoError
testConcat
::
[
ByteArray
]
->
IO
()
testConcat
arrs
=
do
let
lis
=
map
toList
arrs
expected
=
mconcat
lis
actual
=
toList
(
mconcat
arrs
)
when
(
expected
/=
actual
)
$
putStrLn
$
unwords
[
"mconcat"
,
show
lis
,
"/="
,
show
actual
]
main
::
IO
()
main
=
do
when
(
toList
@
ByteArray
mempty
/=
[]
)
$
putStrLn
"mempty /= []"
-- test <>
forM_
smallArrs
$
\
x
->
do
let
xli
=
toList
x
forM_
smallArrs
$
\
y
->
do
let
yli
=
toList
y
expected
=
xli
<>
yli
actual
=
toList
(
x
<>
y
)
when
(
expected
/=
actual
)
$
putStrLn
$
unwords
[
show
xli
,
"<>"
,
show
yli
,
"/="
,
show
actual
]
-- test stimes
forM_
smallArrs
$
\
x
->
do
let
xli
=
toList
x
shouldError
(
stimes
(
-
1
::
Integer
)
x
)
$
putStrLn
$
unwords
[
"stimes (-1 :: Integer)"
,
show
xli
,
"didn't fail??"
]
shouldError
(
stimes
(
-
1
::
Tricky
)
x
)
$
putStrLn
$
unwords
[
"stimes (-1 :: Tricky)"
,
show
xli
,
"didn't fail??"
]
when
(
length
xli
>
1
)
$
shouldError
(
stimes
(
maxBound
@
Int
)
x
)
$
putStrLn
$
unwords
[
"stimes (maxBound @Int)"
,
show
xli
,
"didn't fail??"
]
forM_
(
10000
:
[
0
::
Int
..
32
])
$
\
n
->
do
let
expected
=
stimes
n
xli
actual
=
toList
(
stimes
n
x
)
when
(
expected
/=
actual
)
$
putStrLn
$
unwords
[
"stimes"
,
show
n
,
show
xli
,
"/="
,
show
actual
]
evaluate
$
stimes
@
ByteArray
@
Int
maxBound
[]
evaluate
$
stimes
@
ByteArray
@
Integer
(
10
^
100
)
[]
-- test mconcat
testConcat
[]
forM_
smallArrs
$
\
x
->
do
testConcat
[
x
]
forM_
smallArrs
$
\
y
->
do
testConcat
[
x
,
y
]
forM_
smallArrs
$
\
z
->
do
-- OK, 40^3 = 64K
testConcat
[
x
,
y
,
z
]
-- test mconcat's overflow-handling
let
bigArr
=
stimes
(
bit
18
::
Int
)
[
0
]
::
ByteArray
when
(
finiteBitSize
@
Int
0
==
32
)
$
shouldError
(
mconcat
$
replicate
(
bit
14
)
bigArr
)
$
putStrLn
"Impossible mconcat succeeded???"
This diff is collapsed.
Click to expand it.
testsuite/tests/lib/base/all.T
+
1
−
0
View file @
2004e3c8
...
...
@@ -7,3 +7,4 @@ test('T19691', normal, compile, [''])
test
('
executablePath
',
extra_run_opts
(
config
.
os
),
compile_and_run
,
[''])
test
('
T17472
',
normal
,
compile_and_run
,
[''])
test
('
T19569b
',
normal
,
compile_and_run
,
[''])
test
('
Monoid_ByteArray
',
normal
,
compile_and_run
,
[''])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment