fancy 0.3.3 → 0.4.0

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 (182) hide show
  1. data/README.md +14 -14
  2. data/Rakefile +16 -4
  3. data/bin/fancy +3 -0
  4. data/bin/fspec +20 -0
  5. data/bin/fyi +27 -11
  6. data/bin/ifancy +1 -1
  7. data/boot/fancy_ext.rb +1 -0
  8. data/boot/fancy_ext/block_env.rb +1 -9
  9. data/boot/fancy_ext/delegator.rb +64 -0
  10. data/boot/fancy_ext/object.rb +4 -0
  11. data/boot/fancy_ext/thread.rb +4 -0
  12. data/boot/load.rb +5 -1
  13. data/boot/rbx-compiler/compiler/ast.rb +0 -1
  14. data/boot/rbx-compiler/compiler/ast/class_def.rb +2 -0
  15. data/boot/rbx-compiler/compiler/ast/method_def.rb +2 -0
  16. data/boot/rbx-compiler/compiler/ast/node.rb +10 -0
  17. data/boot/rbx-compiler/compiler/ast/ruby_args.rb +12 -0
  18. data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +2 -0
  19. data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
  20. data/boot/rbx-compiler/parser/lexer.lex +5 -11
  21. data/boot/rbx-compiler/parser/parser.rb +16 -5
  22. data/boot/rbx-compiler/parser/parser.y +39 -24
  23. data/doc/api/fancy.css +1 -1
  24. data/doc/api/fancy.jsonp +1 -1
  25. data/doc/api/fdoc.js +22 -4
  26. data/doc/api/index.html +5 -6
  27. data/doc/api/jquery-ui.min.js +401 -0
  28. data/doc/api/jquery.tools.min.js +192 -0
  29. data/doc/api/themeswitchertool.js +250 -0
  30. data/doc/features.md +17 -0
  31. data/examples/actor_bunnies.fy +32 -0
  32. data/examples/actors.fy +26 -0
  33. data/examples/actors_primitive.fy +27 -0
  34. data/examples/actors_ring.fy +37 -0
  35. data/examples/armstrong_numbers.fy +1 -1
  36. data/examples/array.fy +7 -9
  37. data/examples/async_send.fy +1 -2
  38. data/examples/blocks.fy +4 -4
  39. data/examples/call_with_receiver.fy +1 -1
  40. data/examples/class.fy +1 -1
  41. data/examples/default_args.fy +4 -1
  42. data/examples/define_methods.fy +2 -2
  43. data/examples/echo.fy +1 -1
  44. data/examples/factorial.fy +1 -1
  45. data/examples/future_composition.fy +2 -2
  46. data/examples/futures.fy +0 -5
  47. data/examples/game_of_life.fy +1 -1
  48. data/examples/person.fy +1 -1
  49. data/lib/argv.fy +7 -2
  50. data/lib/array.fy +109 -42
  51. data/lib/block.fy +39 -14
  52. data/lib/boot.fy +2 -0
  53. data/lib/class.fy +2 -0
  54. data/lib/compiler/ast.fy +2 -1
  55. data/lib/compiler/ast/assign.fy +2 -3
  56. data/lib/compiler/ast/async_send.fy +1 -15
  57. data/lib/compiler/ast/class_def.fy +2 -1
  58. data/lib/compiler/ast/expression_list.fy +4 -5
  59. data/lib/compiler/ast/future_send.fy +1 -10
  60. data/lib/compiler/ast/goto.fy +46 -0
  61. data/lib/compiler/ast/identifier.fy +9 -7
  62. data/lib/compiler/ast/literals.fy +8 -1
  63. data/lib/compiler/ast/match.fy +14 -4
  64. data/lib/compiler/ast/message_send.fy +34 -6
  65. data/lib/compiler/ast/method_def.fy +6 -6
  66. data/lib/compiler/ast/node.fy +3 -3
  67. data/lib/compiler/ast/range.fy +1 -0
  68. data/lib/compiler/ast/script.fy +0 -2
  69. data/lib/compiler/ast/singleton_method_def.fy +2 -4
  70. data/lib/compiler/ast/string_interpolation.fy +17 -0
  71. data/lib/compiler/ast/super.fy +5 -4
  72. data/lib/compiler/ast/try_catch.fy +8 -6
  73. data/lib/compiler/ast/tuple_literal.fy +3 -2
  74. data/lib/compiler/command.fy +0 -1
  75. data/lib/compiler/compiler.fy +1 -5
  76. data/lib/compiler/stages.fy +6 -14
  77. data/lib/documentation.fy +57 -46
  78. data/lib/enumerable.fy +257 -23
  79. data/lib/enumerator.fy +122 -15
  80. data/lib/false_class.fy +10 -1
  81. data/lib/fancy_spec.fy +263 -61
  82. data/lib/fdoc.fy +11 -25
  83. data/lib/fiber.fy +11 -0
  84. data/lib/file.fy +8 -11
  85. data/lib/future.fy +84 -5
  86. data/lib/hash.fy +65 -14
  87. data/lib/integer.fy +35 -0
  88. data/lib/iteration.fy +54 -29
  89. data/lib/message.fy +6 -0
  90. data/lib/method.fy +0 -16
  91. data/lib/nil_class.fy +58 -8
  92. data/lib/number.fy +49 -22
  93. data/lib/object.fy +371 -65
  94. data/lib/package.fy +24 -1
  95. data/lib/package/installer.fy +5 -9
  96. data/lib/package/specification.fy +2 -2
  97. data/lib/parser/ext/lexer.lex +15 -11
  98. data/lib/parser/ext/parser.y +70 -23
  99. data/lib/parser/methods.fy +33 -14
  100. data/lib/proxy.fy +33 -3
  101. data/lib/range.fy +28 -0
  102. data/lib/rbx.fy +3 -1
  103. data/lib/rbx/actor.fy +53 -0
  104. data/lib/rbx/alpha.fy +31 -0
  105. data/lib/rbx/array.fy +21 -12
  106. data/lib/rbx/bignum.fy +6 -2
  107. data/lib/rbx/block.fy +23 -26
  108. data/lib/rbx/class.fy +54 -2
  109. data/lib/rbx/code_loader.fy +8 -4
  110. data/lib/rbx/date.fy +9 -0
  111. data/lib/rbx/directory.fy +18 -0
  112. data/lib/rbx/environment_variables.fy +1 -0
  113. data/lib/rbx/exception.fy +9 -2
  114. data/lib/rbx/fiber.fy +22 -4
  115. data/lib/rbx/file.fy +5 -5
  116. data/lib/rbx/fixnum.fy +5 -0
  117. data/lib/rbx/float.fy +11 -3
  118. data/lib/rbx/hash.fy +31 -16
  119. data/lib/rbx/integer.fy +1 -0
  120. data/lib/rbx/io.fy +17 -7
  121. data/lib/rbx/match_data.fy +15 -4
  122. data/lib/rbx/method.fy +40 -7
  123. data/lib/rbx/name_error.fy +4 -0
  124. data/lib/rbx/object.fy +92 -24
  125. data/lib/rbx/range.fy +20 -6
  126. data/lib/rbx/regexp.fy +11 -3
  127. data/lib/rbx/string.fy +51 -1
  128. data/lib/rbx/stringio.fy +17 -0
  129. data/lib/rbx/symbol.fy +15 -1
  130. data/lib/rbx/system.fy +20 -2
  131. data/lib/rbx/tcp_server.fy +4 -1
  132. data/lib/rbx/tcp_socket.fy +11 -0
  133. data/lib/rbx/time.fy +6 -0
  134. data/lib/rbx/tuple.fy +14 -5
  135. data/lib/set.fy +144 -29
  136. data/lib/stack.fy +42 -11
  137. data/lib/string.fy +118 -8
  138. data/lib/struct.fy +13 -3
  139. data/lib/symbol.fy +21 -2
  140. data/lib/thread_pool.fy +2 -1
  141. data/lib/true_class.fy +45 -7
  142. data/lib/tuple.fy +27 -9
  143. data/lib/version.fy +2 -2
  144. data/ruby_lib/fancy +43 -0
  145. data/ruby_lib/fdoc +23 -0
  146. data/ruby_lib/fspec +3 -0
  147. data/ruby_lib/fyi +3 -0
  148. data/ruby_lib/ifancy +3 -0
  149. data/tests/argv.fy +5 -9
  150. data/tests/array.fy +323 -196
  151. data/tests/assignment.fy +29 -29
  152. data/tests/block.fy +72 -59
  153. data/tests/class.fy +227 -138
  154. data/tests/control_flow.fy +83 -51
  155. data/tests/documentation.fy +8 -8
  156. data/tests/enumerable.fy +8 -0
  157. data/tests/enumerator.fy +47 -29
  158. data/tests/exception.fy +49 -32
  159. data/tests/file.fy +28 -28
  160. data/tests/fixnum.fy +170 -0
  161. data/tests/future.fy +24 -7
  162. data/tests/hash.fy +55 -38
  163. data/tests/method.fy +50 -43
  164. data/tests/nil_class.fy +37 -37
  165. data/tests/object.fy +152 -70
  166. data/tests/pattern_matching.fy +67 -31
  167. data/tests/range.fy +6 -6
  168. data/tests/set.fy +101 -4
  169. data/tests/stack.fy +14 -5
  170. data/tests/string.fy +115 -61
  171. data/tests/stringio.fy +18 -0
  172. data/tests/struct.fy +27 -0
  173. data/tests/symbol.fy +19 -6
  174. data/tests/true_class.fy +34 -34
  175. data/tests/tuple.fy +30 -12
  176. metadata +103 -81
  177. data/boot/rbx-compiler/compiler/ast/require.rb +0 -20
  178. data/examples/actor.fy +0 -37
  179. data/examples/curl_async.fy +0 -37
  180. data/lib/compiler/ast/require.fy +0 -15
  181. data/tests/number.fy +0 -135
  182. data/tests/parsing/sexp.fy +0 -50
