@@ -2,12 +2,15 @@ module Test.Main where
2
2
3
3
import Prelude
4
4
import Data.Either
5
+ import Control.Apply
5
6
import Control.Monad.Eff
6
- import Control.Monad.Eff.Console
7
+ import qualified Control.Monad.Eff.Console as C
8
+ import Control.Monad.Eff.Exception
7
9
import Data.URI
8
10
import Data.URI.Types
9
11
import Text.Parsing.StringParser
10
12
13
+
11
14
main = do
12
15
test runParseURIRef " mongodb://localhost"
13
16
test runParseURIRef " http://en.wikipedia.org/wiki/URI_scheme"
@@ -31,22 +34,30 @@ main = do
31
34
test runParseURIRef " foo://info.example.com?fred"
32
35
test runParseURIRef
" ftp://cnn.example.com&[email protected] /top_story.htm"
33
36
34
- log " \n Failing test cases: "
35
- test runParseURIRef " news:comp.infosystems.www.servers.unix"
36
- test runParseURIRef " tel:+1-816-555-1212"
37
- test runParseURIRef " urn:oasis:names:specification:docbook:dtd:xml:4.1.2"
38
- test runParseURIRef
" mailto:[email protected] "
39
- test runParseURIRef
" mailto:[email protected] "
40
- test runParseURIRef " ../top_story.htm"
41
- test runParseURIRef " top_story.htm"
42
- test runParseURIRef " /top_story.htm"
37
+ C . log " \n Failing test cases: "
38
+ testFails runParseURIRef " news:comp.infosystems.www.servers.unix"
39
+ testFails runParseURIRef " tel:+1-816-555-1212"
40
+ testFails runParseURIRef " urn:oasis:names:specification:docbook:dtd:xml:4.1.2"
41
+ testFails runParseURIRef
" mailto:[email protected] "
42
+ testFails runParseURIRef
" mailto:[email protected] "
43
+ testFails runParseURIRef " ../top_story.htm"
44
+ testFails runParseURIRef " top_story.htm"
45
+ testFails runParseURIRef " /top_story.htm"
43
46
44
47
45
- test :: forall a . (String -> Either ParseError URIRef ) -> String -> _
46
- test f s = do
47
- log $ " \n Trying to parse " ++ s ++ " "
48
+ testCommon :: (String -> Eff _ Unit ) -> (String -> Eff _ Unit ) ->
49
+ (String -> Either ParseError URIRef ) -> String -> _
50
+ testCommon leftMsg rightMsg f s = do
51
+ C .log $ " \n Trying to parse " <> s <> " "
48
52
case f s of
49
- (Left err) -> log $ " Parse failed: " ++ show err
50
- (Right x) -> do
51
- log $ " printURI: " ++ printURIRef x
52
- log $ " show: " ++ show x
53
+ Left err -> leftMsg $ " Parse failed: " <> show err
54
+ Right x -> do
55
+ rightMsg $ " printURI: " <> printURIRef x
56
+ <> " \n show: " <> show x
57
+
58
+
59
+ test :: (String -> Either ParseError URIRef ) -> String -> _
60
+ test = testCommon (\x -> C .error x *> (throwException $ error x)) C .log
61
+
62
+ testFails :: (String -> Either ParseError URIRef ) -> String -> _
63
+ testFails = testCommon C .log (\x -> C .error x *> (throwException $ error x))
0 commit comments