Kiln » babybearparser
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

Better exception and exception handling.

Changeset c381bb2b7e39

Parent 876e4bb434dc

by Profile picture of User 138Hao Lian <hao@fogcreek.com>

Changes to 2 files · Browse files at c381bb2b7e39 Showing diff from parent 876e4bb434dc Diff from another changeset...

 
5
6
7
8
9
10
11
12
13
14
15
 
19
20
21
22
23
24
25
26
27
28
 
 
29
30
31
 
41
42
43
44
 
45
46
47
 
5
6
7
 
 
 
 
 
8
9
10
 
14
15
16
 
 
 
 
 
17
 
18
19
20
21
22
 
32
33
34
 
35
36
37
38
@@ -5,11 +5,6 @@
 open System    type Keyword = Word of string | Phrase of string - with - override this.ToString() = - match this with - | Word s -> String.Format("Word<{0}>", s) - | Phrase s -> String.Format("Phrase<{0}>", s)    type Filter =   | Author of string @@ -19,13 +14,9 @@
  | Repo of string    type Atom = KeywordAtom of Keyword | FilterAtom of Filter - with - override this.ToString() = - match this with - | KeywordAtom k -> String.Format("KeywordAtom<{0}>", k) - | FilterAtom f -> String.Format("FilterAtom<{0}>", f)   -exception ParseError of string +type ParseError (msg: string) = + inherit Exception (msg)    (* Utilities *)  let pipeline (f, a) = f a @@ -41,7 +32,7 @@
  | "file" -> File   | "project" -> Project   | "repo" -> Repo - | _ -> raise <| Exception "Invalid filter name" + | _ -> raise <| ParseError "Invalid filter name"    (* Parsers *)  let word = many1Satisfy <| fun c -> c <> ' '
 
6
7
8
9
 
 
10
11
12
13
14
 
15
16
17
 
6
7
8
 
9
10
11
12
13
14
 
15
16
17
18
@@ -6,12 +6,13 @@
   open babybearparser.Parser   -let equals actual expected = Assert.IsTrue ((actual = expected), String.Format("{0} <> {1}", actual, expected)) +let equals actual expected = Assert.IsTrue ((actual = expected), sprintf "%+A <> %+A" actual expected) +  let throwsParseError (f: unit -> unit) contains =   try   f(); Assert.Fail ("throws: no exception thrown of type ParseError")   with - | ParseError(x) -> Assert.IsTrue (x.Contains(contains), String.Format("{0} does not contain {1}", x, contains)) + | :? ParseError as ex -> Assert.IsTrue (ex.Message.Contains(contains), sprintf "%O does not contain %s" ex contains)    [<TestClass>]  type public Tests () =