nydp 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +77 -56
  4. data/lib/lisp/core-000.nydp +1 -1
  5. data/lib/lisp/core-010-precompile.nydp +49 -29
  6. data/lib/lisp/core-012-utils.nydp +12 -8
  7. data/lib/lisp/core-015-documentation.nydp +41 -15
  8. data/lib/lisp/core-017-builtin-dox.nydp +621 -100
  9. data/lib/lisp/core-020-utils.nydp +33 -6
  10. data/lib/lisp/core-025-warnings.nydp +1 -1
  11. data/lib/lisp/core-030-syntax.nydp +64 -48
  12. data/lib/lisp/core-035-flow-control.nydp +20 -28
  13. data/lib/lisp/core-037-list-utils.nydp +84 -21
  14. data/lib/lisp/core-040-utils.nydp +8 -5
  15. data/lib/lisp/core-041-string-utils.nydp +17 -11
  16. data/lib/lisp/core-043-list-utils.nydp +140 -77
  17. data/lib/lisp/core-045-dox-utils.nydp +1 -0
  18. data/lib/lisp/core-050-test-runner.nydp +8 -12
  19. data/lib/lisp/core-070-prefix-list.nydp +19 -15
  20. data/lib/lisp/core-080-pretty-print.nydp +13 -5
  21. data/lib/lisp/core-090-hook.nydp +11 -11
  22. data/lib/lisp/core-100-utils.nydp +51 -66
  23. data/lib/lisp/core-110-hash-utils.nydp +34 -7
  24. data/lib/lisp/core-120-settings.nydp +14 -9
  25. data/lib/lisp/core-130-validations.nydp +28 -13
  26. data/lib/lisp/core-900-benchmarking.nydp +420 -47
  27. data/lib/lisp/tests/000-empty-args-examples.nydp +5 -0
  28. data/lib/lisp/tests/andify-examples.nydp +1 -1
  29. data/lib/lisp/tests/auto-hash-examples.nydp +6 -1
  30. data/lib/lisp/tests/best-examples.nydp +1 -1
  31. data/lib/lisp/tests/boot-tests.nydp +1 -1
  32. data/lib/lisp/tests/date-examples.nydp +129 -102
  33. data/lib/lisp/tests/destructuring-examples.nydp +1 -1
  34. data/lib/lisp/tests/dox-tests.nydp +2 -2
  35. data/lib/lisp/tests/hash-examples.nydp +58 -33
  36. data/lib/lisp/tests/list-tests.nydp +137 -1
  37. data/lib/lisp/tests/pretty-print-tests.nydp +12 -0
  38. data/lib/lisp/tests/rotate-2d-array-examples.nydp +26 -0
  39. data/lib/lisp/tests/sort-examples.nydp +5 -5
  40. data/lib/lisp/tests/string-tests.nydp +16 -5
  41. data/lib/lisp/tests/syntax-tests.nydp +10 -2
  42. data/lib/lisp/tests/time-examples.nydp +8 -1
  43. data/lib/lisp/tests/unparse-tests.nydp +13 -7
  44. data/lib/nydp/assignment.rb +15 -28
  45. data/lib/nydp/builtin/abs.rb +4 -3
  46. data/lib/nydp/builtin/apply.rb +8 -10
  47. data/lib/nydp/builtin/cdr_set.rb +1 -1
  48. data/lib/nydp/builtin/comment.rb +1 -3
  49. data/lib/nydp/builtin/date.rb +11 -28
  50. data/lib/nydp/builtin/divide.rb +3 -10
  51. data/lib/nydp/builtin/ensuring.rb +6 -21
  52. data/lib/nydp/builtin/error.rb +2 -4
  53. data/lib/nydp/builtin/eval.rb +9 -4
  54. data/lib/nydp/builtin/greater_than.rb +7 -8
  55. data/lib/nydp/builtin/handle_error.rb +10 -34
  56. data/lib/nydp/builtin/hash.rb +24 -45
  57. data/lib/nydp/builtin/inspect.rb +1 -3
  58. data/lib/nydp/builtin/is_equal.rb +4 -7
  59. data/lib/nydp/builtin/less_than.rb +6 -7
  60. data/lib/nydp/builtin/log.rb +7 -0
  61. data/lib/nydp/builtin/math_ceiling.rb +1 -3
  62. data/lib/nydp/builtin/math_floor.rb +1 -3
  63. data/lib/nydp/builtin/math_power.rb +1 -3
  64. data/lib/nydp/builtin/math_round.rb +2 -2
  65. data/lib/nydp/builtin/minus.rb +7 -14
  66. data/lib/nydp/builtin/parse.rb +5 -5
  67. data/lib/nydp/builtin/parse_in_string.rb +5 -7
  68. data/lib/nydp/builtin/plus.rb +14 -31
  69. data/lib/nydp/builtin/pre_compile.rb +1 -3
  70. data/lib/nydp/builtin/puts.rb +4 -8
  71. data/lib/nydp/builtin/quit.rb +1 -1
  72. data/lib/nydp/builtin/rand.rb +6 -11
  73. data/lib/nydp/builtin/random_string.rb +2 -4
  74. data/lib/nydp/builtin/rng.rb +25 -0
  75. data/lib/nydp/builtin/ruby_wrap.rb +27 -14
  76. data/lib/nydp/builtin/script_run.rb +1 -3
  77. data/lib/nydp/builtin/set_intersection.rb +3 -4
  78. data/lib/nydp/builtin/set_union.rb +3 -4
  79. data/lib/nydp/builtin/sort.rb +2 -7
  80. data/lib/nydp/builtin/string_match.rb +5 -13
  81. data/lib/nydp/builtin/string_replace.rb +2 -7
  82. data/lib/nydp/builtin/string_split.rb +3 -8
  83. data/lib/nydp/builtin/sym.rb +2 -9
  84. data/lib/nydp/builtin/thread_locals.rb +2 -2
  85. data/lib/nydp/builtin/time.rb +38 -44
  86. data/lib/nydp/builtin/times.rb +6 -15
  87. data/lib/nydp/builtin/to_integer.rb +8 -14
  88. data/lib/nydp/builtin/to_string.rb +2 -13
  89. data/lib/nydp/builtin/type_of.rb +10 -16
  90. data/lib/nydp/builtin/vm_info.rb +2 -10
  91. data/lib/nydp/builtin.rb +15 -37
  92. data/lib/nydp/compiler.rb +29 -19
  93. data/lib/nydp/cond.rb +95 -88
  94. data/lib/nydp/context_symbol.rb +11 -9
  95. data/lib/nydp/core.rb +74 -73
  96. data/lib/nydp/core_ext.rb +87 -26
  97. data/lib/nydp/date.rb +22 -19
  98. data/lib/nydp/error.rb +2 -3
  99. data/lib/nydp/function_invocation.rb +76 -289
  100. data/lib/nydp/helper.rb +18 -9
  101. data/lib/nydp/interpreted_function.rb +159 -25
  102. data/lib/nydp/lexical_context.rb +9 -8
  103. data/lib/nydp/lexical_context_builder.rb +1 -1
  104. data/lib/nydp/literal.rb +3 -7
  105. data/lib/nydp/loop.rb +72 -0
  106. data/lib/nydp/namespace.rb +52 -0
  107. data/lib/nydp/pair.rb +146 -50
  108. data/lib/nydp/parser.rb +9 -11
  109. data/lib/nydp/plugin.rb +88 -19
  110. data/lib/nydp/runner.rb +141 -23
  111. data/lib/nydp/symbol.rb +16 -26
  112. data/lib/nydp/symbol_lookup.rb +3 -2
  113. data/lib/nydp/tokeniser.rb +1 -1
  114. data/lib/nydp/truth.rb +2 -37
  115. data/lib/nydp/version.rb +1 -1
  116. data/lib/nydp.rb +33 -44
  117. data/nydp.gemspec +2 -1
  118. data/spec/date_spec.rb +26 -32
  119. data/spec/embedded_spec.rb +22 -22
  120. data/spec/error_spec.rb +12 -16
  121. data/spec/foreign_hash_spec.rb +21 -36
  122. data/spec/hash_non_hash_behaviour_spec.rb +12 -29
  123. data/spec/hash_spec.rb +36 -49
  124. data/spec/literal_spec.rb +6 -6
  125. data/spec/nydp_spec.rb +14 -14
  126. data/spec/pair_spec.rb +8 -8
  127. data/spec/parser_spec.rb +41 -37
  128. data/spec/rand_spec.rb +1 -4
  129. data/spec/spec_helper.rb +3 -3
  130. data/spec/string_atom_spec.rb +15 -16
  131. data/spec/symbol_spec.rb +27 -52
  132. data/spec/thread_local_spec.rb +23 -8
  133. data/spec/time_spec.rb +4 -10
  134. data/spec/tokeniser_spec.rb +10 -10
  135. metadata +25 -13
  136. data/lib/nydp/builtin/modulo.rb +0 -11
  137. data/lib/nydp/builtin/regexp.rb +0 -7
  138. data/lib/nydp/builtin/sqrt.rb +0 -7
  139. data/lib/nydp/builtin/string_pad_left.rb +0 -7
  140. data/lib/nydp/builtin/string_pad_right.rb +0 -7
  141. data/lib/nydp/hash.rb +0 -9
  142. data/lib/nydp/image_store.rb +0 -21
  143. data/lib/nydp/vm.rb +0 -129
