File: Main.hs

package info (click to toggle)
haskell-ini 0.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 76 kB
  • sloc: haskell: 250; makefile: 5
file content (74 lines) | stat: -rw-r--r-- 2,568 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{-# LANGUAGE OverloadedStrings #-}

-- | Simple test suite.

module Main where

import qualified Data.HashMap.Strict as HM
import           Data.Ini
import           Test.Hspec

main :: IO ()
main =
  hspec
    (do describe
          "Regular files"
          (do it
                "Multi-section file with comments"
                (shouldBe
                   (parseIni
                      "# Some comment.\n\
                      \[SERVER]\n\
                      \port=6667\n\
                      \hostname=localhost\n\
                      \[AUTH]\n\
                      \user=hello\n\
                      \pass=world\n\
                      \# Salt can be an empty string.\n\
                      \salt=")
                   (Right
                      (Ini
                         { iniSections =
                             HM.fromList
                               [ ( "AUTH"
                                 , [ ("user", "hello")
                                   , ("pass", "world")
                                   , ("salt", "")
                                   ])
                               , ( "SERVER"
                                 , [("port", "6667"), ("hostname", "localhost")])
                               ]
                         , iniGlobals = []
                         })))
              it
                "File with globals"
                (shouldBe
                   (parseIni
                      "# Some comment.\n\
                      \port=6667\n\
                      \hostname=localhost\n\
                      \[AUTH]\n\
                      \user=hello\n\
                      \pass=world\n\
                      \# Salt can be an empty string.\n\
                      \salt=")
                   (Right
                      (Ini
                         { iniSections =
                             HM.fromList
                               [ ( "AUTH"
                                 , [ ("user", "hello")
                                   , ("pass", "world")
                                   , ("salt", "")
                                   ])
                               ]
                         , iniGlobals =
                             [("port", "6667"), ("hostname", "localhost")]
                         })))
              it
                "File with invalid keys"
                (shouldBe
                   (parseIni
                      "Name=Foo\n\
                      \Name[en_GB]=Fubar")
                   (Left "Failed reading: Name[en_GB]=Fubar"))))