@@ -9,68 +9,85 @@ class Foo {
9
9
  }
10
10
 
11
11
  FancySpec describe: StdError with: {
12
- it: "should raise an exception and catch it correctly" for: 'raise! when: {
12
+ it: "raises an exception and catch it correctly" with: 'raise! when: {
13
13
  try {
14
14
  StdError new: "FAIL!" . raise!
15
- nil should == true # this should not occur
15
+ nil is: true # this is not occur
16
16
  } catch StdError => ex {
17
- ex message should == "FAIL!"
17
+ ex message is: "FAIL!"
18
18
  }
19
19
  }
20
20
 
21
- it: "should raise an exception inside a method and catch it correctly" when: {
21
+ it: "raises an exception and have the expected error message" with: 'raise! when: {
22
+ {
23
+ StdError new: "FAIL!" . raise!
24
+ } raises: StdError with: |e| {
25
+ e message is: "FAIL!"
26
+ }
27
+
28
+ {
29
+ "FAIL, AGAIN!" raise!
30
+ } raises: StdError with: |e| {
31
+ e message is: "FAIL, AGAIN!"
32
+ }
33
+ }
34
+
35
+ it: "raises an exception inside a method and catch it correctly" when: {
22
36
  f = Foo new
23
- f bar: "Don't raise here" . should == 'no_error
37
+ f bar: "Don't raise here" . is: 'no_error
24
38
  try {
25
- f bar: 'error . should == 'no_error
39
+ f bar: 'error . is: 'no_error
26
40
  } catch StdError => e {
27
- e message should == "Some Error"
41
+ e message is: "Some Error"
28
42
  }
29
43
  }
30
44
 
31
- # it: "should raise a NoMethodError" when: {
45
+ # it: "raises a NoMethodError" when: {
32
46
  # s = 'symbol
33
47
  # try {
34
48
  # s this_method_doesnt_exist!
35
- # nil should == true # should not execute
49
+ # nil is: true # is not execute
36
50
  # } catch NoMethodError => err {
37
- # err for_class should == Symbol
38
- # err method_name should == "this_method_doesnt_exist!"
51
+ # err for_class is: Symbol
52
+ # err method_name is: "this_method_doesnt_exist!"
39
53
  # }
40
54
  # }
41
55
 
42
- it: "should have access to variables in exception handlers defined in the surrounding scope" when: {
56
+ it: "has access to variables in exception handlers defined in the surrounding scope" when: {
43
57
  var = 1234
44
58
  try {
45
59
  var wont_work!
46
60
  } catch NoMethodError => err {
47
- var should == 1234
61
+ var is: 1234
48
62
  }
49
63
  }
50
64
 
51
- it: "should always evaluate the finally clause" when: {
65
+ it: "always evaluates the finally clause" when: {
66
+ set_in_finally = false
52
67
  try {
53
68
  x = 10 / 0 # ouch!
54
- "This should fail!" should == true # should not get here!
69
+ "This is fail!" is: true # is not get here!
55
70
  } catch ZeroDivisionError => err {
56
- err message should == "divided by 0"
71
+ err message is: "divided by 0"
57
72
  } finally {
58
73
  # this part gets always run :)
59
- "It works!" should == "It works!"
74
+ "It works!" is: "It works!"
75
+ set_in_finally is: false
76
+ set_in_finally = true
60
77
  }
78
+ set_in_finally is: true
61
79
  }
62
80
 
63
- it: "should raise a StdError when raising a String" for: 'raise! when: {
81
+ it: "raises a StdError when raising a String" with: 'raise! when: {
64
82
  msg = "A Custom Error!"
65
- try {
83
+ {
66
84
  msg raise!
67
- msg should_not == msg # this should not get executed
68
- } catch StdError => e {
69
- e message should == msg
85
+ } raises: StdError with: |e| {
86
+ e message is: msg
70
87
  }
71
88
  }
72
89
 
73
- it: "should raise and catch a custom exception correctly" for: 'raise! when: {
90
+ it: "raises and catch a custom exception correctly" with: 'raise! when: {
74
91
  class MyError : StdError{
75
92
  def initialize {
76
93
  initialize: "MyError message"
@@ -79,28 +96,28 @@ FancySpec describe: StdError with: {
79
96
 
80
97
  try {
81
98
  MyError new raise!
82
- nil should == true # will fail
99
+ nil is: true # will fail
83
100
  } catch MyError => e {
84
- e message should == "MyError message"
101
+ e message is: "MyError message"
85
102
  }
86
103
  }
87
104
 
88
- it: "should restart itself after being fixed in a catch clause" when: {
105
+ it: "restarts itself after being fixed in a catch clause" when: {
89
106
  y = 0
90
107
  x = 0
91
108
  try {
92
109
  x = 10 / y
93
110
  } catch ZeroDivisionError => e {
94
- y should == 0
95
- x should == 0
111
+ y is: 0
112
+ x is: 0
96
113
  y = 2
97
114
  retry
98
115
  }
99
- y should == 2
100
- x should == 5
116
+ y is == 2
117
+ x is == 5
101
118
  }
102
119
 
103
- it: "should always execute the finally block when defined" when: {
120
+ it: "always executes the finally block when defined" when: {
104
121
  try {
105
122
  msg = "Reraise a new Exception :P"
106
123
  try {
@@ -109,7 +126,7 @@ FancySpec describe: StdError with: {
109
126
  msg raise!
110
127
  }
111
128
  } catch StdError => e {
112
- e message should == msg
129
+ e message is: msg
113
130
  }
114
131
  }
115
132
  }
@@ -1,49 +1,49 @@
1
1
  FancySpec describe: File with: {
2
- it: "should return an array with the openmodes symbols" for: 'open:modes: when: {
2
+ it: "returns an array with the openmodes symbols" with: 'open:modes: when: {
3
3
  file = File open: "README.md" modes: ['read]
4
- file modes should == ['read]
4
+ file modes is: ['read]
5
5
  file close
6
6
  }
7
7
 
8
- it: "should be open after opening it and closed after closing" for: 'close when: {
8
+ it: "is open after opening it and closed after closing" with: 'close when: {
9
9
  file = File open: "README.md" modes: ['read]
10
- file open? should == true
10
+ file open? is: true
11
11
  file close
12
- file open? should == false
12
+ file open? is: false
13
13
  }
14
14
 
15
- it: "should be closed when not correctly opened" for: 'open? when: {
16
- { file = File new } should raise: ArgumentError
15
+ it: "is closed when not correctly opened" with: 'open? when: {
16
+ { file = File new } raises: ArgumentError
17
17
  }
18
18
 
19
- it: "should write and read from a file correctly" for: 'writeln: when: {
19
+ it: "writes and reads from a file correctly" with: 'writeln: when: {
20
20
  filename = "/tmp/read_write_test.txt"
21
21
  file = File open: filename modes: ['write]
22
22
  file writeln: "hello, world!"
23
23
  file writeln: "line number two"
24
24
  file close
25
25
 
26
- File exists?: filename . should == true
26
+ File exists?: filename . is: true
27
27
 
28
28
  file = File open: filename modes: ['read]
29
29
  lines = []
30
30
  2 times: {
31
31
  lines << (file readln)
32
32
  }
33
- lines[0] should == "hello, world!\n"
34
- lines[1] should == "line number two\n"
35
- lines should == ["hello, world!\n", "line number two\n"]
33
+ lines[0] is: "hello, world!\n"
34
+ lines[1] is: "line number two\n"
35
+ lines is: ["hello, world!\n", "line number two\n"]
36
36
 
37
37
  # delete file
38
38
  File delete: filename
39
- File exists?: filename . should == false
39
+ File exists?: filename . is: false
40
40
  }
41
41
 
42
- it: "should raise an IOError exception when trying to open an invalid file" when: {
43
- { file = File open: "/foo/bar/baz" modes: ['read] } should raise: IOError
42
+ it: "raises an IOError exception when trying to open an invalid file" when: {
43
+ { file = File open: "/foo/bar/baz" modes: ['read] } raises: IOError
44
44
  }
45
45
 
46
- it: "should rename a File" when: {
46
+ it: "renames a File" when: {
47
47
  dirname = "tmp/"
48
48
  filename = dirname ++ "foobar"
49
49
 
@@ -53,25 +53,25 @@ FancySpec describe: File with: {
53
53
  f writeln: "testing!"
54
54
  }
55
55
 
56
- Directory exists?: dirname . should == true
57
- File exists?: dirname . should == true
58
- File directory?: dirname . should == true
56
+ Directory exists?: dirname . is: true
57
+ File exists?: dirname . is: true
58
+ File directory?: dirname . is: true
59
59
 
60
60
  File rename: filename to: (filename ++ "-new")
61
- File exists?: filename . should == false
62
- File exists?: (filename ++ "-new") . should == true
61
+ File exists?: filename . is: false
62
+ File exists?: (filename ++ "-new") . is: true
63
63
  File delete: (filename ++ "-new")
64
64
  Directory delete: "tmp/"
65
65
  }
66
66
 
67
- it: "should be a directory" for: 'directory?: when: {
68
- File directory?: "lib/" . should == true
69
- File directory?: "lib/rbx" . should == true
67
+ it: "is a directory" with: 'directory?: when: {
68
+ File directory?: "lib/" . is: true
69
+ File directory?: "lib/rbx" . is: true
70
70
  }
71
71
 
72
- it: "should NOT be a directory" for: 'directory?: when: {
73
- File directory?: "src/Makefile" . should == false
74
- File directory?: "README" . should == false
75
- File directory?: "src/bootstrap/Makefile" . should == false
72
+ it: "is NOT a directory" with: 'directory?: when: {
73
+ File directory?: "src/Makefile" . is: false
74
+ File directory?: "README" . is: false
75
+ File directory?: "src/bootstrap/Makefile" . is: false
76
76
  }
77
77
  }
@@ -0,0 +1,170 @@
1
+ FancySpec describe: Fixnum with: {
2
+ it: "adds two numbers correctly" with: '+ when: {
3
+ n1 = 20
4
+ n2 = 22
5
+ n1 + n2 is: 42
6
+ }
7
+
8
+ it: "subtracts two numbers correctly" with: '- when: {
9
+ n1 = 20
10
+ n2 = 22
11
+ n1 - n2 is: -2
12
+ }
13
+
14
+ it: "multiplies two numbers correctly" with: '* when: {
15
+ n1 = 20
16
+ n2 = 22
17
+ n1 * n2 is: 440
18
+ }
19
+
20
+ it: "divides two numbers correctly" with: '/ when: {
21
+ n1 = 20
22
+ n2 = 10
23
+ n1 / n2 is: 2
24
+ }
25
+
26
+ it: "raises an exception when dividing by zero" when: {
27
+ { 10 / 0 } is raise: ZeroDivisionError
28
+ }
29
+
30
+ it: "calculates the correct modulo value" with: 'modulo: when: {
31
+ 9 % 4 is: 1
32
+ 10 modulo: 2 . is: 0
33
+ }
34
+
35
+ it: "does proper integer division" with: 'div: when: {
36
+ 50 div: 10 . is: 5
37
+ 55 div: 10 . is: 5
38
+ 5 div: 10 . is: 0
39
+ ((55 div: 10) * 10) + (55 modulo: 10) is: 55
40
+ }
41
+
42
+ it: "is the negation" with: 'negate when: {
43
+ 42 negate is: -42
44
+ }
45
+
46
+ it: "is odd" with: 'odd? when: {
47
+ 1 odd? is: true
48
+ 1 even? is: false
49
+ }
50
+
51
+ it: "is even" with: 'even? when: {
52
+ 2 odd? is: false
53
+ 2 even? is: true
54
+ }
55
+
56
+ it: "returns an array from 0 upto 10" with: 'upto: when: {
57
+ 0 upto: 10 . is: [0,1,2,3,4,5,6,7,8,9,10]
58
+ }
59
+
60
+ it: "iterates from 1 upto 10" with: 'upto:do: when: {
61
+ sum = 0
62
+ 1 upto: 10 do: |n| { sum = sum + n }
63
+ sum is: 55
64
+ }
65
+
66
+ it: "returns an array from 10 downto 0" with: 'downto: when: {
67
+ 10 downto: 0 . is: [10,9,8,7,6,5,4,3,2,1,0]
68
+ }
69
+
70
+ it: "iterates from 10 downto 1" with: 'downto:do: when: {
71
+ sum = 0
72
+ 10 downto: 1 do: |n| { sum = sum + n }
73
+ sum is: 55
74
+ }
75
+
76
+ it: "calculates the given power of itself" with: '** when: {
77
+ 2 ** 3 is: 8
78
+ 2 ** 0 is: 1
79
+ 2 ** 1 is: 2
80
+ 0 upto: 10 do: |i| {
81
+ i ** 0 is: 1
82
+ i ** 1 is: i
83
+ i ** 2 is: (i squared)
84
+ }
85
+ }
86
+
87
+ it: "is the square of self" with: 'squared when: {
88
+ 5 squared is: 25
89
+ 10 squared is: 100
90
+ 20 upto: 50 do: |i| {
91
+ i squared is: (i * i)
92
+ }
93
+ }
94
+
95
+ it: "is the double value of self" with: 'doubled when: {
96
+ 5 doubled is: 10
97
+ 10 doubled is: 20
98
+ 20 upto: 50 do: |i| {
99
+ i doubled is: (i + i)
100
+ }
101
+ }
102
+
103
+ it: "is the same when using underscores within the literal" when: {
104
+ 50000 is: 50_000
105
+ 100_000 is: 100000
106
+ 100_000 is: 100_000
107
+ 100_000 is: 100000.0
108
+ 100_000.0 is: 100000
109
+ 100_999.999 is: 100999.999
110
+ }
111
+
112
+ it: "evaluates octal literals correctly" when: {
113
+ 0o00 is: 0
114
+ 0o01 is: 1
115
+ 0o07 is: 7
116
+ 0o10 is: 8
117
+ 0o70 is: 56
118
+ }
119
+
120
+ it: "evaluates binary literals correctly" when: {
121
+ 0b00 is: 0
122
+ 0b01 is: 1
123
+ 0b10 is: 2
124
+ 0b11 is: 3
125
+ 0b100 is: 4
126
+ }
127
+
128
+ it: "evaluates hexadecimal literals correctly" when: {
129
+ 0x00 is: 0
130
+ 0x01 is: 1
131
+ 0x0A is: 10
132
+ 0xA0 is: 160
133
+ 0xFF is: 255
134
+ }
135
+
136
+ it: "calls a block a given amount of times" with: 'times: when: {
137
+ times_called = 0
138
+ 10 times: { times_called = times_called + 1 }
139
+ times_called is: 10
140
+
141
+ sum = 0
142
+ 10 times: |i| { sum = sum + i }
143
+ sum is: ((0..9) sum)
144
+ }
145
+
146
+ it: "calls a block a given amount of times with an offset" with: 'times:offset: when: {
147
+ times_called = 0
148
+ sum = 0
149
+ 10 times: |i| {
150
+ times_called = times_called + 1
151
+ sum = sum + i
152
+ } offset: 10
153
+ times_called is: 10
154
+ sum is: ((10..19) sum)
155
+ }
156
+
157
+ it: "returns the maximum" with: 'max: when: {
158
+ 0 max: 0 . is: 0
159
+ 1 max: 2 . is: 2
160
+ 2 max: 1 . is: 2
161
+ -2 max: -3 . is: -2
162
+ }
163
+
164
+ it: "returns the minimum" with: 'min: when: {
165
+ 0 min: 0 . is: 0
166
+ -1 min: 0 . is: -1
167
+ -2 min: -3 . is: -3
168
+ 2 min: 1 . is: 1
169
+ }
170
+ }
@@ -1,24 +1,41 @@
1
- FancySpec describe: Future with: {
2
- it: "should compose Futures to create execution pipelines" for: '&& when: {
1
+ FancySpec describe: FutureSend with: {
2
+ it: "returns a FutureSend" when: {
3
+ def future_send_method {
4
+ "hello, future world!"
5
+ }
6
+ f = self @ future_send_method
7
+ f is_a?: FutureSend . is: true
8
+ f value is: future_send_method
9
+ }
10
+
11
+ it: "returns nil for async sends" when: {
12
+ def async_send_method {
13
+ "hello, async world!"
14
+ }
15
+ a = self @@ async_send_method
16
+ a is: nil
17
+ }
18
+
19
+ it: "composes Futures to create execution pipelines" with: '&& when: {
3
20
  def some_computation: num {
4
21
  num upto: (num ** num ** num)
5
22
  }
6
23
 
7
- f = self @ some_computation: 2 && @{select: 'even?} && 'size
8
- f is_a?: Future . should == true
9
- f value is_a?: Fixnum . should == true
24
+ f = self @ some_computation: 2 && @{select: 'even?} && @{size}
25
+ f is_a?: FutureSend . is: true
26
+ f value is_a?: Fixnum . is: true
10
27
  }
11
28
  }
12
29
 
13
30
  FancySpec describe: FutureCollection with: {
14
- it: "should execute a block for each future in the collection when it's ready" for: 'each: when: {
31
+ it: "executes a block for each future in the collection when it's ready" with: 'each: when: {
15
32
  futures = 0 upto: 10 . map: |i| {
16
33
  i ** i @ ** i
17
34
  }
18
35
 
19
36
  fc = FutureCollection new: futures
20
37
  fc each: |val| {
21
- val is_a?: Integer . should == true
38
+ val is_a?: Integer . is: true
22
39
  }
23
40
 
24
41
  fc await_all