Revision 43b3b5c1

b/Makefile.am
473 473
	htools/Ganeti/Utils.hs
474 474

  
475 475
HS_TEST_SRCS = \
476
	htest/Test/Ganeti/Attoparsec.hs \
476 477
	htest/Test/Ganeti/BasicTypes.hs \
477 478
	htest/Test/Ganeti/Common.hs \
478 479
	htest/Test/Ganeti/Confd/Utils.hs \
b/htest/Test/Ganeti/Attoparsec.hs
1
{-# LANGUAGE TemplateHaskell #-}
2

  
3
{-| Unittests for Attoparsec support for unicode -}
4

  
5
{-
6

  
7
Copyright (C) 2012 Google Inc.
8

  
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
13

  
14
This program is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
General Public License for more details.
18

  
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
02110-1301, USA.
23

  
24
-}
25

  
26
module Test.Ganeti.Attoparsec (testAttoparsec) where
27

  
28
import Test.QuickCheck
29

  
30
import Test.Ganeti.TestHelper
31
import Test.Ganeti.TestCommon
32

  
33
import qualified Data.Attoparsec.Text as A
34
import Data.Attoparsec.Text (Parser)
35
import Data.Text (pack, unpack)
36

  
37
-- | Unicode test string, first part.
38
part1 :: String
39
part1 = "äßĉ"
40

  
41
-- | Unicode test string, second part.
42
part2 :: String
43
part2 = "ðèق"
44

  
45
-- | Simple parser able to split a string in two parts, name and
46
-- value, separated by a '=' sign.
47
simpleParser :: Parser (String, String)
48
simpleParser = do
49
  n <- A.takeTill (\c -> A.isHorizontalSpace c || c == '=')
50
  A.skipWhile A.isHorizontalSpace
51
  _ <- A.char '='
52
  A.skipWhile A.isHorizontalSpace
53
  v <- A.takeTill A.isEndOfLine
54
  return (unpack n, unpack v)
55

  
56
-- | Tests whether a Unicode string is still Unicode after being
57
-- parsed.
58
prop_parserSupportsUnicode :: Property
59
prop_parserSupportsUnicode = case A.parseOnly simpleParser text of
60
    Right (name, value) -> (name ==? part1) .&&. (value ==? part2)
61
    Left msg -> failTest $ "Failed to parse: " ++ msg
62
  where text = Data.Text.pack $ part1 ++ "  = \t" ++ part2
63

  
64
testSuite "Attoparsec"
65
          [ 'prop_parserSupportsUnicode
66
          ]
b/htest/test.hs
30 30
import System.Environment (getArgs)
31 31

  
32 32
import Test.Ganeti.TestImports ()
33
import Test.Ganeti.Attoparsec
33 34
import Test.Ganeti.BasicTypes
34 35
import Test.Ganeti.Common
35 36
import Test.Ganeti.Confd.Utils
......
74 75
allTests :: [Test]
75 76
allTests =
76 77
  [ testBasicTypes
78
  , testAttoparsec
77 79
  , testCommon
78 80
  , testConfd_Utils
79 81
  , testDaemon

Also available in: Unified diff