Skip to content

Commit 09b396e

Browse files
committed
Add more tests in preparation of rewrite
1 parent b8102cf commit 09b396e

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

tests/src/Test/FileSystemPath.gren

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,42 @@ tests =
8585
\{} ->
8686
Path.fromPosixString ""
8787
|> Expect.equal (Path.fromPosixString ".")
88+
, test "file with multiple dots" <|
89+
\{} ->
90+
Path.fromPosixString "archive.tar.gz"
91+
|> Expect.equal
92+
{ root = ""
93+
, directory = []
94+
, filename = "archive.tar"
95+
, extension = "gz"
96+
}
97+
, test "hidden file" <|
98+
\{} ->
99+
Path.fromPosixString ".hidden"
100+
|> Expect.equal
101+
{ root = ""
102+
, directory = []
103+
, filename = ".hidden"
104+
, extension = ""
105+
}
106+
, test "file with multiple extensions" <|
107+
\{} ->
108+
Path.fromPosixString "file.backup.old"
109+
|> Expect.equal
110+
{ root = ""
111+
, directory = []
112+
, filename = "file.backup"
113+
, extension = "old"
114+
}
115+
, test "absolute path with trailing slash" <|
116+
\{} ->
117+
Path.fromPosixString "/some/path/"
118+
|> Expect.equal
119+
{ root = "/"
120+
, directory = [ "some" ]
121+
, filename = "path"
122+
, extension = ""
123+
}
88124
]
89125
, describe "fromWin32String"
90126
[ test "absolute file" <|
@@ -96,6 +132,109 @@ tests =
96132
, filename = "path"
97133
, extension = "js"
98134
}
135+
, test "absolute file without extension" <|
136+
\{} ->
137+
Path.fromWin32String "C:\\some\\long"
138+
|> Expect.equal
139+
{ root = "C:\\"
140+
, directory = [ "some" ]
141+
, filename = "long"
142+
, extension = ""
143+
}
144+
, test "relative file" <|
145+
\{} ->
146+
Path.fromWin32String "some\\other\\file"
147+
|> Expect.equal
148+
{ root = ""
149+
, directory = [ "some", "other" ]
150+
, filename = "file"
151+
, extension = ""
152+
}
153+
, test "just a file name" <|
154+
\{} ->
155+
Path.fromWin32String "file.md"
156+
|> Expect.equal
157+
{ root = ""
158+
, directory = []
159+
, filename = "file"
160+
, extension = "md"
161+
}
162+
, test "paths are normalized" <|
163+
\{} ->
164+
Path.fromWin32String "some\\other\\file\\."
165+
|> Expect.equal
166+
{ root = ""
167+
, directory = [ "some", "other" ]
168+
, filename = "file"
169+
, extension = ""
170+
}
171+
, test "paths are normalized, leading . is ignored" <|
172+
\{} ->
173+
Path.fromWin32String ".\\file"
174+
|> Expect.equal
175+
{ root = ""
176+
, directory = []
177+
, filename = "file"
178+
, extension = ""
179+
}
180+
, test "paths are normalized, even in extreme cases" <|
181+
\{} ->
182+
Path.fromWin32String "some\\other\\\\file\\other\\.."
183+
|> Expect.equal
184+
{ root = ""
185+
, directory = [ "some", "other" ]
186+
, filename = "file"
187+
, extension = ""
188+
}
189+
, test "empty path" <|
190+
\{} ->
191+
Path.fromWin32String ""
192+
|> Expect.equal
193+
{ root = ""
194+
, directory = []
195+
, filename = ""
196+
, extension = ""
197+
}
198+
, test "current path" <|
199+
\{} ->
200+
Path.fromWin32String ""
201+
|> Expect.equal (Path.fromWin32String ".")
202+
, test "UNC path" <|
203+
\{} ->
204+
Path.fromWin32String "\\\\server\\share\\file.txt"
205+
|> Expect.equal
206+
{ root = "\\\\server\\share\\"
207+
, directory = []
208+
, filename = "file"
209+
, extension = "txt"
210+
}
211+
, test "file with multiple dots" <|
212+
\{} ->
213+
Path.fromWin32String "archive.tar.gz"
214+
|> Expect.equal
215+
{ root = ""
216+
, directory = []
217+
, filename = "archive.tar"
218+
, extension = "gz"
219+
}
220+
, test "hidden file" <|
221+
\{} ->
222+
Path.fromWin32String ".hidden"
223+
|> Expect.equal
224+
{ root = ""
225+
, directory = []
226+
, filename = ".hidden"
227+
, extension = ""
228+
}
229+
, test "file with multiple extensions" <|
230+
\{} ->
231+
Path.fromWin32String "file.backup.old"
232+
|> Expect.equal
233+
{ root = ""
234+
, directory = []
235+
, filename = "file.backup"
236+
, extension = "old"
237+
}
99238
]
100239
, describe "to*String"
101240
[ test "toPosixString is the inverse of fromPosixString" <|

0 commit comments

Comments
 (0)