Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
Packages
text
Commits
9722f0e5
Commit
9722f0e5
authored
Dec 05, 2014
by
bos
Browse files
Extract Unicode test code into its own package
parent
231bc1f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
tests/Tests/QuickCheckUtils.hs
View file @
9722f0e5
...
...
@@ -7,14 +7,6 @@
module
Tests.QuickCheckUtils
(
genUnicode
,
genUnicodeWith
,
ascii
,
plane0
,
plane1
,
plane2
,
plane14
,
planes
,
unsquare
,
smallArbitrary
...
...
@@ -43,8 +35,6 @@ import Control.Applicative ((<$>))
import
Control.Arrow
(
first
,
(
***
))
import
Control.DeepSeq
(
NFData
(
..
),
deepseq
)
import
Control.Exception
(
bracket
)
import
Data.Bits
((
.&.
))
import
Data.Char
(
chr
)
import
Data.String
(
IsString
,
fromString
)
import
Data.Text.Foreign
(
I16
)
import
Data.Word
(
Word8
,
Word16
)
...
...
@@ -52,6 +42,7 @@ import Debug.Trace (trace)
import
System.Random
(
Random
(
..
),
RandomGen
)
import
Test.QuickCheck
hiding
(
Small
(
..
),
(
.&.
))
import
Test.QuickCheck.Monadic
(
assert
,
monadicIO
,
run
)
import
Test.QuickCheck.Unicode
(
string
)
import
Tests.Utils
import
qualified
Data.ByteString
as
B
import
qualified
Data.Text
as
T
...
...
@@ -68,6 +59,9 @@ import Data.Int (Int64)
import
Data.Word
(
Word
,
Word64
)
#
endif
genUnicode
::
IsString
a
=>
Gen
a
genUnicode
=
fromString
<$>
string
instance
Random
I16
where
randomR
=
integralRandomR
random
=
randomR
(
minBound
,
maxBound
)
...
...
@@ -98,71 +92,6 @@ instance Random Word64 where
random
=
randomR
(
minBound
,
maxBound
)
#
endif
genUnicode
::
IsString
a
=>
Gen
a
genUnicode
=
genUnicodeWith
planes
genUnicodeWith
::
IsString
a
=>
[
Gen
Int
]
->
Gen
a
genUnicodeWith
gens
=
fmap
fromString
string
where
string
=
sized
$
\
n
->
do
k
<-
choose
(
0
,
n
)
sequence
[
char
|
_
<-
[
1
..
k
]
]
excluding
::
[
a
->
Bool
]
->
Gen
a
->
Gen
a
excluding
bad
gen
=
loop
where
loop
=
do
x
<-
gen
if
or
(
map
(
$
x
)
bad
)
then
loop
else
return
x
reserved
=
[
lowSurrogate
,
highSurrogate
,
noncharacter
]
lowSurrogate
c
=
c
>=
0xDC00
&&
c
<=
0xDFFF
highSurrogate
c
=
c
>=
0xD800
&&
c
<=
0xDBFF
noncharacter
c
=
masked
==
0xFFFE
||
masked
==
0xFFFF
where
masked
=
c
.&.
0xFFFF
char
=
chr
`
fmap
`
excluding
reserved
(
oneof
gens
)
ascii
::
Gen
Int
ascii
=
choose
(
0
,
0x7F
)
plane0
::
Gen
Int
plane0
=
choose
(
0xF0
,
0xFFFF
)
plane1
::
Gen
Int
plane1
=
oneof
[
choose
(
0x10000
,
0x10FFF
)
,
choose
(
0x11000
,
0x11FFF
)
,
choose
(
0x12000
,
0x12FFF
)
,
choose
(
0x13000
,
0x13FFF
)
,
choose
(
0x1D000
,
0x1DFFF
)
,
choose
(
0x1F000
,
0x1FFFF
)
]
plane2
::
Gen
Int
plane2
=
oneof
[
choose
(
0x20000
,
0x20FFF
)
,
choose
(
0x21000
,
0x21FFF
)
,
choose
(
0x22000
,
0x22FFF
)
,
choose
(
0x23000
,
0x23FFF
)
,
choose
(
0x24000
,
0x24FFF
)
,
choose
(
0x25000
,
0x25FFF
)
,
choose
(
0x26000
,
0x26FFF
)
,
choose
(
0x27000
,
0x27FFF
)
,
choose
(
0x28000
,
0x28FFF
)
,
choose
(
0x29000
,
0x29FFF
)
,
choose
(
0x2A000
,
0x2AFFF
)
,
choose
(
0x2B000
,
0x2BFFF
)
,
choose
(
0x2F000
,
0x2FFFF
)
]
plane14
::
Gen
Int
plane14
=
choose
(
0xE0000
,
0xE0FFF
)
planes
::
[
Gen
Int
]
planes
=
[
ascii
,
plane0
,
plane1
,
plane2
,
plane14
]
-- For tests that have O(n^2) running times or input sizes, resize
-- their inputs to the square root of the originals.
unsquare
::
(
Arbitrary
a
,
Show
a
,
Testable
b
)
=>
(
a
->
b
)
->
Property
...
...
tests/text-tests.cabal
View file @
9722f0e5
...
...
@@ -51,6 +51,7 @@ executable text-tests
bytestring,
deepseq,
directory,
quickcheck-unicode,
random,
test-framework >= 0.4,
test-framework-hunit >= 0.2,
...
...
text.cabal
View file @
9722f0e5
...
...
@@ -169,6 +169,7 @@ test-suite tests
deepseq,
directory,
ghc-prim,
quickcheck-unicode,
random,
test-framework >= 0.4,
test-framework-hunit >= 0.2,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment