File: Windows.hs

package info (click to toggle)
haskell-path 0.9.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 432 kB
  • sloc: haskell: 3,246; makefile: 3
file content (164 lines) | stat: -rw-r--r-- 7,845 bytes parent folder | download
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
{-# LANGUAGE LambdaCase          #-}
{-# LANGUAGE QuasiQuotes         #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell     #-}

-- | Test suite.

module Windows (spec) where

import Test.Hspec

import Common.Windows (parseFails, parseSucceeds, parserTest)
import qualified Common.Windows
import OsPath.Windows
import OsPath.Internal.Windows
import qualified System.OsString.Compat.Windows as OsString
import TH.Windows ()

-- | Test suite (Windows version).
spec :: Spec
spec =
  do describe "Parsing: Path Abs Dir" parseAbsDirSpec
     describe "Parsing: Path Rel Dir" parseRelDirSpec
     describe "Parsing: Path Abs File" parseAbsFileSpec
     describe "Parsing: Path Rel File" parseRelFileSpec
     Common.Windows.spec
     describe "Restrictions" restrictions
     describe "QuasiQuotes" quasiquotes

-- | Restricting the input of any tricks.
restrictions :: Spec
restrictions =
  do parseFails [OsString.pstr|..\|]
     parseFails [OsString.pstr|..|]
     parseSucceeds [OsString.pstr|a..|] (Path [OsString.pstr|a..\|])
     parseSucceeds [OsString.pstr|..a|] (Path [OsString.pstr|..a\|])
     parseFails [OsString.pstr|\..|]
     parseFails [OsString.pstr|C:\foo\..\bar\|]
     parseFails [OsString.pstr|C:\foo\bar\..|]

-- | Tests for the tokenizer.
parseAbsDirSpec :: Spec
parseAbsDirSpec =
  do failing [OsString.pstr||]
     failing [OsString.pstr|.\|]
     failing [OsString.pstr|foo.txt|]
     failing [OsString.pstr|C:|]
     succeeding [OsString.pstr|C:\|] (Path [OsString.pstr|C:\|])
     succeeding [OsString.pstr|C:\\|] (Path [OsString.pstr|C:\|])
     succeeding [OsString.pstr|C:\\\foo\\bar\\mu\|] (Path [OsString.pstr|C:\foo\bar\mu\|])
     succeeding [OsString.pstr|C:\\\foo\\bar\\mu|] (Path [OsString.pstr|C:\foo\bar\mu\|])
     succeeding [OsString.pstr|C:\\\foo\\bar\.\\mu|] (Path [OsString.pstr|C:\foo\bar\mu\|])
     succeeding [OsString.pstr|\\unchost\share|] (Path [OsString.pstr|\\unchost\share\|])
     succeeding [OsString.pstr|\/unchost\share|] (Path [OsString.pstr|\\unchost\share\|])
     succeeding [OsString.pstr|\\unchost\share\\folder\|] (Path [OsString.pstr|\\unchost\share\folder\|])
     succeeding [OsString.pstr|\\?\C:\|] (Path [OsString.pstr|\\?\C:\|])
     succeeding [OsString.pstr|/\?\C:\|] (Path [OsString.pstr|\\?\C:\|])
     succeeding [OsString.pstr|\\?\C:\\\folder\\|] (Path [OsString.pstr|\\?\C:\folder\|])

  where failing x = parserTest parseAbsDir x Nothing
        succeeding x with = parserTest parseAbsDir x (Just with)

-- | Tests for the tokenizer.
parseRelDirSpec :: Spec
parseRelDirSpec =
  do failing [OsString.pstr||]
     failing [OsString.pstr|/|]
     failing [OsString.pstr|//|]
     failing [OsString.pstr|\|]
     failing [OsString.pstr|\\|]
     failing [OsString.pstr|\\\foo\\bar\\mu\|]
     failing [OsString.pstr|\\\foo\\bar\\\\mu|]
     failing [OsString.pstr|\\\foo\\bar\.\\mu|]
     failing [OsString.pstr|\\unchost\share|]
     failing [OsString.pstr|\\?\C:\|]
     succeeding [OsString.pstr|.\|] (Path [OsString.pstr||])
     succeeding [OsString.pstr|.\.\|] (Path [OsString.pstr||])
     succeeding [OsString.pstr|...|] (Path [OsString.pstr|...\|])
     succeeding [OsString.pstr|foo.bak|] (Path [OsString.pstr|foo.bak\|])
     succeeding [OsString.pstr|.\foo|] (Path [OsString.pstr|foo\|])
     succeeding [OsString.pstr|.\.\foo|] (Path [OsString.pstr|foo\|])
     succeeding [OsString.pstr|.\foo\.\bar|] (Path [OsString.pstr|foo\bar\|])
     succeeding [OsString.pstr|foo\\bar\\mu\\|] (Path [OsString.pstr|foo\bar\mu\|])
     succeeding [OsString.pstr|foo\\bar////mu|] (Path [OsString.pstr|foo\bar\mu\|])
     succeeding [OsString.pstr|foo\\bar\.\\mu|] (Path [OsString.pstr|foo\bar\mu\|])

  where failing x = parserTest parseRelDir x Nothing
        succeeding x with = parserTest parseRelDir x (Just with)

-- | Tests for the tokenizer.
parseAbsFileSpec :: Spec
parseAbsFileSpec =
  do failing [OsString.pstr||]
     failing [OsString.pstr|.\|]
     failing [OsString.pstr|\.|]
     failing [OsString.pstr|\foo\bar\.|]
     failing [OsString.pstr|~\|]
     failing [OsString.pstr|.\foo.txt|]
     failing [OsString.pstr|\|]
     failing [OsString.pstr|\\|]
     failing [OsString.pstr|\\\foo\\bar\\mu\|]
     failing [OsString.pstr|\...|]
     failing [OsString.pstr|\foo.txt|]
     succeeding [OsString.pstr|C:\\\foo\\bar\\\\mu.txt|] (Path [OsString.pstr|C:\foo\bar\mu.txt|])
     succeeding [OsString.pstr|C:\\\foo\\bar\.\\mu.txt|] (Path [OsString.pstr|C:\foo\bar\mu.txt|])
     succeeding [OsString.pstr|\\unchost\share\\file.txt|] (Path [OsString.pstr|\\unchost\share\file.txt|])
     succeeding [OsString.pstr|\/unchost\share\\file.txt|] (Path [OsString.pstr|\\unchost\share\file.txt|])
     succeeding [OsString.pstr|\\unchost\share\.\folder\\\file.txt|] (Path [OsString.pstr|\\unchost\share\folder\file.txt|])
     succeeding [OsString.pstr|\\?\C:\file.txt|] (Path [OsString.pstr|\\?\C:\file.txt|])
     succeeding [OsString.pstr|/\?\C:\file.txt|] (Path [OsString.pstr|\\?\C:\file.txt|])
     succeeding [OsString.pstr|\\?\C:\\\folder\.\\file.txt|] (Path [OsString.pstr|\\?\C:\folder\file.txt|])

  where failing x = parserTest parseAbsFile x Nothing
        succeeding x with = parserTest parseAbsFile x (Just with)

-- | Tests for the tokenizer.
parseRelFileSpec :: Spec
parseRelFileSpec =
  do failing [OsString.pstr||]
     failing [OsString.pstr|\|]
     failing [OsString.pstr|\\|]
     failing [OsString.pstr|~\|]
     failing [OsString.pstr|\|]
     failing [OsString.pstr|.\|]
     failing [OsString.pstr|a\.|]
     failing [OsString.pstr|a\..\b|]
     failing [OsString.pstr|a\..|]
     failing [OsString.pstr|..\foo.txt|]
     failing [OsString.pstr|\\|]
     failing [OsString.pstr|\\\foo\\bar\\mu\|]
     failing [OsString.pstr|\\\foo\\bar\\\\mu|]
     failing [OsString.pstr|\\\foo\\bar\.\\mu|]
     failing [OsString.pstr|\\unchost\share\\file.txt|]
     failing [OsString.pstr|\\?\C:\file.txt|]
     succeeding [OsString.pstr|a..|] (Path [OsString.pstr|a..|])
     succeeding [OsString.pstr|...|] (Path [OsString.pstr|...|])
     succeeding [OsString.pstr|foo.txt|] (Path [OsString.pstr|foo.txt|])
     succeeding [OsString.pstr|.\foo.txt|] (Path [OsString.pstr|foo.txt|])
     succeeding [OsString.pstr|.\.\foo.txt|] (Path [OsString.pstr|foo.txt|])
     succeeding [OsString.pstr|.\foo\.\bar.txt|] (Path [OsString.pstr|foo\bar.txt|])
     succeeding [OsString.pstr|foo\\bar\\mu.txt|] (Path [OsString.pstr|foo\bar\mu.txt|])
     succeeding [OsString.pstr|foo\\bar\\\\mu.txt|] (Path [OsString.pstr|foo\bar\mu.txt|])
     succeeding [OsString.pstr|foo\\bar\.\\mu.txt|] (Path [OsString.pstr|foo\bar\mu.txt|])

  where failing x = parserTest parseRelFile x Nothing
        succeeding x with = parserTest parseRelFile x (Just with)

-- | Test QuasiQuoters. Make sure they work the same as the $(mk*) constructors.
quasiquotes :: Spec
quasiquotes =
  do it "[absdir|C:\\|] == $(mkAbsDir \"C:\\\")"
       ([absdir|C:\|] `shouldBe` $(mkAbsDir [OsString.pstr|C:\|]))
     it "[absdir|C:\\chris\\|] == $(mkAbsDir \"C:\\chris\\\")"
       ([absdir|C:\chris\|] `shouldBe` $(mkAbsDir [OsString.pstr|C:\chris\|]))
     it "[reldir|foo|] == $(mkRelDir \"foo\")"
       ([reldir|foo|] `shouldBe` $(mkRelDir [OsString.pstr|foo|]))
     it "[reldir|foo\\bar|] == $(mkRelDir \"foo\\bar\")"
       ([reldir|foo\bar|] `shouldBe` $(mkRelDir [OsString.pstr|foo\bar|]))
     it "[absfile|C:\\chris\\foo.txt|] == $(mkAbsFile \"C:\\chris\\foo.txt\")"
       ([absfile|C:\chris\foo.txt|] `shouldBe` $(mkAbsFile [OsString.pstr|C:\chris\foo.txt|]))
     it "[relfile|foo.exe|] == $(mkRelFile \"foo.exe\")"
       ([relfile|foo.exe|] `shouldBe` $(mkRelFile [OsString.pstr|foo.exe|]))
     it "[relfile|chris\\foo.txt|] == $(mkRelFile \"chris\\foo.txt\")"
       ([relfile|chris\foo.txt|] `shouldBe` $(mkRelFile [OsString.pstr|chris\foo.txt|]))