nydp 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -13
  3. data/lib/lisp/core-015-documentation.nydp +11 -2
  4. data/lib/lisp/core-030-syntax.nydp +52 -8
  5. data/lib/lisp/core-040-utils.nydp +35 -47
  6. data/lib/lisp/core-045-dox-utils.nydp +85 -0
  7. data/lib/lisp/core-050-test-runner.nydp +20 -2
  8. data/lib/lisp/core-080-pretty-print.nydp +5 -1
  9. data/lib/lisp/tests/boot-tests.nydp +125 -255
  10. data/lib/lisp/tests/car-examples.nydp +16 -0
  11. data/lib/lisp/tests/collect-tests.nydp +28 -0
  12. data/lib/lisp/tests/cons-examples.nydp +8 -0
  13. data/lib/lisp/tests/curry-tests.nydp +17 -18
  14. data/lib/lisp/tests/detect-examples.nydp +24 -0
  15. data/lib/lisp/tests/dot-syntax-examples.nydp +40 -0
  16. data/lib/lisp/tests/dox-tests.nydp +116 -100
  17. data/lib/lisp/tests/dynamic-scope-test.nydp +10 -10
  18. data/lib/lisp/tests/each-tests.nydp +4 -5
  19. data/lib/lisp/tests/error-tests.nydp +17 -16
  20. data/lib/lisp/tests/explain-mac-examples.nydp +24 -0
  21. data/lib/lisp/tests/foundation-test.nydp +57 -223
  22. data/lib/lisp/tests/hash-examples.nydp +41 -0
  23. data/lib/lisp/tests/isa-examples.nydp +7 -0
  24. data/lib/lisp/tests/len-examples.nydp +11 -0
  25. data/lib/lisp/tests/list-tests.nydp +110 -75
  26. data/lib/lisp/tests/parser-tests.nydp +67 -109
  27. data/lib/lisp/tests/pretty-print-tests.nydp +19 -20
  28. data/lib/lisp/tests/quasiquote-examples.nydp +10 -0
  29. data/lib/lisp/tests/rfnwith-tests.nydp +7 -0
  30. data/lib/lisp/tests/string-tests.nydp +60 -31
  31. data/lib/lisp/tests/syntax-tests.nydp +22 -24
  32. data/lib/lisp/tests/type-of-examples.nydp +48 -0
  33. data/lib/lisp/tests/unparse-tests.nydp +2 -3
  34. data/lib/nydp.rb +2 -1
  35. data/lib/nydp/version.rb +1 -1
  36. metadata +14 -1
