C0 code coverage information
Generated on Wed May 31 01:38:08 AUS Eastern Standard Time 2006 with rcov 0.4.1
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name |
Total lines |
Lines of code |
Total coverage |
Code coverage |
test_misp.rb
|
200
|
189
|
|
|
1 require 'test/unit'
2 require 'misp'
3
4 class MispTest < Test::Unit::TestCase
5
6 def parse(s) Misp.parse(s) end
7 def serialize(sexp) sexp.to_s end
8
9 def assert_parse_err(s)
10 parse s
11 rescue Racc::ParseError => e
12 assert true
13 else
14 flunk "parse error expected from '#{s}'"
15 end
16
17 def assert_serializable(s)
18 assert_equal s, serialize(parse(s))
19 end
20
21 def assert_false(s)
22 assert_equal :nil, parse(s).evaluate
23 end
24 def assert_true(s)
25 assert_not_equal :nil, parse(s).evaluate
26 end
27
28 def assert_eq(expected, expr)
29 assert_equal parse(expected), parse(expr).evaluate
30 end
31
32 def test_array_to_sexp
33 assert_equal Misp::Pair.new(:a, Misp::Pair.new(:b)), [:a, [:b, nil]].to_sexp
34 end
35 def test_nil_to_sexp
36 assert_equal :nil, nil.to_sexp
37 end
38
39 def test_parse_canonical
40 assert_equal :a, parse("a")
41 assert_equal [:a, :b].to_sexp, parse("(a . b)")
42 assert_equal [:a, :b].to_sexp, Misp::SExpr.new("(a . b)")
43 assert_equal [[:a, :b], [:c, :d]].to_sexp, parse("((a . b) . (c . d))")
44 end
45 def test_parse_abbrev
46 assert_equal [:a, :nil].to_sexp, parse("(a)")
47 assert_equal [:a, [:b, :c]].to_sexp, parse("(a b . c)")
48 assert_equal [:a, [:b, :nil]].to_sexp, parse("(a b)")
49 assert_equal [[:a, :b], :nil].to_sexp, parse("((a . b))")
50 assert_equal [:a, [[:b, :c], :d]].to_sexp, parse("(a (b . c) . d)")
51 assert_equal [:a, [[:b, :nil], [:c, :nil]]].to_sexp, parse("(a (b) c)")
52 assert_equal \
53 parse("(eq . ((hd . ((hd . (env . nil)) . nil)) . (key . nil)))"),
54 parse("(eq (hd (hd env)) key)")
55 end
56 def test_parse_quote
57 assert_equal parse("(quote hello)"), parse("'hello")
58 assert_equal parse("(quote (quote hello))"), parse("''hello")
59 assert_equal parse("(quote (a . b))"), parse("'(a . b)")
60 assert_equal parse("(x . (quote . (foo . nil)))"), parse("(x quote foo)")
61 assert_equal parse("(x . (quote . (foo . nil)))"), parse("(x . 'foo)")
62 assert_equal parse("(a . ((quote . (b . nil)) . ((quote . (c . nil)))))"),
63 parse("(a 'b 'c)")
64 end
65 def test_parse_fn
66 assert_equal parse("(fn (x) (pair x x))"), parse("{|x| (pair x x)}")
67 assert_equal parse("(fn (x . xs) xs)"), parse("{|x . xs| xs}")
68 assert_equal parse("(fn xs xs)"), parse("{|.xs| xs}")
69 end
70
71 def test_parse_errors
72 assert_parse_err ")"
73 assert_parse_err "("
74 assert_parse_err "."
75 assert_parse_err "(a . b . c)"
76 assert_parse_err "(a . b (c))"
77 assert_parse_err "(a . (b) . c)"
78 assert_parse_err "(a . (b) c)"
79 assert_parse_err "(a . b"
80 assert_parse_err "(a ."
81 assert_parse_err ". b)"
82 assert_parse_err "a . b)"
83 assert_parse_err "(a . b))"
84 assert_parse_err "(a . )"
85 assert_parse_err "( . b)"
86 assert_parse_err "a . b"
87 assert_parse_err "a b)"
88 assert_parse_err "a b"
89 assert_parse_err "a (b . c))"
90 assert_parse_err "a (b . c)"
91 assert_parse_err "(a . b c)" # implied triplet-dot
92 end
93 def test_parse_error_quote
94 assert_parse_err "foo '"
95 assert_parse_err "(foo ')"
96 assert_parse_err "(foo . ')"
97 assert_parse_err "(foo bar ')"
98 assert_parse_err "(foo . bar ')"
99 assert_parse_err "(foo '. bar)"
100 end
101 def test_parse_error_fn
102 assert_parse_err "|x|y}"
103 assert_parse_err "{x|y}"
104 assert_parse_err "{||y}"
105 assert_parse_err "{|x}"
106 assert_parse_err "{|x|}"
107 assert_parse_err "{|x|y"
108 assert_parse_err "{x|y|}"
109 assert_parse_err "(|x|y)"
110 assert_parse_err "{(x)y}"
111 end
112
113 def test_serialize_basic
114 assert_serializable "foo"
115 assert_serializable "(foo . bar)"
116 assert_serializable "((a . b) . c)"
117 end
118 def test_serialize_abbrev
119 assert_serializable "(a)"
120 assert_serializable "(a b)"
121 assert_serializable "(a b c)"
122 assert_serializable "((a . b) c . d)"
123 assert_serializable "((a) c)"
124 assert_serializable "(a (b) c)"
125 assert_serializable "(eq (hd (hd env)) key)"
126 end
127 def test_serialize_quote
128 assert_serializable "'foo"
129 assert_serializable "''foo"
130 assert_serializable "(foo quote bar)" # not (foo . 'bar)
131 assert_serializable "'(what (is up))"
132 assert_serializable "'(a nested 'quote)"
133 end
134 def test_serialize_if
135 assert_serializable "((if (eq nil 'x) quote pair) (if (eq 'a 'b) 'c 'd) (if (eq 'e 'e) (pair 'g nil) 'h))"
136 end
137 def test_serialize_fn
138 assert_serializable "{|x| (pair x x)}"
139 assert_serializable "{|x . xs| xs}"
140 assert_serializable "{|.xs| xs}"
141 end
142
143 def test_eval_quote
144 assert_equal :hello, parse("'hello").evaluate
145 assert_eq "'hello", "''hello"
146 assert_eq "(a . b)", "'(a . b)"
147 assert_eq "(a b c)", "'(a b c)"
148 assert_eq "(what (is up))", "'(what (is up))"
149 assert_eq "(a nested 'quote)", "'(a nested 'quote)"
150 end
151 def test_eval_eq
152 assert_false "nil"
153 assert_true "'anything-else"
154 assert_false "(eq 'eq 'happy-go-lucka-day)"
155 assert_true "(eq (eq 'eq 'happy-go-lucka-day) nil)"
156 assert_false "(eq '(a . pair) '(a . pair))"
157 assert_false "(eq 'hello 'world)"
158 assert_true "(eq 'hello 'hello)"
159 assert_true "(eq 'nil nil)"
160 assert_true "(eq nil nil)"
161 assert_true "(eq nil (eq 'hello 'world))"
162 assert_false "(eq '(pair) '(pair))"
163 end
164 def test_eval_atom
165 assert_false "(atom '(hog wash))"
166 assert_true "(atom 'hog-wash)"
167 assert_eq "true", "(atom nil)"
168 assert_eq "true", "(atom 'true)"
169 assert_eq "nil", "(atom '(pair))"
170 assert_eq "nil", "(atom '(pair of ((pair) . (pair))))"
171 end
172 def test_eval_pair_hd_tl
173 assert_eq "(of . things)", "(pair 'of 'things)"
174 assert_eq "the-head", "(hd '(the-head the-tail))"
175 assert_eq "(the-tail)", "(tl '(the-head the-tail))"
176 assert_eq "(nil)", "(pair nil nil)"
177 assert_eq "(pair)", "(pair 'pair nil)"
178 assert_eq "(hello world)", "(pair 'hello (pair 'world nil))"
179 assert_eq "((a . b) . (c . d))", "(pair (pair 'a 'b) (pair 'c 'd))"
180 assert_eq "head", "(hd '(head . tail))"
181 assert_eq "head", "(hd (pair 'head 'tail))"
182 assert_eq "a", "(hd (hd (pair (pair 'a 'b) (pair 'c 'd))))"
183 assert_eq "tail", "(tl '(head . tail))"
184 assert_eq "tail", "(tl (pair 'head 'tail))"
185 assert_eq "d", "(tl (tl (pair (pair 'a 'b) (pair 'c 'd))))"
186 end
187 def test_eval_if
188 assert_eq "yes", "(if nil 'nope 'yes)"
189 assert_eq "yes", "(if (eq nil nil) 'yes 'nope)"
190 assert_eq "(d g)", "((if (eq nil 'x) quote pair) (if (eq 'a 'b) 'c 'd) (if (eq 'e 'e) (pair 'g nil) 'h))"
191 end
192 def test_eval_fn
193 assert_eq "foo", "({|x| x} 'foo)"
194 assert_eq "(hi . hi)", "({|x| (pair x x)} 'hi)"
195 assert_eq "nil", "({|x y z| z} 'a 'b)"
196 assert_eq "(b c)", "({|ls| ({|x . xs| xs} . ls)} '(a b c))"
197 assert_eq "(a b c)", "({|.xs| xs} 'a 'b 'c)"
198 assert_eq "(a b c)", "({|list|(list 'a 'b 'c)} {.xs| xs})"
199 end
200 end
Generated using the rcov code coverage analysis tool for Ruby version 0.4.1.