nydp 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,24 @@
1
+ (examples-for explain-mac
2
+ ("does nothing if n is zero"
3
+ (explain-mac 0 '(afn (a) (+ 2 a)))
4
+ (afn (a) (+ 2 a)))
5
+
6
+ ("expands once for n = 1"
7
+ (explain-mac 1 '(afn (a) (+ 2 a)))
8
+ (rfn self (a) (+ 2 a)))
9
+
10
+ ("expands twice for n = 2"
11
+ (explain-mac 2 '(afn (a) (+ 2 a)))
12
+ (let self nil (assign self (fn (a) (+ 2 a)))))
13
+
14
+ ("expands thrice for n = 3"
15
+ (explain-mac 3 '(afn (a) (+ 2 a)))
16
+ (with (self nil) (assign self (fn (a) (+ 2 a)))))
17
+
18
+ ("expands four times for n = 4"
19
+ (explain-mac 4 '(afn (a) (+ 2 a)))
20
+ ((fn (self) (assign self (fn (a) (+ 2 a)))) nil))
21
+
22
+ ("returns same expression for n > number of possible expansions"
23
+ (explain-mac 10 '(afn (a) (+ 2 a)))
24
+ ((fn (self) (assign self (fn (a) (+ 2 a)))) nil)))
@@ -1,223 +1,57 @@
1
- (register-test '(suite "Foundation Tests"
2
- (suite "maths"
3
- ("sqrt"
4
- (sqrt 6.25)
5
- 2.5))
6
-
7
- (suite "strings"
8
- (suite "string-split"
9
- ("splits a string using given expression"
10
- (string-split "a and b and c and d" " and ")
11
- ("a" "b" "c" "d")))
12
-
13
- (suite "string-replace"
14
- ("replaces parts of a string with the given replacement"
15
- (string-replace "and" "or" "a and b and c and d")
16
- "a or b or c or d"))
17
-
18
- (suite "regexp"
19
- ("replace with regexp"
20
- (string-replace "and|or" "x" "a and b or c and d")
21
- "a x b x c x d")
22
-
23
- ("match with regexp"
24
- (let m (string-match "a and b and c and d" "and")
25
- (list m.match m.captures))
26
- ("and" nil))
27
-
28
- ("no match with regexp"
29
- (let m (string-match "a and b and c and d" "not-in-string")
30
- (list m.match m.captures))
31
- (nil nil))
32
-
33
- ("match with regexp and capturing groups"
34
- (let m (string-match " foo\b bar" "(^\\s+)")
35
- (list m.match m.captures))
36
- (" " (" ")))
37
- )
38
-
39
-
40
- (suite "type-of"
41
- ("returns 'fn for builtin function"
42
- (type-of car)
43
- fn)
44
-
45
- ("returns 'fn for nydp-defined function"
46
- (type-of register-test)
47
- fn)
48
-
49
- ("returns 'fn for inline function"
50
- (type-of (fn (x) (p x)))
51
- fn)
52
-
53
- ("returns 'string"
54
- (type-of "foobar")
55
- string)
56
-
57
- ("returns 'hash for new hash"
58
- (type-of (hash))
59
- hash)
60
-
61
- ("returns 'hash for hash literal"
62
- (type-of { a 1 b 2})
63
- hash)
64
-
65
- ("returns 'number for an integer"
66
- (type-of 42)
67
- number)
68
-
69
- ("returns 'number for a float"
70
- (type-of 4.2)
71
- number)
72
-
73
- ("interpolates a string"
74
- "foobar ~(+ 1 2) you know"
75
- "foobar 3 you know")
76
-
77
- ("returns 'string for an interpolated string"
78
- (type-of "foobar ~(+ 1 2)")
79
- string)))
80
-
81
- (suite "eq?"
82
- ("true for two empty symbols"
83
- (eq? '|| '||)
84
- t)
85
-
86
- ("nil for two different symbols"
87
- (eq? 'foo 'bar)
88
- nil))
89
-
90
- (suite "truth and nil"
91
- ("t is boolean true"
92
- (if t "hello" "goodbye")
93
- "hello")
94
-
95
- ("nil is boolean false"
96
- (if nil "hello" "goodbye")
97
- "goodbye")
98
-
99
- ("t is Truth"
100
- (type-of t)
101
- truth)
102
-
103
- ("nil is nil"
104
- (type-of nil)
105
- nil))
106
-
107
- (suite "assignment with '="
108
- ("assigns a symbol"
109
- (pre-compile '(= this 'that))
110
- (assign this 'that)))
111
-
112
- (suite "argument default value"
113
- ("is nil"
114
- ( (fn (x y z) (list x y (car z))) 'a 'b )
115
- (a b nil)))
116
-
117
- (suite "hash"
118
- ("hash-lookup"
119
- (pre-compile 'a.b.c)
120
- (hash-get (hash-get a 'b) 'c))
121
-
122
- ("hash-lookup with dollar-syntax for function call"
123
- (pre-compile '$a.b.c)
124
- (hash-get (hash-get (a) 'b) 'c))
125
-
126
- ("hash-lookup with embedded dollar-syntax for function call"
127
- (pre-compile 'a.$b.c)
128
- (hash-get (hash-get a (b)) 'c))
129
-
130
- ("hash-lookup with embedded unquote"
131
- (pre-compile 'a.,b.c)
132
- (hash-get (hash-get a b) 'c))
133
-
134
- ("hash assignment"
135
- (pre-compile '(= a.b 42))
136
- (hash-set a 'b 42))
137
-
138
- ("hash assignment with unquote"
139
- (pre-compile '(= a.,b 42))
140
- (hash-set a b 42))
141
-
142
- ("recursive hash assignment"
143
- (pre-compile '(= a.b.c.d 42))
144
- (hash-set (hash-get (hash-get a 'b) 'c) 'd 42))
145
-
146
- ("recursive hash assignment with embedded unquote"
147
- (pre-compile '(= a.b.,c.d 42))
148
- (hash-set (hash-get (hash-get a 'b) c) 'd 42))
149
-
150
- ("recursive hash assignment with prefix dollar-syntax"
151
- (pre-compile '(= $a.b.,c.d 42))
152
- (hash-set (hash-get (hash-get (a) 'b) c) 'd 42))
153
-
154
- ("recursive hash assignment with embedded dollar-syntax"
155
- (pre-compile '(= a.$b.,c.d 42))
156
- (hash-set (hash-get (hash-get a (b)) c) 'd 42))
157
-
158
- (suite "merge"
159
- ("merge with symbol keys"
160
- (let h (hash-merge { a 1 b 2 c 3 } { a 99 c 98 d 97 })
161
- (list h.a h.b h.c h.d (hash-keys h) ))
162
- (99 2 98 97 (a b c d )))
163
-
164
- ("merge with mixed symbol and string and int keys"
165
- (let h (hash-merge { a 1 "b" 2 3 'c } { a 99 b 98 3 "foo" })
166
- (cons (hash-keys h) (mapx (hash-keys h) k h.,k)))
167
- ((a "b" 3 b) 99 2 "foo" 98))))
168
-
169
- (suite "isa"
170
- ("t for 'pair for list"
171
- (isa 'pair '(a b c))
172
- t)
173
- ("nil for 'pair for non-list"
174
- (isa 'pair 42)
175
- nil)
176
- ("t for 'symbol for symbol"
177
- (isa 'symbol 'foo)
178
- t)
179
- ("nil for 'symbol for non-symbol"
180
- (isa 'symbol "foo")
181
- nil)
182
- ("t for 'string for string"
183
- (isa 'string "foo")
184
- t)
185
- ("nil for 'string for string"
186
- (isa 'string '(a b c))
187
- nil))
188
-
189
- (suite "Lists"
190
- (suite "cons"
191
- ("cons creates a list"
192
- (cons 'a '(b c))
193
- (a b c))
194
-
195
- ("cons conses two strings"
196
- (cons "a" "b")
197
- ("a" . "b"))
198
-
199
- ("len returns length of proper list"
200
- (len (cons "a" (cons "b" nil)))
201
- 2)
202
-
203
- ("type-of returns pair"
204
- (type-of (cons "a" "b"))
205
- pair))
206
-
207
- (suite "car"
208
- ("car of nil is nil"
209
- (car nil)
210
- nil)
211
-
212
- ("car of empty list is nil"
213
- (car '())
214
- nil)
215
-
216
- ("car - no need to quote empty list"
217
- (car ())
218
- nil)
219
-
220
- ("car returns car of argument"
221
- (car '(foo 12.34 "bar"))
222
- foo)
223
- ))))
1
+ (examples-for sqrt
2
+ ("sqrt"
3
+ (sqrt 6.25)
4
+ 2.5))
5
+
6
+ (examples-for eq?
7
+ ("true for two empty symbols"
8
+ (eq? '|| '||)
9
+ t)
10
+
11
+ ("nil for two different symbols"
12
+ (eq? 'foo 'bar)
13
+ nil))
14
+
15
+ (examples-for =
16
+ ("assigns a symbol"
17
+ (pre-compile '(= this 'that))
18
+ (assign this 'that)))
19
+
20
+ (examples-for if
21
+ ("single-expr 'if is just the expr"
22
+ (pre-compile '(if a))
23
+ a)
24
+
25
+ ("two-expr 'if expands to 'cond"
26
+ (pre-compile '(if a b))
27
+ (cond a b))
28
+
29
+ ("three-expr 'if expands to 'cond"
30
+ (pre-compile '(if a b c))
31
+ (cond a b c))
32
+
33
+ ("four-expr 'if expands to nested 'cond"
34
+ (pre-compile '(if a b c d))
35
+ (cond a b (cond c d)))
36
+
37
+ ("five-expr 'if expands to nested 'cond"
38
+ (pre-compile '(if a b c d e))
39
+ (cond a b (cond c d e)))
40
+
41
+ ("t is boolean true"
42
+ (if t "hello" "goodbye")
43
+ "hello")
44
+
45
+ ("nil is boolean false"
46
+ (if nil "hello" "goodbye")
47
+ "goodbye"))
48
+
49
+ (examples-for unless
50
+ ("expands to negative 'if"
51
+ (pre-compile '(unless x y z))
52
+ (cond (no x) ((fn () y z)))))
53
+
54
+ (examples-for fn
55
+ ("argument default value is nil"
56
+ ( (fn (x y z) (list x y (car z))) 'a 'b )
57
+ (a b nil)))
@@ -0,0 +1,41 @@
1
+ (examples-for hash-merge
2
+ ("merge with symbol keys"
3
+ (let h (hash-merge { a 1 b 2 c 3 } { a 99 c 98 d 97 })
4
+ (list h.a h.b h.c h.d (hash-keys h) ))
5
+ (99 2 98 97 (a b c d )))
6
+
7
+ ("merge with mixed symbol and string and int keys"
8
+ (let h (hash-merge { a 1 "b" 2 3 'c } { a 99 b 98 3 "foo" })
9
+ (cons (hash-keys h) (mapx (hash-keys h) k h.,k)))
10
+ ((a "b" 3 b) 99 2 "foo" 98)))
11
+
12
+ (examples-for hash-key?
13
+ ("detects key presence"
14
+ (hash-key? { foo 1 bar 2 } 'foo)
15
+ t)
16
+
17
+ ("detects key absence"
18
+ (hash-key? { foo 1 bar 2 } 'zed)
19
+ nil))
20
+
21
+ (examples-for brace-list
22
+ ("build a hash table from brace-list syntax"
23
+ (let hsh { foo 1 bar 2 }
24
+ (list 'foo hsh.foo 'bar hsh.bar))
25
+ (foo 1 bar 2))
26
+
27
+ ("single-item brace list is just the thing itself"
28
+ (let zi 10 "finds the ~{zi}th item")
29
+ "finds the 10th item")
30
+
31
+ ("unquotes hash keys"
32
+ (with (zi 'foo chi 'bar yi 'grr)
33
+ (let hsh { ,zi 10 ,chi 11 ,yi 12 }
34
+ (list zi hsh.foo chi hsh.bar yi hsh.grr)))
35
+ (foo 10 bar 11 grr 12))
36
+
37
+ ("allows literal and invocation hash keys"
38
+ (with (zi "hello" chi "world")
39
+ (let hsh { (joinstr " " zi chi) 10 "yesterday" 11 }
40
+ (list "hello world" (hash-get hsh "hello world") "yesterday" (hash-get hsh "yesterday"))))
41
+ ("hello world" 10 "yesterday" 11)))
@@ -0,0 +1,7 @@
1
+ (examples-for isa
2
+ ("t for 'pair for list" (isa 'pair '(a b c)) t)
3
+ ("nil for 'pair for non-list" (isa 'pair 42) nil)
4
+ ("t for 'symbol for symbol" (isa 'symbol 'foo) t)
5
+ ("nil for 'symbol for non-symbol" (isa 'symbol "foo") nil)
6
+ ("t for 'string for string" (isa 'string "foo") t)
7
+ ("nil for 'string for string" (isa 'string '(a b c)) nil))
@@ -0,0 +1,11 @@
1
+ (examples-for len
2
+ ("nonzero" (len "foo-bar") 7)
3
+ ("zero" (len "") 0)
4
+
5
+ ("ignores backslash-escaped interpolation symbol"
6
+ (len "hello \~world")
7
+ 12)
8
+
9
+ ("len returns length of proper list"
10
+ (len (cons "a" (cons "b" nil)))
11
+ 2))
@@ -1,75 +1,110 @@
1
- (register-test
2
- '(suite "List Tests"
3
- (suite "joinlists"
4
- ("joins one list to another"
5
- (joinlists '(a b c) '(x y z))
6
- (a b c x y z))
7
-
8
- ("joins three lists"
9
- (joinlists '(a b c) '(x y z) '(1 2 3))
10
- (a b c x y z 1 2 3)))
11
-
12
- (suite "firstn"
13
- ("returns no items for n = 0"
14
- (firstn 0 '(a b c d))
15
- nil)
16
-
17
- ("returns first n items for n > 0 and n < size of list"
18
- (firstn 3 '(a b c d e))
19
- (a b c))
20
-
21
- ("returns all items for n > size of list"
22
- (firstn 33 '(a b c d e))
23
- (a b c d e)))
24
-
25
- (suite "nthcdr"
26
- ("returns all items for n = 0"
27
- (nthcdr 0 '(a b c d))
28
- (a b c d))
29
-
30
- ("returns nth cdr of list for n > 0 and n < size of list"
31
- (nthcdr 3 '(a b c d e))
32
- (d e))
33
-
34
- ("returns nothing for n > size of list"
35
- (nthcdr 33 '(a b c d e))
36
- nil))
37
-
38
- (suite "car/cdr combinations"
39
- ("caar of list" (caar '((x y) (1 2))) x )
40
- ("caar of nil" (caar nil) nil )
41
- ("cadr of list" (cadr '((x y) (1 2))) (1 2) )
42
- ("cadr of nil" (cadr nil) nil )
43
- ("cdar of list" (cdar '((x y) (1 2))) (y) )
44
- ("cdar of nil" (cdar nil) nil )
45
- ("cddr of list" (cddr '(x y 1 2)) (1 2) )
46
- ("cddr of nil" (cddr nil) nil )
47
- ("cadar of list" (cadar '((x y) (1 2))) y )
48
- ("cadar of nil" (cadar nil) nil )
49
- ("caddr of list" (caddr '(x y 1 2)) 1 )
50
- ("caddr of nil" (caddr nil) nil )
51
- ("cdddr of list" (cdddr '(x y 1 2)) (2) )
52
- ("cdddr of nil" (cdddr nil) nil )
53
- ("cadddr of list" (cadddr '(x y 1 2 3)) 2 )
54
- ("cadddr of nil" (cadddr nil) nil ))
55
-
56
- (suite "proper?"
57
- ("t for a proper list"
58
- (proper? '(a b c d))
59
- t)
60
-
61
- ("t for a proper list, even if we write it funny"
62
- (proper? '(a b . (c d)))
63
- t)
64
-
65
- ("t for a proper list, even if we write it funny with nil"
66
- (proper? '(a b . nil))
67
- t)
68
-
69
- ("nil for an improper list"
70
- (proper? '(a b . c))
71
- nil)
72
-
73
- ("nil for a very improper list"
74
- (proper? '(a b . (c . d)))
75
- nil))))
1
+ (examples-for pairs
2
+ ("'pair breaks a list into pairs"
3
+ (pairs '(1 a 2 b 3 c))
4
+ ((1 a) (2 b) (3 c))))
5
+
6
+ (examples-for rev
7
+ ("'rev reverses a list"
8
+ (rev '(a b c))
9
+ (c b a))
10
+
11
+ ("'rev handles nil"
12
+ (rev nil)
13
+ nil)
14
+
15
+ ("'rev doesn't recurse"
16
+ (rev '(a b (c d e) f g))
17
+ (g f (c d e) b a)))
18
+
19
+ (examples-for flatten
20
+ ("'flatten returns a flat list of things"
21
+ (flatten '((poo (x) (* x x)) (1 2 3)))
22
+ (poo x * x x 1 2 3)))
23
+
24
+ (examples-for joinlists
25
+ ("joins one list to another"
26
+ (joinlists '(a b c) '(x y z))
27
+ (a b c x y z))
28
+
29
+ ("joins three lists"
30
+ (joinlists '(a b c) '(x y z) '(1 2 3))
31
+ (a b c x y z 1 2 3)))
32
+
33
+ (examples-for firstn
34
+ ("returns no items for n = 0"
35
+ (firstn 0 '(a b c d))
36
+ nil)
37
+
38
+ ("returns first n items for n > 0 and n < size of list"
39
+ (firstn 3 '(a b c d e))
40
+ (a b c))
41
+
42
+ ("returns all items for n > size of list"
43
+ (firstn 33 '(a b c d e))
44
+ (a b c d e)))
45
+
46
+ (examples-for nthcdr
47
+ ("returns all items for n = 0"
48
+ (nthcdr 0 '(a b c d))
49
+ (a b c d))
50
+
51
+ ("returns nth cdr of list for n > 0 and n < size of list"
52
+ (nthcdr 3 '(a b c d e))
53
+ (d e))
54
+
55
+ ("returns nothing for n > size of list"
56
+ (nthcdr 33 '(a b c d e))
57
+ nil))
58
+
59
+ (examples-for caar
60
+ ("caar of list" (caar '((x y) (1 2))) x )
61
+ ("caar of nil" (caar nil) nil ))
62
+
63
+ (examples-for cadr
64
+ ("cadr of list" (cadr '((x y) (1 2))) (1 2) )
65
+ ("cadr of nil" (cadr nil) nil ))
66
+
67
+ (examples-for cdar
68
+ ("cdar of list" (cdar '((x y) (1 2))) (y) )
69
+ ("cdar of nil" (cdar nil) nil ))
70
+
71
+ (examples-for cddr
72
+ ("cddr of list" (cddr '(x y 1 2)) (1 2) )
73
+ ("cddr of nil" (cddr nil) nil ))
74
+
75
+ (examples-for cadar
76
+ ("cadar of list" (cadar '((x y) (1 2))) y )
77
+ ("cadar of nil" (cadar nil) nil ))
78
+
79
+ (examples-for caddr
80
+ ("caddr of list" (caddr '(x y 1 2)) 1 )
81
+ ("caddr of nil" (caddr nil) nil ))
82
+
83
+ (examples-for cdddr
84
+ ("cdddr of list" (cdddr '(x y 1 2)) (2) )
85
+ ("cdddr of nil" (cdddr nil) nil ))
86
+
87
+ (examples-for cadddr
88
+ ("cadddr of list" (cadddr '(x y 1 2 3)) 2 )
89
+ ("cadddr of nil" (cadddr nil) nil ))
90
+
91
+ (examples-for proper?
92
+ ("t for a proper list"
93
+ (proper? '(a b c d))
94
+ t)
95
+
96
+ ("t for a proper list, even if we write it funny"
97
+ (proper? '(a b . (c d)))
98
+ t)
99
+
100
+ ("t for a proper list, even if we write it funny with nil"
101
+ (proper? '(a b . nil))
102
+ t)
103
+
104
+ ("nil for an improper list"
105
+ (proper? '(a b . c))
106
+ nil)
107
+
108
+ ("nil for a very improper list"
109
+ (proper? '(a b . (c . d)))
110
+ nil))