@@ -1,103 +1,130 @@
1
1
  (examples-for date
2
- ("creates a single date" (to-string (date 1965 6 8)) "1965-06-08" )
3
- ("navigates to next day" (let d (date 2004 3 11) (to-string d.tomorrow)) "2004-03-12" )
4
- ("navigates to previous day" (let d (date 2006 6 22) (to-string d.yesterday)) "2006-06-21" )
5
- ("navigates to previous year" (let d (date 1971 12 18) (to-string d.last-year)) "1970-12-18" )
6
- ("navigates to next year" (let d (date 1974 1 11) (to-string d.next-year)) "1975-01-11" )
7
- ("navigates to previous month" (let d (date 1971 12 18) (to-string d.last-month)) "1971-11-18" )
8
- ("navigates to next month" (let d (date 1974 1 11) (to-string d.next-month)) "1974-02-11" )
9
- ("jumps a year to previous month" (let d (date 1974 1 11) (to-string d.last-month)) "1973-12-11" )
10
- ("navigates to previous week" (let d (date 2008 2 16) (to-string d.last-week)) "2008-02-09" )
11
- ("navigates to next week" (let d (date 1972 11 13) (to-string d.next-week)) "1972-11-20" )
12
- ("navigates to year start" (let d (date 1972 11 13) (to-string d.beginning-of-year)) "1972-01-01" )
13
- ("navigates to year end" (let d (date 1972 11 13) (to-string d.end-of-year)) "1972-12-31" )
14
- ("navigates to month start" (let d (date 1971 11 18) (to-string d.beginning-of-month)) "1971-11-01" )
15
- ("navigates to month end" (let d (date 1971 11 18) (to-string d.end-of-month)) "1971-11-30" )
16
- ("navigates to week start" (let d (date 2015 11 6) (to-string d.beginning-of-week)) "2015-11-02" )
17
- ("navigates to week start from sun" (let d (date 2015 11 1) (to-string d.beginning-of-week)) "2015-10-26" )
18
- ("navigates to week end from sun" (let d (date 2015 11 1) (to-string d.end-of-week)) "2015-11-01" )
19
- ("navigates to week end" (let d (date 2015 11 6) (to-string d.end-of-week)) "2015-11-08" )
20
-
21
- ("works with apply" (to-string (apply date '(2006 6 21))) "2006-06-21")
22
- ("works with apply again" (to-string (apply date 2006 6 21 nil)) "2006-06-21")
23
-
24
- ("parses string" (let d (date "2004-03-12") (list d.year d.month d.day)) (2004 3 12))
25
-
26
- ("can act as hash key"
27
- (with (h {} d (date 2015 11 8))
28
- (hash-set h d "on this day")
29
- (to-string (hash-get h (date 2015 11 8))))
30
- "on this day")
31
-
32
- ("equals itself" (eq? (date 2004 3 12) (date 2004 3 12)) t )
33
- ("does not equal another" (eq? (date 2004 3 12) (date 2006 6 21)) nil)
34
- ("does not equal nil" (eq? (date 2004 3 12) nil ) nil)
35
- ("nil does not equal a date" (eq? nil (date 2004 3 12) ) nil)
36
-
37
- ("returns its year" (let d (date 1999 12 31) d.year) 1999)
38
- ("returns its month" (let d (date 1999 12 31) d.month) 12 )
39
- ("returns its day" (let d (date 1999 12 31) d.day) 31 )
40
- ("returns its week-day" (let d (date 1999 12 31) d.week-day) 5 )
41
- ("recognises not monday" (let d (date 2015 11 1) d.monday? ) nil )
42
- ("recognises monday" (let d (date 2015 11 2) d.monday? ) t )
43
- ("recognises tuesday" (let d (date 2015 11 3) d.tuesday? ) t )
44
- ("recognises wednesday" (let d (date 2015 11 4) d.wednesday?) t )
45
- ("recognises thursday" (let d (date 2015 11 5) d.thursday? ) t )
46
- ("recognises friday" (let d (date 2015 11 6) d.friday? ) t )
47
- ("recognises not friday" (let d (date 2015 11 7) d.friday? ) nil )
48
- ("recognises saturday" (let d (date 2015 11 7) d.saturday? ) t )
49
- ("recognises sunday" (let d (date 2015 11 8) d.sunday? ) t )
50
- ("adds days" (let d (date 2015 11 8) (to-string (+ d 1))) "2015-11-09")
51
- ("adds more days" (let d (date 2015 11 8) (to-string (+ d 10))) "2015-11-18")
52
- ("subtracts a day" (let d (date 2015 11 18) (to-string (- d 1))) "2015-11-17")
53
- ("subtracts more days" (let d (date 2015 11 18) (to-string (- d 5))) "2015-11-13")
54
-
55
- ("advances by -2 weeks" (let d (date 1965 6 8) (to-string (+ d '(-2 week)))) "1965-05-25")
56
- ("advances by -1 week" (let d (date 1965 6 8) (to-string (+ d '(-1 week)))) "1965-06-01")
57
- ("advances by 1 week" (let d (date 1965 6 8) (to-string (+ d '( 1 week)))) "1965-06-15")
58
- ("advances by 2 weeks" (let d (date 1965 6 8) (to-string (+ d '( 2 week)))) "1965-06-22")
59
-
60
- ("advances by -2 weeks" (let d (date 1965 6 8) (to-string (+ d '(-2 week)))) "1965-05-25")
61
- ("advances by -1 week" (let d (date 1965 6 8) (to-string (+ d '(-1 week)))) "1965-06-01")
62
- ("advances by 1 week" (let d (date 1965 6 8) (to-string (+ d '( 1 week)))) "1965-06-15")
63
- ("advances by 2 weeks" (let d (date 1965 6 8) (to-string (+ d '( 2 week)))) "1965-06-22")
64
-
65
- ("advances by -2 days" (let d (date 1965 6 8) (to-string (+ d '(-2 day)))) "1965-06-06")
66
- ("advances by -1 day" (let d (date 1965 6 8) (to-string (+ d '(-1 day)))) "1965-06-07")
67
- ("advances by 1 day" (let d (date 1965 6 8) (to-string (+ d '( 1 day)))) "1965-06-09")
68
- ("advances by 2 days" (let d (date 1965 6 8) (to-string (+ d '( 2 day)))) "1965-06-10")
69
-
70
- ("advances by -2 months" (let d (date 1965 6 8) (to-string (+ d '(-2 month)))) "1965-04-08")
71
- ("advances by -1 month" (let d (date 1965 6 8) (to-string (+ d '(-1 month)))) "1965-05-08")
72
- ("advances by 1 month" (let d (date 1965 6 8) (to-string (+ d '( 1 month)))) "1965-07-08")
73
- ("advances by 2 months" (let d (date 1965 6 8) (to-string (+ d '( 2 month)))) "1965-08-08")
74
-
75
- ("advances by -2 years" (let d (date 1965 6 8) (to-string (+ d '(-2 year)))) "1963-06-08")
76
- ("advances by -1 year" (let d (date 1965 6 8) (to-string (+ d '(-1 year)))) "1964-06-08")
77
- ("advances by 1 year" (let d (date 1965 6 8) (to-string (+ d '( 1 year)))) "1966-06-08")
78
- ("advances by 2 years" (let d (date 1965 6 8) (to-string (+ d '( 2 year)))) "1967-06-08")
79
-
80
- ("adapts for leap years" (let d (date 2019 12 31) (to-string (+ d '( 2 month)))) "2020-02-29")
81
- ("jumps one year" (let d (date 2019 12 31) (to-string (+ d '( 1 year) ))) "2020-12-31")
82
- ("jumps to 28 feb a year later" (let d (date 2019 12 31) (to-string (+ d '(14 month)))) "2021-02-28")
83
- ("jumps to end of june" (let d (date 2019 12 31) (to-string (+ d '( 6 month)))) "2020-06-30")
84
- ("jumps to end of july" (let d (date 2019 12 31) (to-string (+ d '( 7 month)))) "2020-07-31")
85
- ("jumps from end feb to end feb" (let d (date 2020 02 29) (to-string (+ d '(12 month)))) "2021-02-28")
86
-
87
- ("finds anniversary before a given date in previous year"
88
- (to-string (anniversary/previous (date 2019 6 21) (date 1949 10 3)))
89
- "2018-10-03")
90
-
91
- ("finds anniversary before a given date in same year"
92
- (to-string (anniversary/previous (date 2019 11 20) (date 1949 10 3)))
93
- "2019-10-03")
94
-
95
- ("finds anniversary after a given date in same year"
96
- (to-string (anniversary/next (date 2019 6 21) (date 1949 10 3)))
97
- "2019-10-03")
98
-
99
-
100
- ("finds anniversary after a given date in following year"
101
- (to-string (anniversary/next (date 2019 11 20) (date 1949 10 3)))
102
- "2020-10-03")
103
- )
2
+ ("creates a single date" (to-string (date 1965 6 8)) "1965-06-08" )
3
+ ("navigates to next day" (let d (date 2004 3 11) (to-string d.tomorrow)) "2004-03-12" )
4
+ ("navigates to previous day" (let d (date 2006 6 22) (to-string d.yesterday)) "2006-06-21" )
5
+ ("navigates to previous year" (let d (date 1971 12 18) (to-string d.last-year)) "1970-12-18" )
6
+ ("navigates to next year" (let d (date 1974 1 11) (to-string d.next-year)) "1975-01-11" )
7
+ ("navigates to previous month" (let d (date 1971 12 18) (to-string d.last-month)) "1971-11-18" )
8
+ ("navigates to next month" (let d (date 1974 1 11) (to-string d.next-month)) "1974-02-11" )
9
+ ("jumps a year to previous month" (let d (date 1974 1 11) (to-string d.last-month)) "1973-12-11" )
10
+ ("navigates to previous week" (let d (date 2008 2 16) (to-string d.last-week)) "2008-02-09" )
11
+ ("navigates to next week" (let d (date 1972 11 13) (to-string d.next-week)) "1972-11-20" )
12
+ ("navigates to year start" (let d (date 1972 11 13) (to-string d.beginning-of-year)) "1972-01-01" )
13
+ ("navigates to year end" (let d (date 1972 11 13) (to-string d.end-of-year)) "1972-12-31" )
14
+ ("navigates to month start" (let d (date 1971 11 18) (to-string d.beginning-of-month)) "1971-11-01" )
15
+ ("navigates to month end" (let d (date 1971 11 18) (to-string d.end-of-month)) "1971-11-30" )
16
+ ("navigates to week start" (let d (date 2015 11 6) (to-string d.beginning-of-week)) "2015-11-02" )
17
+ ("navigates to week start from sun" (let d (date 2015 11 1) (to-string d.beginning-of-week)) "2015-10-26" )
18
+ ("navigates to week end from sun" (let d (date 2015 11 1) (to-string d.end-of-week)) "2015-11-01" )
19
+ ("navigates to week end" (let d (date 2015 11 6) (to-string d.end-of-week)) "2015-11-08" )
20
+
21
+ ("works with apply" (to-string (apply date '(2006 6 21))) "2006-06-21")
22
+ ("works with apply again" (to-string (apply date 2006 6 21 nil)) "2006-06-21")
23
+
24
+ ("parses string" (let d (date "2004-03-12") (list d.year d.month d.day)) (2004 3 12))
25
+
26
+ ("can act as hash key"
27
+ (with (h {} d (date 2015 11 8))
28
+ (hash-set h d "on this day")
29
+ (to-string (hash-get h (date 2015 11 8))))
30
+ "on this day")
31
+
32
+ ("equals itself" (eq? (date 2004 3 12) (date 2004 3 12)) t )
33
+ ("does not equal another" (eq? (date 2004 3 12) (date 2006 6 21)) nil)
34
+ ("does not equal nil" (eq? (date 2004 3 12) nil ) nil)
35
+ ("nil does not equal a date" (eq? nil (date 2004 3 12) ) nil)
36
+
37
+ ("returns its year" (let d (date 1999 12 31) d.year) 1999)
38
+ ("returns its month" (let d (date 1999 12 31) d.month) 12 )
39
+ ("returns its day" (let d (date 1999 12 31) d.day) 31 )
40
+ ("returns its week-day" (let d (date 1999 12 31) d.week-day) 5 )
41
+ ("recognises not monday" (let d (date 2015 11 1) d.monday? ) nil )
42
+ ("recognises monday" (let d (date 2015 11 2) d.monday? ) t )
43
+ ("recognises tuesday" (let d (date 2015 11 3) d.tuesday? ) t )
44
+ ("recognises wednesday" (let d (date 2015 11 4) d.wednesday?) t )
45
+ ("recognises thursday" (let d (date 2015 11 5) d.thursday? ) t )
46
+ ("recognises friday" (let d (date 2015 11 6) d.friday? ) t )
47
+ ("recognises not friday" (let d (date 2015 11 7) d.friday? ) nil )
48
+ ("recognises saturday" (let d (date 2015 11 7) d.saturday? ) t )
49
+ ("recognises sunday" (let d (date 2015 11 8) d.sunday? ) t )
50
+ ("adds days" (let d (date 2015 11 8) (to-string (+ d 1))) "2015-11-09")
51
+ ("adds more days" (let d (date 2015 11 8) (to-string (+ d 10))) "2015-11-18")
52
+ ("subtracts a day" (let d (date 2015 11 18) (to-string (- d 1))) "2015-11-17")
53
+ ("subtracts more days" (let d (date 2015 11 18) (to-string (- d 5))) "2015-11-13")
54
+
55
+ ("advances by -2 weeks" (let d (date 1965 6 8) (to-string (+ d '(-2 week)))) "1965-05-25")
56
+ ("advances by -1 week" (let d (date 1965 6 8) (to-string (+ d '(-1 week)))) "1965-06-01")
57
+ ("advances by 1 week" (let d (date 1965 6 8) (to-string (+ d '( 1 week)))) "1965-06-15")
58
+ ("advances by 2 weeks" (let d (date 1965 6 8) (to-string (+ d '( 2 week)))) "1965-06-22")
59
+
60
+ ("advances by -2 weeks" (let d (date 1965 6 8) (to-string (+ d '(-2 week)))) "1965-05-25")
61
+ ("advances by -1 week" (let d (date 1965 6 8) (to-string (+ d '(-1 week)))) "1965-06-01")
62
+ ("advances by 1 week" (let d (date 1965 6 8) (to-string (+ d '( 1 week)))) "1965-06-15")
63
+ ("advances by 2 weeks" (let d (date 1965 6 8) (to-string (+ d '( 2 week)))) "1965-06-22")
64
+
65
+ ("advances by -2 days" (let d (date 1965 6 8) (to-string (+ d '(-2 day)))) "1965-06-06")
66
+ ("advances by -1 day" (let d (date 1965 6 8) (to-string (+ d '(-1 day)))) "1965-06-07")
67
+ ("advances by 1 day" (let d (date 1965 6 8) (to-string (+ d '( 1 day)))) "1965-06-09")
68
+ ("advances by 2 days" (let d (date 1965 6 8) (to-string (+ d '( 2 day)))) "1965-06-10")
69
+
70
+ ("advances by -2 months" (let d (date 1965 6 8) (to-string (+ d '(-2 month)))) "1965-04-08")
71
+ ("advances by -1 month" (let d (date 1965 6 8) (to-string (+ d '(-1 month)))) "1965-05-08")
72
+ ("advances by 1 month" (let d (date 1965 6 8) (to-string (+ d '( 1 month)))) "1965-07-08")
73
+ ("advances by 2 months" (let d (date 1965 6 8) (to-string (+ d '( 2 month)))) "1965-08-08")
74
+
75
+ ("advances by -2 years" (let d (date 1965 6 8) (to-string (+ d '(-2 year)))) "1963-06-08")
76
+ ("advances by -1 year" (let d (date 1965 6 8) (to-string (+ d '(-1 year)))) "1964-06-08")
77
+ ("advances by 1 year" (let d (date 1965 6 8) (to-string (+ d '( 1 year)))) "1966-06-08")
78
+ ("advances by 2 years" (let d (date 1965 6 8) (to-string (+ d '( 2 year)))) "1967-06-08")
79
+
80
+ ("adapts for leap years" (let d (date 2019 12 31) (to-string (+ d '( 2 month)))) "2020-02-29")
81
+ ("jumps one year" (let d (date 2019 12 31) (to-string (+ d '( 1 year) ))) "2020-12-31")
82
+ ("jumps to 28 feb a year later" (let d (date 2019 12 31) (to-string (+ d '(14 month)))) "2021-02-28")
83
+ ("jumps to end of june" (let d (date 2019 12 31) (to-string (+ d '( 6 month)))) "2020-06-30")
84
+ ("jumps to end of july" (let d (date 2019 12 31) (to-string (+ d '( 7 month)))) "2020-07-31")
85
+ ("jumps from end feb to end feb" (let d (date 2020 02 29) (to-string (+ d '(12 month)))) "2021-02-28")
86
+
87
+ ("finds anniversary before a given date in previous year"
88
+ (to-string (anniversary/previous (date 2019 6 21) (date 1949 10 3)))
89
+ "2018-10-03")
90
+
91
+ ("finds anniversary before a given date in same year"
92
+ (to-string (anniversary/previous (date 2019 11 20) (date 1949 10 3)))
93
+ "2019-10-03")
94
+
95
+ ("finds anniversary after a given date in same year"
96
+ (to-string (anniversary/next (date 2019 6 21) (date 1949 10 3)))
97
+ "2019-10-03")
98
+
99
+
100
+ ("finds anniversary after a given date in following year"
101
+ (to-string (anniversary/next (date 2019 11 20) (date 1949 10 3)))
102
+ "2020-10-03"))
103
+
104
+ (examples-for future?
105
+ ("is true for a future date"
106
+ (let d (+ (today) 10)
107
+ d.future?)
108
+ t)
109
+ ("is false for a past date"
110
+ (let d (- (today) 10)
111
+ d.future?)
112
+ nil)
113
+ ("is false for today"
114
+ (let d (today)
115
+ d.future?)
116
+ nil))
117
+
118
+ (examples-for past?
119
+ ("is true for a past date"
120
+ (let d (- (today) 10)
121
+ d.past?)
122
+ t)
123
+ ("is false for a future date"
124
+ (let d (+ (today) 10)
125
+ d.past?)
126
+ nil)
127
+ ("is false for today"
128
+ (let d (today)
129
+ d.past?)
130
+ nil))
@@ -76,7 +76,7 @@
76
76
  ("warns about arg names shadowing macro names"
77
77
  (do (without-hooks 'warnings/new
78
78
  λ(on-err nil
79
- (pre-compile '(fun (aif (and or) . when)
79
+ (apply macs.fun '((aif (and or) . when)
80
80
  ignore))))
81
81
  warnings/list)
82
82
  ((arg-shadows-macro "arg " when " shadows macro " when " in arg list " (aif (and or) . when) " and body " (ignore) )
@@ -1,5 +1,5 @@
1
1
  (mac this-is-a-well-documented-macro (a b c)
2
- ; documentation for me!
2
+ ; documentation for this mac!
3
3
  `(foo ,a ,b ,c))
4
4
 
5
5
  (mac this-is-an-undocumented-macro (a b c)
@@ -23,7 +23,7 @@
23
23
 
24
24
  ("finds documentation for a documented macro"
25
25
  (hash-get (car:dox-lookup 'this-is-a-well-documented-macro) 'texts)
26
- ("documentation for me!"))
26
+ ("documentation for this mac!"))
27
27
 
28
28
  ("finds arg names for a documented macro"
29
29
  (hash-get (car:dox-lookup 'this-is-a-well-documented-macro) 'args)
@@ -27,6 +27,24 @@
27
27
  (" t for a hash" (hash? {a 1 b 2}) t )
28
28
  ("nil for a symbol" (hash? 'foo) nil))
29
29
 
30
+ (examples-for hash-to-array
31
+ ("returns empty list for empty hash"
32
+ (hash-to-array {})
33
+ ())
34
+
35
+ ("returns one-element list for single-element hash"
36
+ (hash-to-array { a 1})
37
+ ((a 1)))
38
+
39
+ ("returns a list of two-element lists"
40
+ (hash-to-array { a 1 b 2 c 3 })
41
+ ((a 1) (b 2) (c 3))))
42
+
43
+ (examples-for map-hash
44
+ ("converts a hash to a list of objects"
45
+ (to-string:map-hash (fn (k v) { name k price v }) { a 1 b 2 c 3 })
46
+ "({:name=>:a, :price=>1} {:name=>:b, :price=>2} {:name=>:c, :price=>3})"))
47
+
30
48
  (examples-for hash-slice
31
49
  ("returns a new hash containing only the specified keys"
32
50
  (let h (hash-slice { a 1 b 2 c 3 d 4 } '(a b e f))
@@ -45,39 +63,40 @@
45
63
  ((a "b" 3 b) 99 2 "foo" 98)))
46
64
 
47
65
  (examples-for hash-keys
48
- ("returns nil for a number" (hash-keys 1) nil)
49
- ("returns nil for nil" (hash-keys nil) nil)
50
- ("returns nil for a string" (hash-keys "hello") nil)
51
- ("returns nil for a symbol" (hash-keys 'lipstick) nil)
52
-
53
- ("returns date operations"
54
- (sort:hash-keys (date 2015 11 18))
55
- (age
56
- beginning_of_month
57
- beginning_of_week
58
- beginning_of_year
59
- day
60
- end_of_month
61
- end_of_week
62
- end_of_year
63
- friday?
64
- last_month
65
- last_week
66
- last_year
67
- monday?
68
- month
69
- next_month
70
- next_week
71
- next_year
72
- saturday?
73
- sunday?
74
- thursday?
75
- tomorrow
76
- tuesday?
77
- wednesday?
78
- week_day
79
- year
80
- yesterday))
66
+ ("returns nil for a number" (hash-keys 1) nil)
67
+ ("returns nil for nil" (hash-keys nil) nil)
68
+ ("returns nil for a string" (hash-keys "hello") nil)
69
+ ("returns nil for a symbol" (hash-keys 'lipstick) nil)
70
+ ("returns nil for a date" (hash-keys (date 2015 11 18)) nil)
71
+
72
+ ;; ("returns date operations"
73
+ ;; (sort:hash-keys (date 2015 11 18))
74
+ ;; (age
75
+ ;; beginning_of_month
76
+ ;; beginning_of_week
77
+ ;; beginning_of_year
78
+ ;; day
79
+ ;; end_of_month
80
+ ;; end_of_week
81
+ ;; end_of_year
82
+ ;; friday?
83
+ ;; last_month
84
+ ;; last_week
85
+ ;; last_year
86
+ ;; monday?
87
+ ;; month
88
+ ;; next_month
89
+ ;; next_week
90
+ ;; next_year
91
+ ;; saturday?
92
+ ;; sunday?
93
+ ;; thursday?
94
+ ;; tomorrow
95
+ ;; tuesday?
96
+ ;; wednesday?
97
+ ;; week_day
98
+ ;; year
99
+ ;; yesterday))
81
100
 
82
101
  ("returns keys of a given hash"
83
102
  (hash-keys {a 1 b 2 c { x 99 y 98 z 97 }})
@@ -127,3 +146,9 @@
127
146
  (let hsh { (joinstr " " zi chi) 10 "yesterday" 11 }
128
147
  (list "hello world" (hash-get hsh "hello world") "yesterday" (hash-get hsh "yesterday"))))
129
148
  ("hello world" 10 "yesterday" 11)))
149
+
150
+ (examples-for hash-transform-values
151
+ ("returns a new hash with the same keys as the given hash, where each corresponding value is transformed by the given transform function"
152
+ (let h { a 1 b 2 c 3 d 4 }
153
+ (to-list (hash-transform-values λkvi(* v v) h)))
154
+ ((a 1) (b 4) (c 9) (d 16))))
@@ -224,6 +224,121 @@
224
224
  (list/fill '(a b c) λ(++ idx) 10))
225
225
  (a b c 1 2 3 4 5 6 7)))
226
226
 
227
+ (examples-for list/index-of
228
+ ("returns nil if thing is not found in an empty list"
229
+ (list/index-of 5 '())
230
+ nil)
231
+
232
+ ("returns nil if thing is not found"
233
+ (list/index-of 5 '(1 2 3 4))
234
+ nil)
235
+
236
+ ("returns 0 if thing is first in the list"
237
+ (list/index-of 'a '(a b c d a b c d))
238
+ 0)
239
+
240
+ ("returns 1 if thing is second in the list"
241
+ (list/index-of 'b '(a b c d a b c d))
242
+ 1)
243
+
244
+ ("returns 2 if thing is third in the list"
245
+ (list/index-of 'c '(a b c d a b c d))
246
+ 2))
247
+
248
+ (examples-for list/around-thing
249
+ ("returns nil,nil if item is not in the empty list"
250
+ (list/around-thing 6 '())
251
+ (nil nil))
252
+
253
+ ("returns nil,nil if item is not in the list"
254
+ (list/around-thing 6 '(1 2 3 4 5))
255
+ (nil nil))
256
+
257
+ ("returns nil,next if item is at the start of the list"
258
+ (list/around-thing 1 '(1 2 3 4 5))
259
+ (nil 2))
260
+
261
+ ("returns prev,nil if item is at the end of the list"
262
+ (list/around-thing 5 '(1 2 3 4 5))
263
+ (4 nil))
264
+
265
+ ("returns nil,nil if item is the only element of the list"
266
+ (list/around-thing 42 '(42))
267
+ (nil nil))
268
+
269
+ ("returns prev,next if item is the second element of a longer list list"
270
+ (list/around-thing 2 '(1 2 3 4 5))
271
+ (1 3))
272
+
273
+ ("returns prev,next if item is the second-last element of a longer list list"
274
+ (list/around-thing 4 '(1 2 3 4 5))
275
+ (3 5))
276
+
277
+ ("returns prev,next if item is anywhere in the middle of a longer list list"
278
+ (list/around-thing 3 '(1 2 3 4 5))
279
+ (2 4)))
280
+
281
+ (examples-for list/around
282
+ ("returns nil,nil if index is nil"
283
+ (list/around nil '(a b c d e))
284
+ (nil nil))
285
+
286
+ ("returns nil,nil if index is nil and list is empty"
287
+ (list/around nil '())
288
+ (nil nil))
289
+
290
+ ("returns nil,nil if index is negative"
291
+ (list/around -1 '(a b c d e))
292
+ (nil nil))
293
+
294
+ ("returns nil,nil if index is negative and list is empty"
295
+ (list/around -1 '())
296
+ (nil nil))
297
+
298
+ ("returns nil,nil if index is out of range"
299
+ (list/around 10 '(a b c d e))
300
+ (nil nil))
301
+
302
+ ("returns nil,nil if index is out of range and list is empty"
303
+ (list/around 10 '())
304
+ (nil nil))
305
+
306
+ ("returns nil,nil if index is even slightly out of range"
307
+ (list/around 5 '(a b c d e))
308
+ (nil nil))
309
+
310
+ ("returns nil,next if index is zero"
311
+ (list/around 0 '(a b c d e))
312
+ (nil b))
313
+
314
+ ("returns nil,nil if index is zero and list is empty"
315
+ (list/around 0 '())
316
+ (nil nil))
317
+
318
+ ("returns nil,nil if index is one and list is empty"
319
+ (list/around 1 '())
320
+ (nil nil))
321
+
322
+ ("returns prev,nil index is at the end of the list"
323
+ (list/around 4 '(a b c d e))
324
+ (d nil))
325
+
326
+ ("returns nil,nil if index is 0 and list has only one item"
327
+ (list/around 0 '(xxx))
328
+ (nil nil))
329
+
330
+ ("returns prev,next if index is 1"
331
+ (list/around 1 '(a b c d e))
332
+ (a c))
333
+
334
+ ("returns prev,next if index corresponds to the second-last element of a longer list"
335
+ (list/around 3 '(a b c d e))
336
+ (c e))
337
+
338
+ ("returns prev,next if index is anywhere in the middle of a longer list"
339
+ (list/around 2 '(a b c d e))
340
+ (b d)))
341
+
227
342
  (examples-for list/last
228
343
  ("returns the thing if it's nil"
229
344
  (list/last nil)
@@ -233,14 +348,35 @@
233
348
  (list/last 42)
234
349
  42)
235
350
 
351
+ ("is not tricked when the last item is itself a list"
352
+ (list/last '(1 2 3 (a b c)))
353
+ (a b c))
354
+
355
+ ;; (1 2 3 . (a b c)) is equivalent to '(1 2 3 a b c)
356
+ ("is not tricked by tricky syntax"
357
+ (list/last '(1 2 3 . (a b c)))
358
+ c)
359
+
360
+ ("is not tricked when the last list-item is a list but there is also a last-cdr"
361
+ (list/last '(1 2 3 (a b c) . foo))
362
+ foo)
363
+
236
364
  ("returns the cdr if it's not a pair"
237
365
  (list/last '(x . y))
238
366
  y)
239
367
 
368
+ ("returns the cdr if it's not a pair"
369
+ (list/last '(x nil . y))
370
+ y)
371
+
372
+ ("dot nil is not real"
373
+ (list/last '(x q . nil))
374
+ q)
375
+
240
376
  ("returns the last item in the list"
241
377
  (list/last '(x y z))
242
378
  z)
243
379
 
244
380
  ("returns nil if it's the last item in the list"
245
- (list/last '(x y z nil))
381
+ (list/last '(x nil y z nil))
246
382
  nil))
@@ -285,6 +285,18 @@ toto")
285
285
  (pp '(percent-syntax || (dot-syntax x y)))
286
286
  "%x.y")
287
287
 
288
+ ("percent-syntax with args"
289
+ (pp '(%tr.klakla
290
+ (%td:otherkla:joinstr ", " (map &firstname ppl))
291
+ (%td:otherkla:joinstr ", " (map &email ppl))))
292
+ "(%tr.klakla
293
+ (%td:otherkla:joinstr
294
+ \", \"
295
+ (map &firstname ppl))
296
+ (%td:otherkla:joinstr
297
+ \", \"
298
+ (map &email ppl)))")
299
+
288
300
  ("brace list"
289
301
  (pp '(let hello {a 1 b "two" c 'three d ,four e (sub invocation) f {sub brace list here} }))
290
302
  "(let hello { a 1
@@ -0,0 +1,26 @@
1
+ (examples-for rotate-2d-array
2
+ ("returns nothing for nothing"
3
+ (rotate-2d-array nil)
4
+ nil)
5
+
6
+ ("returns transformed array"
7
+ (rotate-2d-array
8
+ '((a b c d)
9
+ (1 2 3 4)
10
+ (w x y z)
11
+ (one two three four)
12
+ (un deux trois quatre)))
13
+ ((a 1 w one un)
14
+ (b 2 x two deux)
15
+ (c 3 y three trois)
16
+ (d 4 z four quatre)))
17
+
18
+ ("first given list determines number of lists"
19
+ (rotate-2d-array
20
+ '((a b)
21
+ (1 2 3 4)
22
+ (w x y z)
23
+ (one two three four)
24
+ (un deux trois quatre)))
25
+ ((a 1 w one un)
26
+ (b 2 x two deux))))
@@ -16,8 +16,8 @@
16
16
  (let hh (list { a 1 b 2 } { a 7 b 9 } { a 3 b 1 } { a 2 b 8 })
17
17
  (pp (sort-by &a hh)))
18
18
  "({ a 1 b 2 } { a 2 b 8 }
19
- { a 3 b 1 }
20
- { a 7 b 9 })")
19
+ { a 3 b 1 }
20
+ { a 7 b 9 })")
21
21
 
22
22
  ("sorts a list of strings according to their length"
23
23
  (sort-by len
@@ -30,9 +30,9 @@
30
30
  ("max" "min" "sport" "short" "very song" "very long")))
31
31
 
32
32
  (examples-for safe-sort-by
33
- ("sorts a list of hashes by a specified key"
33
+ ("sorts a list of hashes by a specified key function, with default sort value if key function returns nil"
34
34
  (let hh (list { a 1 b 2 } { b 9 } { a 3 b 1 } { a nil b 8 })
35
35
  (pp (safe-sort-by &a 99 hh)))
36
36
  "({ a 1 b 2 } { a 3 b 1 }
37
- { a nil b 8 }
38
- { b 9 })"))
37
+ { a nil b 8 }
38
+ { b 9 })"))
@@ -13,12 +13,23 @@
13
13
 
14
14
  ("reports errors"
15
15
  (on-err errors
16
- (let s "hello \~|u|, \~x + \~y is \~(+ x y), thank heavens!"
16
+ (let s "hello \~|u|, \~x + \~y is \~(+ 2 y), thank heavens!"
17
17
  (string/eval-with-args s '(a b c) "world" 36 6)))
18
- ("error evaluating \"hello \~|u|, \~x + \~y is \~(+ x y), thank heavens!\"
19
- with arg names (a b c)
20
- and args (\"world\" 36 6)"
21
- "unbound symbol: y")))
18
+ ("error evaluating \"hello \~|u|, \~x + \~y is \~(+ 2 y), thank heavens!\"
19
+ with arg names (a b c)\nand args (\"world\" 36 6)"
20
+
21
+ "Called builtin/apply
22
+ with args
23
+ NydpGenerated_2F5C2EF513C87E2349A55BCB331F83CC856076BBB89CDFAAA1817D62AFEEF0DB.rb:15
24
+ (fn (a b c) (string-pieces \"hello \" u \", \" x \" + \" y \" is \" (+ 2 y) \", thank heavens!\"))
25
+ (\"world\" 36 6)"
26
+
27
+ "Called builtin/+
28
+ with args
29
+ 2
30
+ nil"
31
+
32
+ "nil can't be coerced into Integer")))
22
33
 
23
34
  (examples-for string/pad-left
24
35
  ("does not change a string whose length is greater than the given length"
@@ -9,11 +9,12 @@
9
9
 
10
10
  ("dislikes no-prefix"
11
11
  (on-err (joinstr "\n" errors)
12
- (pre-compile '(:foo 1 2 3)))
12
+ (pre-compile (car (parse "(:foo 1 2 3)"))))
13
13
  "expanding
14
14
  (colon-syntax || foo)
15
15
  with
16
- (fn names ((orf (hash-get colon-syntax-overrides car [0#0#0]names) default-colon-syntax) [0#0#0]names))
16
+ NydpGenerated_D5FEA04F6E33706A6789A4F7BD15E937C3CFFAF5C16B89D54087F38BD4E594D1.rb:24
17
+ (fn names ((orf (hash-get colon-syntax-overrides (car names)) default-colon-syntax) names))
17
18
  Irregular ': syntax: got (|| foo) : not prefix-syntax : in :foo"))
18
19
 
19
20
  (examples-for prefix-list
@@ -36,3 +37,10 @@ Irregular ': syntax: got (|| foo) : not prefix-syntax : in :foo"))
36
37
  ("with two args, to be sure"
37
38
  (λpq(+ p (* p q)) 3 5)
38
39
  18))
40
+
41
+ (examples-for tilde-prefix-expansion
42
+ ("tilde expands to to-string"
43
+ (with (a (to-string (date "2004-03-12"))
44
+ b ~(date "2004-03-12"))
45
+ (list a b))
46
+ ("2004-03-12" "2004-03-12")))