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
@@ -1,109 +1,67 @@
1
- (register-test '(suite "Parser tests"
2
- (suite "brace-list"
3
- ("parses an empty brace list"
4
- (parse "{}")
5
- ((brace-list)))
6
-
7
- ("parses a single-item list"
8
- (parse "{foo}")
9
- ((brace-list foo)))
10
-
11
- ("parses a list"
12
- (parse "{foo bar 1 2 3}")
13
- ((brace-list foo bar 1 2 3))))
14
-
15
- (suite "prefix-list"
16
- ("parse quasiquote"
17
- (parse "`(1 2 3)")
18
- ((quasiquote (1 2 3))))
19
-
20
- ("parse unquote unquote-splicing"
21
- (parse ",,@(1 2 3)")
22
- ((unquote (unquote-splicing (1 2 3)))))
23
-
24
- ("parse unquote"
25
- (parse ",(1 2 3)")
26
- ((unquote (1 2 3))))
27
-
28
- ("parse custom prefix-lists"
29
- (parse "x(1 2 3)")
30
- ((prefix-list "x" (1 2 3))))
31
-
32
- ("parse custom prefix-lists with a special-syntax prefix"
33
- (parse "x.y(1 2 3)")
34
- ((prefix-list "x.y" (1 2 3)))))
35
-
36
- (suite "parse"
37
- ("parses an empty symbol"
38
- (parse "||")
39
- (||) )
40
-
41
- ("parses a colon-syntax symbol"
42
- (parse "this:that")
43
- ((colon-syntax this that)) )
44
-
45
- ("parses a percent-syntax symbol"
46
- (parse "this%that")
47
- ((percent-syntax this that)) )
48
-
49
- ("parses a percent-prefix-syntax symbol"
50
- (parse "%this-and-that")
51
- ((percent-syntax || this-and-that)) )
52
-
53
- ("parses a dot-syntax symbol"
54
- (parse "this.that.zozo")
55
- ((dot-syntax this that zozo)) )
56
-
57
- ("parses a mixed-syntax symbol"
58
- (parse "this$that.zozo")
59
- ((dot-syntax (dollar-syntax this that) zozo)))
60
-
61
- ("parses a mixed-syntax prefix symbol"
62
- (parse "$this.that.zozo")
63
- ((dot-syntax (dollar-syntax || this) that zozo)))
64
-
65
- ("parses a prefix dollar"
66
- (parse "$this")
67
- ((dollar-syntax || this)))
68
-
69
- ("parses a prefix dollar-dot"
70
- (parse "$.this")
71
- ((dot-syntax (dollar-syntax || ||) this)))
72
-
73
- ("parses an expression"
74
- (parse "(foo bar \"hello, String\") 1 2 (3 t nil) nil")
75
- ((foo bar "hello, String") 1 2 (3 t nil))))
76
-
77
- (suite "parse-in-string"
78
- ("parses a plain string"
79
- (parse-in-string "hello, world, take me to your dealer")
80
- "hello, world, take me to your dealer")
81
-
82
- ("parses a plain string with interpolations"
83
- (parse-in-string (joinstr "" (list "hello, " '~ "(world), take me to your " '~ "dealer please")))
84
- (string-pieces "hello, " (world) ", take me to your " dealer " please"))
85
-
86
- ("parses a plain string of html text with interpolations"
87
- (parse-in-string "<div id='content_item_~~{id}'><label>~~{data-name-1}</label> ~~{data-text-1}</div>")
88
- (string-pieces "<div id='content_item_" (brace-list id) "'><label>" (brace-list data-name-1) "</label> " (brace-list data-text-1) "</div>"))
89
-
90
- ("ignores standalone interpolation symbol"
91
- (parse-in-string (joinstr "" (list "hello " '~ " world")))
92
- "hello \~ world")
93
-
94
- ("ignores backslash-escaped interpolation symbol"
95
- (len "hello \~world")
96
- 12)
97
-
98
- ("ignores escaped interpolation symbol"
99
- (parse-in-string (joinstr "" (list "hello " '~ '~ "world")))
100
- "hello \~world")
101
-
102
- ("really ignores standalone interpolation symbol"
103
- (len (parse-in-string (joinstr "" (list "hello " '~ " world"))))
104
- 13)
105
-
106
- ("reports parse errors gracefully"
107
- (on-err "CAUGHT: ~err" (parse-in-string (joinstr "" "blah ~~(\"stri...")))
108
- "CAUGHT: parse error: \"unterminated string\" in\n blah ~~(\"stri..." )
109
- )))
1
+ (examples-for parse
2
+ ("parses an empty brace list" (parse "{}") ((brace-list)))
3
+ ("parses a single-item list" (parse "{foo}") ((brace-list foo)))
4
+ ("parses a list" (parse "{foo bar 1 2 3}") ((brace-list foo bar 1 2 3)))
5
+ ("parse quasiquote" (parse "`(1 2 3)") ((quasiquote (1 2 3))))
6
+ ("parse unquote unquote-splicing" (parse ",,@(1 2 3)") ((unquote (unquote-splicing (1 2 3)))))
7
+ ("parse unquote" (parse ",(1 2 3)") ((unquote (1 2 3))))
8
+ ("parse custom prefix-lists" (parse "x(1 2 3)") ((prefix-list "x" (1 2 3))))
9
+ ("parses an empty symbol" (parse "||") (||) )
10
+ ("parses a colon-syntax symbol" (parse "this:that") ((colon-syntax this that)) )
11
+ ("parses a percent-syntax symbol" (parse "this%that") ((percent-syntax this that)) )
12
+ ("parses a prefix dollar" (parse "$this") ((dollar-syntax || this)))
13
+ ("parses a prefix dollar-dot" (parse "$.this") ((dot-syntax (dollar-syntax || ||) this)))
14
+
15
+ ("parse custom prefix-lists with a special-syntax prefix"
16
+ (parse "x.y(1 2 3)")
17
+ ((prefix-list "x.y" (1 2 3))))
18
+
19
+ ("parses a percent-prefix-syntax symbol"
20
+ (parse "%this-and-that")
21
+ ((percent-syntax || this-and-that)) )
22
+
23
+ ("parses a dot-syntax symbol"
24
+ (parse "this.that.zozo")
25
+ ((dot-syntax this that zozo)) )
26
+
27
+ ("parses a mixed-syntax symbol"
28
+ (parse "this$that.zozo")
29
+ ((dot-syntax (dollar-syntax this that) zozo)))
30
+
31
+ ("parses a mixed-syntax prefix symbol"
32
+ (parse "$this.that.zozo")
33
+ ((dot-syntax (dollar-syntax || this) that zozo)))
34
+
35
+
36
+ ("parses an expression"
37
+ (parse "(foo bar \"hello, String\") 1 2 (3 t nil) nil")
38
+ ((foo bar "hello, String") 1 2 (3 t nil))))
39
+
40
+ (examples-for parse-in-string
41
+ ("parses a plain string"
42
+ (parse-in-string "hello, world, take me to your dealer")
43
+ "hello, world, take me to your dealer")
44
+
45
+ ("parses a plain string with interpolations"
46
+ (parse-in-string (joinstr "" (list "hello, " '~ "(world), take me to your " '~ "dealer please")))
47
+ (string-pieces "hello, " (world) ", take me to your " dealer " please"))
48
+
49
+ ("parses a plain string of html text with interpolations"
50
+ (parse-in-string "<div id='content_item_~~{id}'><label>~~{data-name-1}</label> ~~{data-text-1}</div>")
51
+ (string-pieces "<div id='content_item_" (brace-list id) "'><label>" (brace-list data-name-1) "</label> " (brace-list data-text-1) "</div>"))
52
+
53
+ ("ignores standalone interpolation symbol"
54
+ (parse-in-string (joinstr "" (list "hello " '~ " world")))
55
+ "hello \~ world")
56
+
57
+ ("ignores escaped interpolation symbol"
58
+ (parse-in-string (joinstr "" (list "hello " '~ '~ "world")))
59
+ "hello \~world")
60
+
61
+ ("really ignores standalone interpolation symbol"
62
+ (len (parse-in-string (joinstr "" (list "hello " '~ " world"))))
63
+ 13)
64
+
65
+ ("reports parse errors gracefully"
66
+ (on-err "CAUGHT: ~err" (parse-in-string (joinstr "" "blah ~~(\"stri...")))
67
+ "CAUGHT: parse error: \"unterminated string\" in\n blah ~~(\"stri..." ))
@@ -1,20 +1,19 @@
1
- (register-test
2
- '(suite "Pretty Printing Tests"
3
- ("a macro invocation"
4
- (pp '(mac pp/def (name args . body) `(hash-set pp/special-forms ',name (fn ,args ,@body))))
5
- "(mac pp/def (name args body)\n `(hash-set pp/special-forms ',name (fn ,args ,@body)))")
1
+ (examples-for pp
2
+ ("a macro invocation"
3
+ (pp '(mac pp/def (name args . body) `(hash-set pp/special-forms ',name (fn ,args ,@body))))
4
+ "(mac pp/def (name args body)\n `(hash-set pp/special-forms ',name (fn ,args ,@body)))")
6
5
 
7
- ("a 'def invocation"
8
- (pp '(def pp (form) (pp/main form 0)))
9
- "(def pp (form)\n (pp/main form 0))")
6
+ ("a 'def invocation"
7
+ (pp '(def pp (form) (pp/main form 0)))
8
+ "(def pp (form)\n (pp/main form 0))")
10
9
 
11
- ("something with a plain string literal"
12
- (pp '(def yoohoo (it) (wrangle "foobar" it)))
13
- "(def yoohoo (it)\n (wrangle \"foobar\" it))")
10
+ ("something with a plain string literal"
11
+ (pp '(def yoohoo (it) (wrangle "foobar" it)))
12
+ "(def yoohoo (it)\n (wrangle \"foobar\" it))")
14
13
 
15
- ("combined with dox system"
16
- (pp:dox-src 'pp/find-breaks)
17
- "(def pp/find-breaks (form)
14
+ ("combined with dox system"
15
+ (pp:dox-src 'pp/find-breaks)
16
+ "(def pp/find-breaks (form)
18
17
  (if (eq? 'if (car form))
19
18
  (let if-args (cdr form)
20
19
  (cons (list 'if (car if-args)) (map list (cdr if-args))))
@@ -22,10 +21,10 @@
22
21
  (pp/find-breaks/mac form)
23
22
  (list form))))")
24
23
 
25
- ("special syntax"
26
- (pp '(string-pieces "hello " (bang-syntax || (dot-syntax x y (ampersand-syntax foo bar))) " and welcome to " (prefix-list "%%" (a b c d)) " and friends!"))
27
- "\"hello ~~!x.y.foo&bar and welcome to ~~%%(a b c d) and friends!\"")
24
+ ("special syntax"
25
+ (pp '(string-pieces "hello " (bang-syntax || (dot-syntax x y (ampersand-syntax foo bar))) " and welcome to " (prefix-list "%%" (a b c d)) " and friends!"))
26
+ "\"hello ~~!x.y.foo&bar and welcome to ~~%%(a b c d) and friends!\"")
28
27
 
29
- ("brace list"
30
- (pp '(&x {a 1 b "two" c 'three d ,four e (sub invocation) f {sub brace list} }))
31
- "(&x {a 1 b \"two\" c 'three d ,four e (sub invocation) f {sub brace list}})")))
28
+ ("brace list"
29
+ (pp '(&x {a 1 b "two" c 'three d ,four e (sub invocation) f {sub brace list} }))
30
+ "(&x {a 1 b \"two\" c 'three d ,four e (sub invocation) f {sub brace list}})"))
@@ -0,0 +1,10 @@
1
+ (examples-for quasiquote
2
+ ("same as quote for standalone item" `a a)
3
+ ("same as quote for standalone list" `(a b c) (a b c))
4
+ ("substitutes single variables" (let b 10 `(a ,b c)) (a 10 c))
5
+ ("substitutes a list" (let b '(1 2 3) `(a ,@b c)) (a 1 2 3 c))
6
+ ("substitutes a list at the end of a given list" (let b '(1 2 3) `(a ,b ,@b)) (a (1 2 3) 1 2 3))
7
+ ("more complicated substitution example" (with (d '(1 2 3) g '(x y z)) `(a (b c ,d (e f ,@g)))) (a (b c (1 2 3) (e f x y z))))
8
+ ("peeks inside nested quotes" `(a b '(c ,(+ 1 2))) (a b '(c 3)))
9
+ ("handles nested unquote-splicing" ``(a ,,@(list '+ 1 2) b) `((a ,(+ 1 2) b)))
10
+ ("returns nested quasiquotes" `(a b `(c d ,(+ 1 2) ,,(+ 3 4))) (a b `(c d ,(+ 1 2) ,7))))
@@ -0,0 +1,7 @@
1
+ (examples-for rfnwith
2
+ ("generates a locally-scoped recursive function"
3
+ (rfnwith triangle (n 10)
4
+ (if (eq? n 0)
5
+ 0
6
+ (+ n (triangle (- n 1)))))
7
+ 55))
@@ -1,31 +1,60 @@
1
- (register-test
2
- '(suite "String Tests"
3
- (suite "length"
4
- ("nonzero" (len "foo-bar") 7)
5
- ("zero" (len "") 0))
6
-
7
- (suite "joinstr"
8
- ("joins elements into a string"
9
- (joinstr "" '("foo" "bar" "bax"))
10
- "foobarbax")
11
-
12
- ("joins separate elements into a string"
13
- (joinstr "/" "foo" "bar" "bax")
14
- "foo/bar/bax")
15
-
16
- ("joins a single thing"
17
- (joinstr "/" "foo")
18
- "foo")
19
-
20
- ("joins nested and separate elements into a string"
21
- (joinstr "/" "foo" "bar" '(twiddle diddle) "bax")
22
- "foo/bar/twiddle/diddle/bax")
23
-
24
- ("joins elements into a string"
25
- (joinstr " - " '(1 2 3))
26
- "1 - 2 - 3"))
27
-
28
- (suite "strip"
29
- ("removes leading whitespace" (string-strip " hello!") "hello!" )
30
- ("removes trailing whitespace" (string-strip "(world) ") "(world)" )
31
- ("removes leading and trailing whitespace" (string-strip "\n\nme\n\n") "me" ))))
1
+ (examples-for string-split
2
+ ("splits a string using given expression"
3
+ (string-split "a and b and c and d" " and ")
4
+ ("a" "b" "c" "d")))
5
+
6
+ (examples-for string-replace
7
+ ("replaces parts of a string with the given replacement"
8
+ (string-replace "and" "or" "a and b and c and d")
9
+ "a or b or c or d")
10
+
11
+ ("replace with regexp"
12
+ (string-replace "and|or" "x" "a and b or c and d")
13
+ "a x b x c x d"))
14
+
15
+ (examples-for string-match
16
+ ("match with regexp"
17
+ (let m (string-match "a and b and c and d" "and")
18
+ (list m.match m.captures))
19
+ ("and" nil))
20
+
21
+ ("no match with regexp"
22
+ (let m (string-match "a and b and c and d" "not-in-string")
23
+ (list m.match m.captures))
24
+ (nil nil))
25
+
26
+ ("match with regexp and capturing groups"
27
+ (let m (string-match " foo\b bar" "(^\\s+)")
28
+ (list m.match m.captures))
29
+ (" " (" "))))
30
+
31
+ (examples-for string-pieces
32
+ ("interpolates a string"
33
+ "foobar ~(+ 1 2) you know"
34
+ "foobar 3 you know"))
35
+
36
+ (examples-for joinstr
37
+ ("joins elements into a string"
38
+ (joinstr "" '("foo" "bar" "bax"))
39
+ "foobarbax")
40
+
41
+ ("joins separate elements into a string"
42
+ (joinstr "/" "foo" "bar" "bax")
43
+ "foo/bar/bax")
44
+
45
+ ("joins a single thing"
46
+ (joinstr "/" "foo")
47
+ "foo")
48
+
49
+ ("joins nested and separate elements into a string"
50
+ (joinstr "/" "foo" "bar" '(twiddle diddle) "bax")
51
+ "foo/bar/twiddle/diddle/bax")
52
+
53
+ ("joins elements into a string"
54
+ (joinstr " - " '(1 2 3))
55
+ "1 - 2 - 3"))
56
+
57
+ (examples-for string-strip
58
+ ("removes leading whitespace" (string-strip " hello!") "hello!" )
59
+ ("removes trailing whitespace" (string-strip "(world) ") "(world)" )
60
+ ("removes leading and trailing whitespace" (string-strip "\n\nme\n\n") "me" ))
@@ -1,29 +1,27 @@
1
- (register-test
2
- '(suite "syntax tests"
3
- (suite "colon-syntax"
4
- ("expands to sequential function application"
5
- (pre-compile 'a:b)
6
- (fn args (a (apply b args))))
1
+ (examples-for colon-syntax
2
+ ("expands to sequential function application"
3
+ (pre-compile 'a:b)
4
+ (fn args (a (apply b args))))
7
5
 
8
- ("example with car:cdr"
9
- (car:cdr '(a b c))
10
- b)
6
+ ("example with car:cdr"
7
+ (car:cdr '(a b c))
8
+ b)
11
9
 
12
- ("dislikes no-prefix"
13
- (on-err err (pre-compile '(:foo 1 2 3)))
14
- "(\"Irregular ': syntax: got (|| foo) : not prefix-syntax : in :foo\")"))
10
+ ("dislikes no-prefix"
11
+ (on-err err (pre-compile '(:foo 1 2 3)))
12
+ "(\"Irregular ': syntax: got (|| foo) : not prefix-syntax : in :foo\")"))
15
13
 
16
- (suite "lambda shortcut"
17
- ("one argument"
18
- (map λa(len a.name)
19
- (list { name "bob" } { name "willy" } { name "pteradactyl" }))
20
- (3 5 11))
14
+ (examples-for prefix-list
15
+ ("one argument"
16
+ (map λa(len a.name)
17
+ (list { name "bob" } { name "willy" } { name "pteradactyl" }))
18
+ (3 5 11))
21
19
 
22
- ("with two args"
23
- (reduce λxy(joinstr ":" x y)
24
- '(a b c d e f))
25
- "a:b:c:d:e:f")
20
+ ("with two args"
21
+ (reduce λxy(joinstr ":" x y)
22
+ '(a b c d e f))
23
+ "a:b:c:d:e:f")
26
24
 
27
- ("with two args, to be sure"
28
- (λpq(+ p (* p q)) 3 5)
29
- 18))))
25
+ ("with two args, to be sure"
26
+ (λpq(+ p (* p q)) 3 5)
27
+ 18))
@@ -0,0 +1,48 @@
1
+ (examples-for type-of
2
+ ("returns pair for a cons cell"
3
+ (type-of (cons "a" "b"))
4
+ pair)
5
+
6
+ ("returns 'fn for builtin function"
7
+ (type-of car)
8
+ fn)
9
+
10
+ ("returns 'fn for nydp-defined function"
11
+ (type-of register-test)
12
+ fn)
13
+
14
+ ("returns 'fn for inline function"
15
+ (type-of (fn (x) (p x)))
16
+ fn)
17
+
18
+ ("returns 'string"
19
+ (type-of "foobar")
20
+ string)
21
+
22
+ ("returns 'hash for new hash"
23
+ (type-of (hash))
24
+ hash)
25
+
26
+ ("returns 'hash for hash literal"
27
+ (type-of { a 1 b 2})
28
+ hash)
29
+
30
+ ("returns 'number for an integer"
31
+ (type-of 42)
32
+ number)
33
+
34
+ ("returns 'number for a float"
35
+ (type-of 4.2)
36
+ number)
37
+
38
+ ("returns 'string for an interpolated string"
39
+ (type-of "foobar ~(+ 1 2)")
40
+ string)
41
+
42
+ ("t is Truth"
43
+ (type-of t)
44
+ truth)
45
+
46
+ ("nil is nil"
47
+ (type-of nil)
48
+ nil))
@@ -1,7 +1,6 @@
1
- (register-test '(suite "pair to-string"
1
+ (examples-for to-string
2
2
  ("unquote" (to-string '(unquote a)) ",a" )
3
3
  ("quote" (to-string '(quote a)) "'a" )
4
4
  ("quasiquote" (to-string '(quasiquote a)) "`a" )
5
5
  ("unquote-splicing" (to-string '(unquote-splicing a)) ",@a" )
6
- ("brace-list" (to-string '(brace-list a b c d)) "{ a b c d }" )
7
- ))
6
+ ("brace-list" (to-string '(brace-list a b c d)) "{ a b c d }" ))