@@ -0,0 +1,28 @@
1
+ (examples-for collect
2
+ ("returns all matching items in a list"
3
+ (collect (fn (x) (eq? (len x) 2))
4
+ (list "foo" "bar" "xx" "pp"))
5
+ ("xx" "pp"))
6
+
7
+ ("returns nil when nothing matches"
8
+ (collect (fn (x) (eq? (len x) 20))
9
+ (list "foo" "bar" "xx" "pp"))
10
+ nil)
11
+
12
+ ;; kind of pointless
13
+ ("returns list of nils if nil is the matching item"
14
+ (collect no (list "foo" "bar" nil "pp" nil))
15
+ (nil nil))
16
+
17
+ ("returns item if it's an atom and matches"
18
+ (collect (fn (x) (eq? (len x) 2)) "zz")
19
+ "zz")
20
+
21
+ ("preserves structure of improper list"
22
+ (collect (fn (x) (eq? (len x) 2)) '("aa" "bbb" "cc" "ddd" . "ee"))
23
+ ("aa" "cc" . "ee"))
24
+
25
+ ("returns nil if it's an atom and doesn't match"
26
+ (collect (fn (x) (eq? (len x) 20))
27
+ "zz")
28
+ nil))
@@ -0,0 +1,8 @@
1
+ (examples-for cons
2
+ ("cons creates a list"
3
+ (cons 'a '(b c))
4
+ (a b c))
5
+
6
+ ("cons conses two strings"
7
+ (cons "a" "b")
8
+ ("a" . "b")))
@@ -1,24 +1,23 @@
1
1
  (def chicken-korma (a b c d e)
2
2
  (list a b c d e))
3
3
 
4
- (register-test
5
- '(suite "Curry Tests"
6
- ("zero-params"
7
- (let ck0 (curry chicken-korma)
8
- (ck0 1 2 3 4 5))
9
- (1 2 3 4 5))
4
+ (examples-for curry
5
+ ("zero-params"
6
+ (let ck0 (curry chicken-korma)
7
+ (ck0 1 2 3 4 5))
8
+ (1 2 3 4 5))
10
9
 
11
- ("one param"
12
- (let ck0 (curry chicken-korma 'x)
13
- (ck0 1 2 3 4))
14
- (x 1 2 3 4))
10
+ ("one param"
11
+ (let ck0 (curry chicken-korma 'x)
12
+ (ck0 1 2 3 4))
13
+ (x 1 2 3 4))
15
14
 
16
- ("two params"
17
- (let ck0 (curry chicken-korma 'x 'y)
18
- (ck0 1 2 3))
19
- (x y 1 2 3))
15
+ ("two params"
16
+ (let ck0 (curry chicken-korma 'x 'y)
17
+ (ck0 1 2 3))
18
+ (x y 1 2 3))
20
19
 
21
- ("three params"
22
- (let ck0 (curry chicken-korma 'x 'y 'z)
23
- (ck0 1 2))
24
- (x y z 1 2))))
20
+ ("three params"
21
+ (let ck0 (curry chicken-korma 'x 'y 'z)
22
+ (ck0 1 2))
23
+ (x y z 1 2)))
@@ -0,0 +1,24 @@
1
+ (examples-for detect
2
+ ("returns first matching item in a list"
3
+ (detect (fn (x) (eq? (len x) 2))
4
+ (list "foo" "bar" "xx" "pp"))
5
+ "xx")
6
+
7
+ ("returns nil when nothing matches"
8
+ (detect (fn (x) (eq? (len x) 20))
9
+ (list "foo" "bar" "xx" "pp"))
10
+ nil)
11
+
12
+ ;; kind of pointless
13
+ ("returns nil if nil is the matching item"
14
+ (detect no (list "foo" "bar" nil "pp"))
15
+ nil)
16
+
17
+ ("returns item if it's an atom and matches"
18
+ (detect (fn (x) (eq? (len x) 2)) "zz")
19
+ "zz")
20
+
21
+ ("returns nil if it's an atom and doesn't match"
22
+ (detect (fn (x) (eq? (len x) 20))
23
+ "zz")
24
+ nil))
@@ -0,0 +1,40 @@
1
+ (examples-for dox-syntax
2
+ ("hash-lookup"
3
+ (pre-compile 'a.b.c)
4
+ (hash-get (hash-get a 'b) 'c))
5
+
6
+ ("hash-lookup with dollar-syntax for function call"
7
+ (pre-compile '$a.b.c)
8
+ (hash-get (hash-get (a) 'b) 'c))
9
+
10
+ ("hash-lookup with embedded dollar-syntax for function call"
11
+ (pre-compile 'a.$b.c)
12
+ (hash-get (hash-get a (b)) 'c))
13
+
14
+ ("hash-lookup with embedded unquote"
15
+ (pre-compile 'a.,b.c)
16
+ (hash-get (hash-get a b) 'c))
17
+
18
+ ("hash assignment"
19
+ (pre-compile '(= a.b 42))
20
+ (hash-set a 'b 42))
21
+
22
+ ("hash assignment with unquote"
23
+ (pre-compile '(= a.,b 42))
24
+ (hash-set a b 42))
25
+
26
+ ("recursive hash assignment"
27
+ (pre-compile '(= a.b.c.d 42))
28
+ (hash-set (hash-get (hash-get a 'b) 'c) 'd 42))
29
+
30
+ ("recursive hash assignment with embedded unquote"
31
+ (pre-compile '(= a.b.,c.d 42))
32
+ (hash-set (hash-get (hash-get a 'b) c) 'd 42))
33
+
34
+ ("recursive hash assignment with prefix dollar-syntax"
35
+ (pre-compile '(= $a.b.,c.d 42))
36
+ (hash-set (hash-get (hash-get (a) 'b) c) 'd 42))
37
+
38
+ ("recursive hash assignment with embedded dollar-syntax"
39
+ (pre-compile '(= a.$b.,c.d 42))
40
+ (hash-set (hash-get (hash-get a (b)) c) 'd 42)))
@@ -1,53 +1,51 @@
1
1
  (mac this-is-a-well-documented-macro (a b c)
2
- ; documentation for me!
2
+ ; documentation for me!
3
3
  `(foo ,a ,b ,c))
4
4
 
5
5
  (mac this-is-an-undocumented-macro (a b c)
6
6
  `(baz ,a ,b ,c))
7
7
 
8
8
  (def this-is-a-well-documented-def (a b c)
9
- ; documentation for me!
9
+ ; documentation for me!
10
10
  (foo a b c))
11
11
 
12
12
  (def this-is-an-undocumented-def (a b c)
13
13
  (baz a b c))
14
14
 
15
- (register-test
16
- '(suite "Documentation Tests"
17
- (suite "comment detection"
18
- ("identify comment"
19
- (isa-comment? '(comment "yes, it is"))
20
- t)
21
-
22
- ("identify non-comment"
23
- (isa-comment? "not this time")
24
- nil))
25
-
26
- (suite "gather comments from 'body argument"
27
- ("no comment"
28
- (dox-gather-comments '((this) (that)))
29
- (nil ((this) (that))))
30
-
31
- ("one comment"
32
- (dox-gather-comments '((comment "hello") (this) (that)))
33
- (("hello") ((this) (that))))
34
-
35
- ("more comments"
36
- (dox-gather-comments '((comment "hello")
37
- (comment "more details")
38
- (comment "very rigourous")
39
- (this)
40
- (that)))
41
- (("hello" "more details" "very rigourous") ((this) (that)))))
42
-
43
- (suite "dox-show-info"
44
- ("shows each item"
45
- (dox-show-info "bingo"
46
- 'def
47
- '("there was a farmer had a dog" "and Bingo was his name-o")
48
- '(count)
49
- '(def bingo (count) (times count (bark))))
50
- "Function : bingo
15
+ (examples-for isa-comment?
16
+ ("identifies a comment"
17
+ (isa-comment? '(comment "yes, it is"))
18
+ t)
19
+
20
+ ("identifies a non-comment"
21
+ (isa-comment? "not this time")
22
+ nil))
23
+
24
+ (examples-for dox-gather-comments
25
+ ("find no comments"
26
+ (dox-gather-comments '((this) (that)))
27
+ (nil ((this) (that))))
28
+
29
+ ("finds one comment"
30
+ (dox-gather-comments '((comment "hello") (this) (that)))
31
+ (("hello") ((this) (that))))
32
+
33
+ ("finds more comments"
34
+ (dox-gather-comments '((comment "hello")
35
+ (comment "more details")
36
+ (comment "very rigourous")
37
+ (this)
38
+ (that)))
39
+ (("hello" "more details" "very rigourous") ((this) (that)))))
40
+
41
+ (examples-for dox-show-info
42
+ ("shows each item"
43
+ (dox-show-info "bingo"
44
+ 'def
45
+ '("there was a farmer had a dog" "and Bingo was his name-o")
46
+ '(count)
47
+ '(def bingo (count) (times count (bark))))
48
+ "Function : bingo
51
49
 
52
50
  args : (count)
53
51
 
@@ -56,68 +54,86 @@ and Bingo was his name-o
56
54
 
57
55
  source
58
56
  ======
59
- (def bingo (count)
57
+ \(def bingo (count)
60
58
  (times count (bark)))
61
59
  "))
62
60
 
63
- (suite "mac"
64
- ("a documented macro"
65
- (dox-lookup 'this-is-a-well-documented-macro)
66
- ((this-is-a-well-documented-macro
67
- mac
68
- ("documentation for me!")
69
- (a b c)
70
- (mac this-is-a-well-documented-macro (a b c)
71
- `(foo ,a ,b ,c)))))
72
-
73
- ("arg list"
74
- (dox-arg-names 'this-is-a-well-documented-macro)
75
- (a b c))
76
-
77
- ("src"
78
- (dox-src 'this-is-a-well-documented-macro)
79
- (mac this-is-a-well-documented-macro (a b c) (quasiquote (foo (unquote a) (unquote b) (unquote c)))))
80
-
81
- ("is a def"
82
- (dox-what-is? 'this-is-a-well-documented-macro)
83
- mac)
84
-
85
- ("an undocumented macro"
86
- (dox-lookup 'this-is-an-undocumented-macro)
87
- ((this-is-an-undocumented-macro
88
- mac
89
- nil
90
- (a b c)
91
- (mac this-is-an-undocumented-macro (a b c)
92
- `(baz ,a ,b ,c)))))
93
-
94
- (suite "def"
95
- ("a documented def"
96
- (dox-lookup 'this-is-a-well-documented-def)
97
- ((this-is-a-well-documented-def
98
- def
99
- ("documentation for me!")
100
- (a b c)
101
- (def this-is-a-well-documented-def (a b c)
102
- (foo a b c)))))
103
-
104
- ("arg list"
105
- (dox-arg-names 'this-is-a-well-documented-def)
106
- (a b c))
107
-
108
- ("is a def"
109
- (dox-what-is? 'this-is-a-well-documented-def)
110
- def)
111
-
112
- ("src"
113
- (dox-src 'this-is-a-well-documented-def)
114
- (def this-is-a-well-documented-def (a b c) (foo a b c)))
115
-
116
- ("an undocumented def"
117
- (dox-lookup 'this-is-an-undocumented-def)
118
- ((this-is-an-undocumented-def
119
- def
120
- nil
121
- (a b c)
122
- (def this-is-an-undocumented-def (a b c)
123
- (baz a b c)))))))))
61
+ (examples-for dox-lookup
62
+ ("finds info for a documented macro"
63
+ (dox-lookup 'this-is-a-well-documented-macro)
64
+ ((this-is-a-well-documented-macro
65
+ mac
66
+ ("documentation for me!")
67
+ (a b c)
68
+ (mac this-is-a-well-documented-macro (a b c)
69
+ `(foo ,a ,b ,c)))))
70
+
71
+ ("finds info for an undocumented macro"
72
+ (dox-lookup 'this-is-an-undocumented-macro)
73
+ ((this-is-an-undocumented-macro
74
+ mac
75
+ nil
76
+ (a b c)
77
+ (mac this-is-an-undocumented-macro (a b c)
78
+ `(baz ,a ,b ,c)))))
79
+
80
+ ("finds info for a documented def"
81
+ (dox-lookup 'this-is-a-well-documented-def)
82
+ ((this-is-a-well-documented-def
83
+ def
84
+ ("documentation for me!")
85
+ (a b c)
86
+ (def this-is-a-well-documented-def (a b c)
87
+ (foo a b c)))))
88
+
89
+ ("finds info for an undocumented def"
90
+ (dox-lookup 'this-is-an-undocumented-def)
91
+ ((this-is-an-undocumented-def
92
+ def
93
+ nil
94
+ (a b c)
95
+ (def this-is-an-undocumented-def (a b c)
96
+ (baz a b c))))))
97
+
98
+ (examples-for dox-arg-names
99
+ ("macro"
100
+ (dox-arg-names 'this-is-a-well-documented-macro)
101
+ (a b c))
102
+
103
+ ("function def"
104
+ (dox-arg-names 'this-is-a-well-documented-def)
105
+ (a b c)))
106
+
107
+ (examples-for dox-src
108
+ ("mac src"
109
+ (dox-src 'this-is-a-well-documented-macro)
110
+ (mac this-is-a-well-documented-macro (a b c) (quasiquote (foo (unquote a) (unquote b) (unquote c)))))
111
+
112
+ ("def src"
113
+ (dox-src 'this-is-a-well-documented-def)
114
+ (def this-is-a-well-documented-def (a b c) (foo a b c))))
115
+
116
+
117
+ (examples-for dox-what-is?
118
+ ("for mac"
119
+ (dox-what-is? 'this-is-a-well-documented-macro)
120
+ mac)
121
+
122
+ ("is a def"
123
+ (dox-what-is? 'this-is-a-well-documented-def)
124
+ def))
125
+
126
+ (examples-for dox-show-one-example
127
+ ("produces a string representation of a given example"
128
+ (dox-show-one-example 'foo '("this is an example of an example"
129
+ (foo bar yadda 1 2 3)
130
+ 720))
131
+ "foo this is an example of an example
132
+
133
+ running :
134
+ (foo bar yadda 1 2 3)
135
+
136
+ produces : 720
137
+
138
+ --------------------------------
139
+ "))
@@ -1,14 +1,14 @@
1
1
  (dynamic foodynamic)
2
2
 
3
3
  (def listfoody ()
4
- (list (foodynamic)
5
- (+ 6 (foodynamic))
6
- (+ 10 (foodynamic))))
4
+ (list (foodynamic)
5
+ (+ 6 (foodynamic))
6
+ (+ 10 (foodynamic))))
7
7
 
8
- (register-test '(suite "dynamic scoping"
9
- ("relies on thread-locals"
10
- (list
11
- (w/foodynamic 101 (listfoody))
12
- (w/foodynamic 0 (listfoody))
13
- (w/foodynamic 666 (listfoody)))
14
- ((101 107 111) (0 6 10) (666 672 676)))))
8
+ (examples-for dynamic
9
+ ("relies on thread-locals"
10
+ (list
11
+ (w/foodynamic 101 (listfoody))
12
+ (w/foodynamic 0 (listfoody))
13
+ (w/foodynamic 666 (listfoody)))
14
+ ((101 107 111) (0 6 10) (666 672 676))))
@@ -1,5 +1,4 @@
1
- (register-test
2
- '(suite "'each Tests"
3
- ("iterates over each item in list"
4
- (let acc 0 (each x '(1 2 3 4) (assign acc (+ x acc))) acc)
5
- 10)))
1
+ (examples-for each
2
+ ("iterates over each item in list"
3
+ (let acc 0 (each x '(1 2 3 4) (assign acc (+ x acc))) acc)
4
+ 10))
@@ -1,22 +1,23 @@
1
- (register-test '(suite "Error Tests"
2
- ("'ensuring gets called on the way out"
1
+ (examples-for ensure
2
+ ("always gets called on the way out"
3
3
  (let x 10
4
- (ensure (assign x (+ x 11))
5
- (assign x (+ x 22)))
6
- x)
7
- 43)
4
+ (ensure (assign x (+ x 11))
5
+ (assign x (+ x 22)))
6
+ x)
7
+ 43))
8
8
 
9
- ("'on-err handles errors"
9
+ (examples-for on-err
10
+ ("'handles errors"
10
11
  (let x nil
11
- (on-err (= x "impossible")
12
- (= x (nil nil nil)))
13
- x)
12
+ (on-err (= x "impossible")
13
+ (= x (nil nil nil)))
14
+ x)
14
15
  "impossible")
15
16
 
16
- ("'on-err handles errors but any ensuring clause gets called first"
17
+ ("handles errors but any ensuring clause gets called first"
17
18
  (with (x nil y nil)
18
- (on-err (= x 'impossible)
19
- (ensure (assign y 'ensure-clause)
20
- (nil nil nil)))
21
- (list x y))
22
- (impossible ensure-clause))))
19
+ (on-err (= x 'impossible)
20
+ (ensure (assign y 'ensure-clause)
21
+ (nil nil nil)))
22
+ (list x y))
23
+ (impossible ensure-clause)))