Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
utf8-string
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
utf8-string
Commits
a82e06b4
Unverified
Commit
a82e06b4
authored
7 years ago
by
glguy
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #25 from gwils/test-warnings
Fix test warnings and wire up encode/decode test
parents
90387939
4b357795
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/Tests.hs
+28
-2
28 additions, 2 deletions
tests/Tests.hs
with
28 additions
and
2 deletions
tests/Tests.hs
+
28
−
2
View file @
a82e06b4
import
Codec.Binary.UTF8.String
import
Test.HUnit
import
Test.HUnit
(
Test
(
TestCase
,
TestList
,
TestLabel
),
assertEqual
,
errors
,
failures
,
runTestTT
)
import
System.Exit
(
exitFailure
)
import
Control.Monad
(
when
)
main
::
IO
()
main
=
do
counts
<-
runTestTT
tests
when
(
errors
counts
>
0
||
failures
counts
>
0
)
exitFailure
tests
=
TestList
[
test_1
,
test_2
,
test_3
,
test_4
,
test_5
]
tests
::
Test
tests
=
TestList
[
test_1
,
test_2
,
test_3
,
test_4
,
test_5
,
test_6
]
test_1
::
Test
test_1
=
TestLabel
"1 Some correct UTF-8 text"
$
TestCase
$
assertEqual
"kosme, "
"
\x03ba\x1f79\x03c3\x03bc\x03b5
"
(
decode
[
0xce
,
0xba
,
0xe1
,
0xbd
,
0xb9
,
0xcf
,
0x83
,
0xce
,
0xbc
,
0xce
,
0xb5
,
0x20
])
test_2
::
Test
test_2
=
TestLabel
"2 Boundary condition test cases"
$
TestList
[
test_2_1
,
test_2_2
,
test_2_3
]
test_2_1
::
Test
test_2_1
=
TestLabel
"2.1 First possible sequence of a certain length"
$
TestList
$
map
TestCase
$
[
assertEqual
"2.1.1, "
"
\0\0
"
(
decode
[
0
,
0
])
...
...
@@ -25,6 +30,7 @@ test_2_1 = TestLabel "2.1 First possible sequence of a certain length" $
,
assertEqual
"2.1.6, "
"
\xfffd\0
"
(
decode
[
0xfc
,
0x84
,
0x80
,
0x80
,
0x80
,
0x80
,
0
])
]
test_2_2
::
Test
test_2_2
=
TestLabel
"2.2 Last possible sequence of a certain length"
$
TestList
$
map
TestCase
$
[
assertEqual
"2.2.1, "
"
\x7f\0
"
(
decode
[
0x7f
,
0
])
...
...
@@ -35,6 +41,7 @@ test_2_2 = TestLabel "2.2 Last possible sequence of a certain length" $
,
assertEqual
"2.2.6, "
"
\xfffd\0
"
(
decode
[
0xfd
,
0xbf
,
0xbf
,
0xbf
,
0xbf
,
0xbf
,
0
])
]
test_2_3
::
Test
test_2_3
=
TestLabel
"2.3 Other boundary conditions"
$
TestList
$
map
TestCase
$
[
assertEqual
"2.3.1, "
"
\xd7ff\0
"
(
decode
[
0xed
,
0x9f
,
0xbf
,
0
])
...
...
@@ -44,9 +51,11 @@ test_2_3 = TestLabel "2.3 Other boundary conditions" $
,
assertEqual
"2.3.5, "
"
\xfffd\0
"
(
decode
[
0xf4
,
0x90
,
0x80
,
0x80
,
0
])
]
test_3
::
Test
test_3
=
TestLabel
"3 Malformed sequences"
$
TestList
[
test_3_1
,
test_3_2
,
test_3_3
,
test_3_4
,
test_3_5
]
test_3_1
::
Test
test_3_1
=
TestLabel
"3.1 Unexpected continuation bytes"
$
TestList
$
map
TestCase
$
[
assertEqual
"3.1.1, "
"
\xfffd\0
"
(
decode
[
0x80
,
0
])
...
...
@@ -64,6 +73,7 @@ test_3_1 = TestLabel "3.1 Unexpected continuation bytes" $
,
assertEqual
"3.1.9, "
(
replicate
64
'
\xfffd
'
)
(
decode
[
0x80
..
0xbf
])
]
test_3_2
::
Test
test_3_2
=
TestLabel
"3.2 Lonely start characters"
$
TestList
$
map
TestCase
$
[
assertEqual
"3.2.1, "
(
concat
(
replicate
32
"
\xfffd
"
))
...
...
@@ -77,6 +87,7 @@ test_3_2 = TestLabel "3.2 Lonely start characters" $
,
assertEqual
"3.2.5, "
"
\xfffd
\xfffd
"
(
decode
[
0xfc
,
0x20
,
0xfd
,
0x20
])
]
test_3_3
::
Test
test_3_3
=
TestLabel
"3.3 Sequences with last continuation byte missing"
$
TestList
$
map
TestCase
$
[
assertEqual
"3.3.1, "
"
\xfffd
"
(
decode
[
0xc0
,
0x20
])
...
...
@@ -91,6 +102,7 @@ test_3_3 = TestLabel "3.3 Sequences with last continuation byte missing" $
,
assertEqual
"3.3.10, "
"
\xfffd
"
(
decode
[
0xfd
,
0xbf
,
0xbf
,
0xbf
,
0xbf
,
0x20
])
]
test_3_4
::
Test
test_3_4
=
TestLabel
"3.4 Concatenation of incomplete sequences"
$
TestCase
$
assertEqual
"3.4, "
(
replicate
10
'
\xfffd
'
)
...
...
@@ -98,6 +110,7 @@ test_3_4 = TestLabel "3.4 Concatenation of incomplete sequences" $
0xfc
,
0x80
,
0x80
,
0x80
,
0x80
,
0xdf
,
0xef
,
0xbf
,
0xf7
,
0xbf
,
0xbf
,
0xfb
,
0xbf
,
0xbf
,
0xbf
,
0xfd
,
0xbf
,
0xbf
,
0xbf
,
0xbf
])
test_3_5
::
Test
test_3_5
=
TestLabel
"3.5 Impossible bytes"
$
TestList
$
map
TestCase
$
[
assertEqual
"3.5.1, "
"
\xfffd
"
(
decode
[
0xfe
,
0x20
])
...
...
@@ -106,9 +119,11 @@ test_3_5 = TestLabel "3.5 Impossible bytes" $
(
decode
[
0xfe
,
0xfe
,
0xff
,
0xff
,
0x20
])
]
test_4
::
Test
test_4
=
TestLabel
"4 Overlong sequences"
$
TestList
[
test_4_1
,
test_4_2
,
test_4_3
]
test_4_1
::
Test
test_4_1
=
TestLabel
"4.1"
$
TestList
$
map
TestCase
$
[
assertEqual
"4.1.1, "
"
\xfffd
"
(
decode
[
0xc0
,
0xaf
,
0x20
])
,
assertEqual
"4.1.2, "
"
\xfffd
"
(
decode
[
0xe0
,
0x80
,
0xaf
,
0x20
])
...
...
@@ -117,6 +132,7 @@ test_4_1 = TestLabel "4.1" $ TestList $ map TestCase $
,
assertEqual
"4.1.5, "
"
\xfffd
"
(
decode
[
0xfc
,
0x80
,
0x80
,
0x80
,
0x80
,
0xaf
,
0x20
])
]
test_4_2
::
Test
test_4_2
=
TestLabel
"4.2 Maximum overlong sequences"
$
TestList
$
map
TestCase
$
[
assertEqual
"4.2.1, "
"
\xfffd
"
(
decode
[
0xc1
,
0xbf
,
0x20
])
...
...
@@ -126,6 +142,7 @@ test_4_2 = TestLabel "4.2 Maximum overlong sequences" $
,
assertEqual
"4.2.5, "
"
\xfffd
"
(
decode
[
0xfc
,
0x83
,
0xbf
,
0xbf
,
0xbf
,
0xbf
,
0x20
])
]
test_4_3
::
Test
test_4_3
=
TestLabel
"4.2 Overlong NUL"
$
TestList
$
map
TestCase
$
[
assertEqual
"4.3.1, "
"
\xfffd
"
(
decode
[
0xc0
,
0x80
,
0x20
])
...
...
@@ -135,9 +152,11 @@ test_4_3 = TestLabel "4.2 Overlong NUL" $
,
assertEqual
"4.3.5, "
"
\xfffd
"
(
decode
[
0xfc
,
0x80
,
0x80
,
0x80
,
0x80
,
0x80
,
0x20
])
]
test_5
::
Test
test_5
=
TestLabel
"Illegal code positions"
$
TestList
[
test_5_1
,
test_5_2
,
test_5_3
]
test_5_1
::
Test
test_5_1
=
TestLabel
"5.1 Single UTF-16 surrogates"
$
TestList
$
map
TestCase
$
[
assertEqual
"5.1.1, "
"
\xfffd
"
(
decode
[
0xed
,
0xa0
,
0x80
,
0x20
])
...
...
@@ -149,6 +168,7 @@ test_5_1 = TestLabel "5.1 Single UTF-16 surrogates" $
,
assertEqual
"5.1.7, "
"
\xfffd
"
(
decode
[
0xed
,
0xbf
,
0xbf
,
0x20
])
]
test_5_2
::
Test
test_5_2
=
TestLabel
"5.2 Paired UTF-16 surrogates"
$
TestList
$
map
TestCase
$
[
assertEqual
"5.2.1, "
res
(
decode
[
0xed
,
0xa0
,
0x80
,
0xed
,
0xb0
,
0x80
,
0x20
])
...
...
@@ -162,12 +182,18 @@ test_5_2 = TestLabel "5.2 Paired UTF-16 surrogates" $
]
where
res
=
"
\xfffd\xfffd
"
test_5_3
::
Test
test_5_3
=
TestLabel
"5.3 Other illegal code positions"
$
TestList
$
map
TestCase
$
[
assertEqual
"5.3.1, "
"
\xfffd
"
(
decode
[
0xef
,
0xbf
,
0xbe
,
0x20
])
,
assertEqual
"5.3.2, "
"
\xfffd
"
(
decode
[
0xef
,
0xbf
,
0xbf
,
0x20
])
]
test_6
::
Test
test_6
=
TestLabel
"Encode then decode"
$
TestList
$
map
TestCase
$
[
assertEqual
"6.1"
encodeDecodeTest
[]
]
--
-- test decode . encode == id for the class of chars we know that to be true of
...
...
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