fancy 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,6 +1,6 @@
1
1
  VERSION_MAJOR = 0
2
- VERSION_MINOR = 3
3
- VERSION_PATCH = 3
2
+ VERSION_MINOR = 4
3
+ VERSION_PATCH = 0
4
4
  VERSION_SUFFIX = "alpha"
5
5
 
6
6
  FANCY_VERSION = [VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH] join: "." ++ " " ++ VERSION_SUFFIX
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env rbx
2
+ # -*- ruby -*-
3
+
4
+ base = File.dirname(__FILE__)
5
+ require File.expand_path("../boot/fancy_ext", base)
6
+
7
+ # Use the bootstrapping code loader.
8
+ require File.expand_path("../boot/load", base)
9
+
10
+ do_retry = true
11
+ begin
12
+ Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/boot", base)
13
+
14
+ # Remove the bootstrapping code loader
15
+ bcl = Fancy.send :remove_const, :CodeLoader
16
+ bcl.load_compiled_file File.expand_path("../lib/rbx/code_loader", base)
17
+
18
+ # Initialize the load path
19
+ Fancy::CodeLoader.push_loadpath File.expand_path("../lib", base)
20
+
21
+ # Load compiler+eval support
22
+ Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/eval", base)
23
+
24
+ # Run main
25
+ Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/main", base)
26
+
27
+ rescue RuntimeError => e
28
+ if e.message =~ /File not found (.*)lib\/boot.fyc/
29
+ if do_retry
30
+ puts "Fancy hasn't been bootstrapped yet. Doing that now.\n\n"
31
+ `cd #{base} && rbx -S rake clean && rbx -S rake`
32
+ do_retry = false
33
+ retry
34
+ else
35
+ raise e
36
+ end
37
+ else
38
+ raise e
39
+ end
40
+ rescue Interrupt => e
41
+ puts e
42
+ exit
43
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rbx
2
+ # -*- ruby -*-
3
+
4
+ class Fancy; end
5
+ class Fancy::Parser; end
6
+
7
+ # fdoc is a documentation generator for fancy.
8
+ # This is a ruby script because we need to setup a hook
9
+ # BEFORE any fancy code is loaded. So we can create
10
+ # documentation for Fancy's builtin objects as well.
11
+ # See fdoc.
12
+ base = File.expand_path("../boot", File.dirname(__FILE__))
13
+ require File.expand_path("rbx-compiler/parser/fancy_parser", base)
14
+ require File.expand_path("rbx-compiler/compiler", base)
15
+ require File.expand_path("code_loader", base)
16
+ require File.expand_path("fancy_ext", base)
17
+
18
+ Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/rbx/documentation.fyc", base)
19
+ Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/fdoc_hook.fyc", base)
20
+
21
+ Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/rbx.fyc", base)
22
+
23
+ Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/fdoc.fyc", base)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rbx
2
+ base = File.expand_path("../bin", File.dirname(__FILE__))
3
+ system("/usr/bin/env fancy #{base}/fspec #{ARGV.join(' ')}")
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rbx
2
+ base = File.expand_path("../bin", File.dirname(__FILE__))
3
+ system("/usr/bin/env fancy #{base}/fyi #{ARGV.join(' ')}")
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rbx
2
+ base = File.expand_path("../bin", File.dirname(__FILE__))
3
+ system("/usr/bin/env fancy #{base}/ifancy #{ARGV.join(' ')}")
@@ -1,14 +1,10 @@
1
1
  FancySpec describe: "ARGV & predefined values" with: {
2
- it: "should have ARGV correctly defined" when: {
3
- ARGV empty? should_not == true
2
+ it: "has ARGV correctly defined" when: {
3
+ ARGV empty? is_not: true
4
4
  }
5
5
 
6
- it: "should have a __FILE__ variable defined" when: {
7
- __FILE__ should_not == nil
8
- __FILE__ should =~ /\/argv.fy$/
9
- }
10
-
11
- it: "should have the __FILE__ value be an element in ARGV" when: {
12
- ARGV any?: |a| { File basename(a) == (File basename(__FILE__)) } . should == true
6
+ it: "has a __FILE__ variable defined" when: {
7
+ __FILE__ is_not: nil
8
+ __FILE__ is =~ /\/argv.fy$/
13
9
  }
14
10
  }
@@ -1,374 +1,501 @@
1
1
  FancySpec describe: Array with: {
2
- it: "should contain three number values after adding them" for: '<< when: {
2
+ it: "contains three number values after adding them" with: '<< when: {
3
3
  arr = []
4
4
  arr << 1
5
5
  arr << 2
6
6
  arr << 3
7
- arr should == [1,2,3]
8
- arr size should == 3
7
+ arr is: [1,2,3]
8
+ arr size is: 3
9
9
  }
10
10
 
11
- it: "should iterate over all elements, calling a block" for: 'each: when: {
11
+ it: "iterates over all elements, calling a block" with: 'each: when: {
12
12
  sum = 0
13
13
  [1,2,3,4,5] each: |x| { sum = sum + x }
14
- sum should == ([1,2,3,4,5] sum)
14
+ sum is: $ [1,2,3,4,5] sum
15
15
  }
16
16
 
17
- it: "should be empty after clearing it" for: 'clear when: {
17
+ it: "iterates over all elements in reverse" with: 'reverse_each: when: {
18
+ sum = 0
19
+ last = 5
20
+ count = 0
21
+ [1,2,3,4,5] reverse_each: |x| {
22
+ x <= last is: true
23
+ last = x
24
+ sum = sum + x
25
+ count = count + 1
26
+ }
27
+ sum is: $ [1,2,3,4,5] sum
28
+ count is: 5
29
+ last is: 1
30
+ }
31
+
32
+ it: "iterates over all elements with their index" with: 'each_with_index: when: {
33
+ sum = 0
34
+ idx_sum = 0
35
+ [10,20,30,40,50] each_with_index: |x i| {
36
+ sum = sum + x
37
+ idx_sum = idx_sum + i
38
+ }
39
+ sum is: 150
40
+ idx_sum is: 10
41
+ }
42
+
43
+ it: "is empty after clearing it" with: 'clear when: {
18
44
  arr = [1,2,3]
19
- arr size should == 3
20
- arr should == [1,2,3]
45
+ arr size is: 3
46
+ arr is: [1,2,3]
21
47
  arr clear
22
- arr size should == 0
23
- arr should == []
48
+ arr size is: 0
49
+ arr is: []
24
50
  }
25
51
 
26
- it: "should be true for empty? when it's empty" for: 'empty? when: {
27
- [] empty? should == true
28
- [1] empty? should == false
29
- [1,2] empty? should == false
30
- [1,2,3] empty? should == false
52
+ it: "is true for empty? when it's empty" with: 'empty? when: {
53
+ [] empty? is: true
54
+ [1] empty? is: false
55
+ [1,2] empty? is: false
56
+ [1,2,3] empty? is: false
31
57
  }
32
58
 
33
- it: "should be an empty array after initialization" for: 'new when: {
59
+ it: "is an empty array after initialization" with: 'new when: {
34
60
  arr = Array new
35
- arr size should == 0
61
+ arr size is: 0
36
62
  }
37
63
 
38
- it: "should return the correct value via index access" for: 'at: when: {
64
+ it: "returns the correct value via index access" with: 'at: when: {
39
65
  arr = ['a, 10, "hello, world"]
40
- arr at: 2 . should == "hello, world"
41
- arr at: 1 . should == 10
42
- arr at: 0 . should == 'a
66
+ arr at: 2 . is: "hello, world"
67
+ arr at: 1 . is: 10
68
+ arr at: 0 . is: 'a
43
69
  }
44
70
 
45
- it: "should set the value for a given index" for: 'at:put: when: {
71
+ it: "sets the value for a given index" with: '[]: when: {
46
72
  arr = [1,2,3]
47
- arr at: 0 put: 10
48
- arr should == [10, 2, 3]
49
- arr at: -1 put: 30
50
- arr should == [10, 2, 30]
51
- arr at: 1 put: 20
52
- arr should == [10,20,30]
53
- arr at: 3 put: 40
54
- arr should == [10,20,30,40]
73
+ arr[0]: 10
74
+ arr is: [10, 2, 3]
75
+ arr[-1]: 30
76
+ arr is: [10, 2, 30]
77
+ arr[1]: 20
78
+ arr is: [10,20,30]
79
+ arr[3]: 40
80
+ arr is: [10,20,30,40]
55
81
  }
56
82
 
57
- it: "should NOT include the items" for: "includes?:" when: {
83
+ it: "does NOT include the items" with: 'includes?: when: {
58
84
  arr = ['a, 10, "hello, world"]
59
- arr includes?: "hello" . should == false
60
- arr includes?: 11 . should == false
61
- arr includes?: 'b . should == false
85
+ arr includes?: "hello" . is: false
86
+ arr includes?: 11 . is: false
87
+ arr includes?: 'b . is: false
62
88
  }
63
89
 
64
- it: "should include the items" for: 'includes?: when: {
90
+ it: "includes the items" with: 'includes?: when: {
65
91
  arr = ['a, 10, "hello, world"]
66
- arr includes?: "hello, world" . should == true
67
- arr includes?: 10 . should == true
68
- arr includes?: 'a . should == true
92
+ arr includes?: "hello, world" . is: true
93
+ arr includes?: 10 . is: true
94
+ arr includes?: 'a . is: true
69
95
  }
70
96
 
71
- it: "should return the correct index (or nil) for an element" for: 'index: when: {
97
+ it: "returns the correct index (or nil) for an element" with: 'index: when: {
72
98
  arr = [1, 2, 'a, 3, 4]
73
- arr index: 1 . should == 0
74
- arr index: 2 . should == 1
75
- arr index: 'a . should == 2
76
- arr index: 3 . should == 3
77
- arr index: 4 . should == 4
78
- arr index: 'foo . should == nil
99
+ arr index: 1 . is: 0
100
+ arr index: 2 . is: 1
101
+ arr index: 'a . is: 2
102
+ arr index: 3 . is: 3
103
+ arr index: 4 . is: 4
104
+ arr index: 'foo . is: nil
79
105
  }
80
106
 
81
- it: "should return an Array of all its indices" for: 'indices when: {
82
- ['foo, 'bar, 'baz] indices should == [0,1,2]
83
- [] indices should == []
84
- ['foo] indices should == [0]
107
+ it: "returns an Array of all its indices" with: 'indices when: {
108
+ ['foo, 'bar, 'baz] indices is: [0,1,2]
109
+ [] indices is: []
110
+ ['foo] indices is: [0]
85
111
  }
86
112
 
87
- it: "should return all indices for an element as an Array" for: 'indices: when: {
113
+ it: "returns all indices for an element as an Array" with: 'indices_of: when: {
88
114
  arr = [1, 2, 'a, 3, 2, 'a]
89
- arr indices_of: 1 . should == [0]
90
- arr indices_of: 2 . should == [1, 4]
91
- arr indices_of: 'a . should == [2, 5]
92
- arr indices_of: 3. should == [3]
93
- arr indices_of: 'foo . should == []
115
+ arr indices_of: 1 . is: [0]
116
+ arr indices_of: 2 . is: [1, 4]
117
+ arr indices_of: 'a . is: [2, 5]
118
+ arr indices_of: 3. is: [3]
119
+ arr indices_of: 'foo . is: []
94
120
  }
95
121
 
96
- it: "should find the value" for: 'find: when: {
122
+ it: "finds the value" with: 'find: when: {
97
123
  arr = ['foo, "bar", 'baz, 1234]
98
124
 
99
- arr find: "bar" . should == "bar"
125
+ arr find: "bar" . is: "bar"
100
126
 
101
127
  arr find: |x| {
102
128
  x is_a?: String . if_true: {
103
129
  x from: 0 to: 1 == "ba"
104
130
  }
105
- } . should == "bar"
131
+ } . is: "bar"
106
132
 
107
- arr find: "foo" . should == nil
133
+ arr find: "foo" . is: nil
108
134
  }
109
135
 
110
- it: "should NOT find the value" for: 'find: when: {
136
+ it: "does NOT find the value" with: 'find: when: {
111
137
  arr = ['foo, "bar", 'baz, 1234]
112
138
 
113
- arr find: "ba" . should == nil
139
+ arr find: "ba" . is: nil
114
140
 
115
141
  arr find: |x| {
116
142
  x is_a?: String . if_true: {
117
143
  x from: 0 to: 1 == "aa"
118
144
  }
119
- } . should == nil
145
+ } . is: nil
120
146
 
121
- arr find: "foobar" . should == nil
147
+ arr find: "foobar" . is: nil
122
148
  }
123
149
 
124
- it: "should find the value via a block" for: 'find_by: when: {
150
+ it: "finds the value via a block" with: 'find_by: when: {
125
151
  arr = [1, 2, 'foo, "yo", nil, true]
126
- arr find_by: |x| { x is_a?: String } . should == "yo"
127
- arr find_by: |x| { x is_a?: Block } . should == nil
152
+ arr find_by: |x| { x is_a?: String } . is: "yo"
153
+ arr find_by: |x| { x is_a?: Block } . is: nil
128
154
  }
129
155
 
130
- it: "should return the last element" for: 'last when: {
156
+ it: "returns the last element" with: 'last when: {
131
157
  arr = [1, 2, 3, 'foo, "bar"]
132
- arr last should == "bar"
133
- (arr last == 'foo) should == false
158
+ arr last is: "bar"
159
+ (arr last == 'foo) is: false
134
160
  }
135
161
 
136
- it: "should return the last n element" for: 'last: when: {
162
+ it: "returns the last n element" with: 'last: when: {
137
163
  arr = [1, 2, 3, 'foo, "bar"]
138
- arr last: 1 . should == [arr last]
139
- arr last: 2 . should == ['foo, "bar"]
140
- arr last: 3 . should == [3, 'foo, "bar"]
141
- arr last: 4 . should == [2, 3, 'foo, "bar"]
142
- arr last: 5 . should == [1, 2, 3, 'foo, "bar"]
143
- arr last: (arr size) . should == arr
144
- arr last: (arr size + 1) . should == arr
164
+ arr last: 1 . is: [arr last]
165
+ arr last: 2 . is: ['foo, "bar"]
166
+ arr last: 3 . is: [3, 'foo, "bar"]
167
+ arr last: 4 . is: [2, 3, 'foo, "bar"]
168
+ arr last: 5 . is: [1, 2, 3, 'foo, "bar"]
169
+ arr last: (arr size) . is: arr
170
+ arr last: (arr size + 1) . is: arr
145
171
  }
146
172
 
147
- it: "should return an array containing the values at the given indices" for: 'values_at: when: {
173
+ it: "returns an array containing the values at the given indices" with: 'values_at: when: {
148
174
  arr = [1, 2, 3, 'foo, "bar"]
149
- arr values_at: [1, 3, 4, 10] . should == [2, 'foo, "bar", nil]
175
+ arr values_at: [1, 3, 4, 10] . is: [2, 'foo, "bar", nil]
150
176
  }
151
177
 
152
- it: "should return unique values only" for: 'uniq when: {
178
+ it: "returns unique values only" with: 'uniq when: {
153
179
  arr = ['foo, 'bar, "baz", 'foo, "baz", "hello", 1, 0, 0, 1, 'bar, 'foo, "hello"]
154
- arr uniq should == ['foo, 'bar, "baz", "hello", 1, 0]
180
+ arr uniq is: ['foo, 'bar, "baz", "hello", 1, 0]
155
181
  }
156
182
 
157
- it: "should prepend self to another array" for: '>> when: {
183
+ it: "prepends self to another array" with: '>> when: {
158
184
  arr1 = ['foo, 'bar, 'baz]
159
185
  arr2 = [1, 2, 3]
160
- (arr1 >> arr2) should == ['foo, 'bar, 'baz, 1, 2, 3]
186
+ (arr1 >> arr2) is: ['foo, 'bar, 'baz, 1, 2, 3]
161
187
  }
162
188
 
163
- it: "should get an element by the []-operator" for: "[]" when: {
189
+ it: "returns an element by the []-operator" with: '[] when: {
164
190
  arr = ['foo, 'bar, 'baz]
165
- arr[0] should == 'foo
166
- arr[1] should == 'bar
167
- arr[2] should == 'baz
191
+ arr[0] is: 'foo
192
+ arr[1] is: 'bar
193
+ arr[2] is: 'baz
168
194
  }
169
195
 
170
- it: "should get a sub-array by the []-operator" for: "[]" when: {
196
+ it: "returns a sub-array by the []-operator" with: '[] when: {
171
197
  arr = ['foo, 'bar, 'baz]
172
- arr[[0,2]] should == arr
173
- arr[[0,1]] should == ['foo, 'bar]
174
- arr[[0,1]] should == (arr from: 0 to: 1)
175
- arr[[0,0]] should == [arr[0]]
176
- arr[[1,1]] should == [arr[1]]
177
- arr[[2,2]] should == [arr[2]]
178
- arr[[0,-1]] should == arr
179
- arr[[-1,-1]] should == [arr last]
180
- arr[[-2,-1]] should == ['bar, 'baz]
181
- arr[[-2,-1]] should == (arr last: 2)
182
- }
183
-
184
- it: "should join all elements with a string to a new string" for: 'join: when: {
198
+ arr[[0,2]] is: arr
199
+ arr[[0,1]] is: ['foo, 'bar]
200
+ arr[[0,1]] is: (arr from: 0 to: 1)
201
+ arr[[0,0]] is: [arr[0]]
202
+ arr[[1,1]] is: [arr[1]]
203
+ arr[[2,2]] is: [arr[2]]
204
+ arr[[0,-1]] is: arr
205
+ arr[[-1,-1]] is: [arr last]
206
+ arr[[-2,-1]] is: ['bar, 'baz]
207
+ arr[[-2,-1]] is: (arr last: 2)
208
+ }
209
+
210
+ it: "joins all elements with a string to a new string" with: 'join: when: {
185
211
  arr = ['foo, 'bar, 'baz]
186
- arr join: "," . should == "foo,bar,baz"
212
+ arr join: "," . is: "foo,bar,baz"
187
213
  }
188
214
 
189
- it: "should join all elements with the empty string to a new string" for: 'join when: {
215
+ it: "joins all elements with the empty string to a new string" with: 'join when: {
190
216
  arr = ['foo, 'bar, 'baz]
191
- arr join should == "foobarbaz"
217
+ arr join is: "foobarbaz"
192
218
  }
193
219
 
194
- it: "should remove an element at a given index" for: 'remove_at: when: {
220
+ it: "removes an element at a given index" with: 'remove_at: when: {
195
221
  arr = [1, 'foo, 2, 'bar, 3, 'baz]
196
222
  # remove_at: returns the removed element
197
- arr remove_at: 1 . should == 'foo
198
- arr should == [1, 2, 'bar, 3, 'baz]
223
+ arr remove_at: 1 . is: 'foo
224
+ arr is: [1, 2, 'bar, 3, 'baz]
199
225
  arr remove_at: 3
200
- arr should == [1, 2, 'bar, 'baz]
226
+ arr is: [1, 2, 'bar, 'baz]
201
227
  arr remove_at: [2, 3]
202
- arr should == [1, 2]
228
+ arr is: [1, 2]
203
229
  arr = [1, 'hello, 2, 'world]
204
230
  # remove_at: returns the removed elements as an array
205
231
  # if it was passed an array of indexes
206
- arr remove_at: [0, 2, 3] . should == [1, 2, 'world]
207
- arr should == ['hello]
232
+ arr remove_at: [0, 2, 3] . is: [1, 2, 'world]
233
+ arr is: ['hello]
208
234
  }
209
235
 
210
- it: "should remove all occurances of a given object in-place" for: 'remove: when: {
236
+ it: "removes all occurances of a given object in-place" with: 'remove: when: {
211
237
  arr = [1, 2, 'foo, 3, 'foo, 2, 4]
212
238
  arr remove: 2
213
- arr should == [1, 'foo, 3, 'foo, 4]
239
+ arr is: [1, 'foo, 3, 'foo, 4]
214
240
  arr remove: 'foo
215
- arr should == [1, 3, 4]
241
+ arr is: [1, 3, 4]
216
242
  }
217
243
 
218
- it: "should remove all elements with the given Array of indices" for: 'remove_at: when: {
244
+ it: "removes all elements with the given Array of indices" with: 'remove_at: when: {
219
245
  arr = [1, 2, 'foo, 3, 'foo, 2, 4]
220
246
  arr remove_at: [0, 2, 4]
221
- arr should == [2, 3, 2, 4]
247
+ arr is: [2, 3, 2, 4]
222
248
  }
223
249
 
224
- it: "should remove all elements that meet a given condition block" for: 'remove_if: when: {
250
+ it: "removes all elements that meet a given condition block" with: 'remove_if: when: {
225
251
  arr = [1, 2, 3, 2, 5, 4]
226
252
  arr remove_if: |x| { x < 3 }
227
- arr should == [3, 5, 4]
253
+ arr is: [3, 5, 4]
228
254
  }
229
255
 
230
- it: "should remove all nil-value entries when calling compact" for: 'compact when: {
231
- ['foo, nil, 'bar, nil, 'baz] compact should == ['foo, 'bar, 'baz]
232
- [] compact should == []
233
- [nil] compact should == []
234
- ['foo] compact should == ['foo]
256
+ it: "removes all nil-value entries when calling compact" with: 'compact when: {
257
+ ['foo, nil, 'bar, nil, 'baz] compact is: ['foo, 'bar, 'baz]
258
+ [] compact is: []
259
+ [nil] compact is: []
260
+ ['foo] compact is: ['foo]
235
261
  }
236
262
 
237
- it: "should remove all nil-value entries in place when calling compact!" for: 'compact! when: {
263
+ it: "removes all nil-value entries in place when calling compact!" with: 'compact! when: {
238
264
  arr = ['foo, nil, 'bar, nil, 'baz]
239
- arr compact! should == ['foo, 'bar, 'baz]
240
- arr should == ['foo, 'bar, 'baz]
241
- [] compact! should == []
242
- [nil] compact! should == []
243
- ['foo] compact! should == ['foo]
265
+ arr compact! is: ['foo, 'bar, 'baz]
266
+ arr is: ['foo, 'bar, 'baz]
267
+ [] compact! is: []
268
+ [nil] compact! is: []
269
+ ['foo] compact! is: ['foo]
244
270
  }
245
271
 
246
- it: "should remove all values that meet a condition" for: 'reject!: when: {
272
+ it: "removes all values that meet a condition" with: 'reject!: when: {
247
273
  arr = ['foo, 'bar, 1, 2, 'baz, "hello"]
248
- arr reject!: |x| { x is_a?: String } . should == ['foo, 'bar, 1, 2, 'baz]
249
- arr should == ['foo, 'bar, 1, 2, 'baz]
274
+ arr reject!: |x| { x is_a?: String } . is: ['foo, 'bar, 1, 2, 'baz]
275
+ arr is: ['foo, 'bar, 1, 2, 'baz]
250
276
  arr reject!: |x| { x is_a?: Fixnum }
251
- arr should == ['foo, 'bar, 'baz]
277
+ arr is: ['foo, 'bar, 'baz]
252
278
  }
253
279
 
254
- it: "should remove all values that don't meet a condition" for: 'select!: when: {
280
+ it: "removes all values that don't meet a condition" with: 'select!: when: {
255
281
  arr = ['foo, 'bar, 1, 2, 'baz, "hello"]
256
282
  arr select!: |x| { x is_a?: Fixnum }
257
- arr should == [1, 2]
283
+ arr is: [1, 2]
258
284
  }
259
285
 
260
- it: "should return a new Array with all elements that meet a given condition" for: 'select: when: {
286
+ it: "returns a new Array with all elements that meet a given condition" with: 'select: when: {
261
287
  arr = [1, 2, "foo", 'bar, 120]
262
- arr select: |x| { x is_a?: Fixnum } . should == [1,2,120]
263
- arr should == [1, 2, "foo", 'bar, 120] # select: is non-destructive
288
+ arr select: |x| { x is_a?: Fixnum } . is: [1,2,120]
289
+ arr is: [1, 2, "foo", 'bar, 120] # select: is non-destructive
264
290
  }
265
291
 
266
- it: "should print the maximum value in the list" for: 'max when: {
267
- [1,2,3,4] max should == 4
268
- [1,5,-3,2,6,-4,-2] max should == 6
292
+ it: "returns the maximum value in the list" with: 'max when: {
293
+ [1,2,3,4] max is: 4
294
+ [1,5,-3,2,6,-4,-2] max is: 6
269
295
  }
270
296
 
271
- it: "should print the minimum value in the list" for: 'min when: {
272
- [1,2,3,4] min should == 1
273
- [1,5,-3,2,6,-4,-2] min should == -4
297
+ it: "prints the minimum value in the list" with: 'min when: {
298
+ [1,2,3,4] min is: 1
299
+ [1,5,-3,2,6,-4,-2] min is: -4
274
300
  }
275
301
 
276
- it: "should return an Array containing the elements n times." for: '* when: {
277
- [1,2,3,4,5] * 2 should == [1,2,3,4,5,1,2,3,4,5]
278
- [1,2,3] * 2 should == ([1,2,3] + [1,2,3])
279
- ['a,'b,'c] * 4 should == ['a,'b,'c, 'a,'b,'c, 'a,'b,'c, 'a,'b,'c]
302
+ it: "returns an Array containing the elements n times." with: '* when: {
303
+ [1,2,3,4,5] * 2 is: [1,2,3,4,5,1,2,3,4,5]
304
+ [1,2,3] * 2 is: ([1,2,3] + [1,2,3])
305
+ ['a,'b,'c] * 4 is: ['a,'b,'c, 'a,'b,'c, 'a,'b,'c, 'a,'b,'c]
280
306
  }
281
307
 
282
- it: "should return the concatenation of two Arrays" for: '+ when: {
283
- ([1,2,3,4] + [-1,-2,-3,-4]) should == [1,2,3,4,-1,-2,-3,-4]
308
+ it: "returns the concatenation of two Arrays" with: '+ when: {
309
+ ([1,2,3,4] + [-1,-2,-3,-4]) is: [1,2,3,4,-1,-2,-3,-4]
284
310
  }
285
311
 
286
- it: "should return true for all elements" for: 'all?: when: {
287
- [1,2,3,4] all?: |x| { x < 5 } . should == true
288
- [1,2,3,4] all?: |x| { x > 0 } . should == true
289
- [1,2,3,4] all?: |x| { x > 4 } . should == false
312
+ it: "returns true for all elements" with: 'all?: when: {
313
+ [1,2,3,4] all?: |x| { x < 5 } . is: true
314
+ [1,2,3,4] all?: |x| { x > 0 } . is: true
315
+ [1,2,3,4] all?: |x| { x > 4 } . is: false
290
316
  }
291
317
 
292
- it: "should return true for any elements" for: 'any?: when: {
293
- [1,2,3,4] any?: |x| { x > 3 } . should == true
294
- [1,2,3,4] any?: |x| { x < 4 } . should == true
295
- [1,2,3,4] any?: |x| { x > 4 } . should == false
318
+ it: "returns true for any elements" with: 'any?: when: {
319
+ [1,2,3,4] any?: |x| { x > 3 } . is: true
320
+ [1,2,3,4] any?: |x| { x < 4 } . is: true
321
+ [1,2,3,4] any?: |x| { x > 4 } . is: false
296
322
  }
297
323
 
298
- it: "should be selected from it with each index" for: 'select_with_index: when: {
299
- ["yooo",2,3,1,'foo,"bar"] select_with_index: |x i| { x is_a?: Fixnum } . should == [[2,1], [3,2], [1,3]]
324
+ it: "is selected from it with each index" with: 'select_with_index: when: {
325
+ ["yooo",2,3,1,'foo,"bar"] select_with_index: |x i| { x is_a?: Fixnum } . is: [[2,1], [3,2], [1,3]]
300
326
  }
301
327
 
302
- it: "should return its remaining (all but the first) elements as a new Array" for: 'rest when: {
303
- [1,2,3,4] rest should == [2,3,4]
304
- [] rest should == []
305
- 100 upto: 1000 . rest should == (101 upto: 1000)
328
+ it: "returns its remaining (all but the first) elements as a new Array" with: 'rest when: {
329
+ [1,2,3,4] rest is: [2,3,4]
330
+ [] rest is: []
331
+ 100 upto: 1000 . rest is: (101 upto: 1000)
306
332
  }
307
333
 
308
- it: "should return itself as a string" for: 'to_s when: {
309
- [1,2,3] to_s should == "123"
334
+ it: "returns itself as a string" with: 'to_s when: {
335
+ [1,2,3] to_s is: "123"
310
336
  }
311
337
 
312
- it: "should call a given block between calling the each block" for: 'each:in_between: when: {
338
+ it: "calls a given block between calling the each block" with: 'each:in_between: when: {
313
339
  arr = []
314
340
  [1,2,3] each: |x| { arr << x } in_between: { arr << "-" }
315
- arr should == [1, "-", 2, "-", 3]
341
+ arr is: [1, "-", 2, "-", 3]
316
342
 
317
343
  str = ""
318
344
  ['foo, 'bar, 'baz] each: |x| { str = str ++ (x to_s) } in_between: { str = str ++ " " }
319
- str should == "foo bar baz"
345
+ str is: "foo bar baz"
320
346
  }
321
347
 
322
- it: "should return the reduced value for a given block and initial value" for: 'reduce:init_val: when: {
348
+ it: "returns the reduced value for a given block and initial value" with: 'reduce:init_val: when: {
323
349
  arr = 1 upto: 10
324
- arr sum should == (arr reduce: '+ init_val: 0)
325
- arr product should == (arr reduce: '* init_val: 1)
326
- arr to_s should == (arr reduce: '++ init_val: "")
350
+ arr sum is: (arr reduce: '+ init_val: 0)
351
+ arr product is: (arr reduce: '* init_val: 1)
352
+ arr to_s is: (arr reduce: '++ init_val: "")
327
353
  }
328
354
 
329
- it: "should return the reverse of itself" for: 'reverse when: {
330
- [1,2,3] reverse should == [3,2,1]
331
- 1 upto: 10 . reverse should == (10 downto: 1)
355
+ it: "returns the reverse of itself" with: 'reverse when: {
356
+ [1,2,3] reverse is: [3,2,1]
357
+ 1 upto: 10 . reverse is: (10 downto: 1)
332
358
  }
333
359
 
334
- it: "should inverse in-place" for: 'reverse! when: {
360
+ it: "inverses in-place" with: 'reverse! when: {
335
361
  arr = [1,2,3]
336
- arr reverse! should == [3,2,1]
337
- arr should == [3,2,1]
362
+ arr reverse! is: [3,2,1]
363
+ arr is: [3,2,1]
338
364
  }
339
365
 
340
- it: "should take elements from itself as long a block yields true" for: 'take_while: when: {
341
- 1 upto: 15 . take_while: |x| { x < 10 } . should == (1 upto: 9)
366
+ it: "takes elements from itself as long a block yields true" with: 'take_while: when: {
367
+ 1 upto: 15 . take_while: |x| { x < 10 } . is: (1 upto: 9)
342
368
  }
343
369
 
344
370
 
345
- it: "should drop elements from itself as long a block yields true" for: 'drop_while: when: {
346
- 1 upto: 15 . drop_while: |x| { x < 10 } . should == (10 upto: 15)
371
+ it: "drops elements from itself as long a block yields true" with: 'drop_while: when: {
372
+ 1 upto: 15 . drop_while: |x| { x < 10 } . is: (10 upto: 15)
347
373
  }
348
374
 
349
- it: "should partition an array via a given block" for: 'partition_by: when: {
375
+ it: "partitions an array via a given block" with: 'partition_by: when: {
350
376
  arr = [1,2,2,3,3,3,4,4,4,4,5]
351
- arr partition_by: 'identity . should == [[1], [2,2], [3,3,3], [4,4,4,4], [5]]
352
- arr partition_by: @{== 2} . should == [[1], [2,2], [3,3,3,4,4,4,4,5]]
377
+ arr partition_by: 'identity . is: [[1], [2,2], [3,3,3], [4,4,4,4], [5]]
378
+ arr partition_by: @{== 2} . is: [[1], [2,2], [3,3,3,4,4,4,4,5]]
353
379
  }
354
380
 
355
- it: "should remove the first value" for: 'shift when: {
381
+ it: "removes the first value" with: 'shift when: {
356
382
  a = [1,2,3]
357
- a shift should == 1
358
- a should == [2,3]
383
+ a shift is: 1
384
+ a is: [2,3]
359
385
 
360
386
  a = []
361
- a shift should == nil
362
- a should == []
387
+ a shift is: nil
388
+ a is: []
363
389
  }
364
390
 
365
- it: "should append a value at the front" for: 'unshift: when: {
391
+ it: "appends a value at the front" with: 'unshift: when: {
366
392
  a = []
367
- a unshift: 1 . should == a # should return self
368
- a should == [1]
393
+ a unshift: 1 . is: a # is return self
394
+ a is: [1]
369
395
 
370
396
  a = [1,2,3]
371
- a unshift: (a shift) . should == a
372
- a should == [1,2,3]
397
+ a unshift: (a shift) . is: a
398
+ a is: [1,2,3]
399
+ }
400
+
401
+ it: "compares 2 arrays without regard to order" with: '=? when: {
402
+ [1,2,3] =? [2,1,3] is: true
403
+ [1,2,3,4] =? [2,1,4,3] is: true
404
+ [1,2] =? [1,2,3] is: false
405
+ [1,2] =? [2] is: false
406
+ [2] =? [1,2] is: false
407
+ [] =? [] is: true
408
+ [1] =? [1] is: true
409
+ }
410
+
411
+ it: "returns the first element" with: 'first when: {
412
+ [1,2] first is: 1
413
+ [1] first is: 1
414
+ [] first is: nil
415
+ }
416
+
417
+ it: "returns the second element" with: 'second when: {
418
+ [1,2,3] second is: 2
419
+ [1,2] second is: 2
420
+ [1] second is: nil
421
+ [] second is: nil
422
+ }
423
+
424
+ it: "returns the third element" with: 'third when: {
425
+ [1,2,3,4] third is: 3
426
+ [1,2,3] third is: 3
427
+ [1,2] third is: nil
428
+ [1] third is: nil
429
+ [] third is: nil
430
+ }
431
+
432
+ it: "returns the fourth element" with: 'fourth when: {
433
+ [1,2,3,4,5] fourth is: 4
434
+ [1,2,3,4] fourth is: 4
435
+ [1,2,3] fourth is: nil
436
+ [1,2] fourth is: nil
437
+ [1] fourth is: nil
438
+ [] fourth is: nil
439
+ }
440
+
441
+ it: "returns all but the first element" with: 'rest when: {
442
+ [1,2,3,4] rest is: [2,3,4]
443
+ [2,3] rest is: [3]
444
+ [1] rest is: []
445
+ [] rest is: []
446
+ }
447
+
448
+ it: "returns a clone" with: 'clone when: {
449
+ [1,2,3] clone is: [1,2,3]
450
+ [1] clone is: [1]
451
+ [] clone is: []
452
+ }
453
+
454
+ it: "calculates the sum for an Array of numbers" with: 'sum when: {
455
+ [1,2,3] sum is: 6
456
+ [1] sum is: 1
457
+ [] sum is: 0
458
+ }
459
+
460
+ it: "calculates the product for an Array of numbers" with: 'product when: {
461
+ [1,2,3,4] product is: 24
462
+ [1] product is: 1
463
+ [] product is: 1
464
+ }
465
+
466
+ it: "calculates the average for an Array of numbers" with: 'average when: {
467
+ [] average is: 0
468
+ [-1] average is: -1
469
+ [0] average is: 0
470
+ [1] average is: 1
471
+ [1,2] average is: 1.5
472
+ [1,2,3] average is: 2
473
+ [1,2,3,4] average is: 2.5
474
+ }
475
+
476
+ it: "sorts the array" with: 'sort when: {
477
+ arr = [1,5,4,2,3]
478
+ arr sort is: [1,2,3,4,5]
479
+ arr is: [1,5,4,2,3]
480
+ }
481
+
482
+ it: "sorts the array with a given comparison block" with: 'sort_by: when: {
483
+ arr = [1,5,4,2,3]
484
+ sorted = [1,2,3,4,5]
485
+ arr sort_by: |a b| { a <=> b } . is: sorted
486
+ arr is: [1,5,4,2,3]
487
+
488
+ arr = [(1,2), (0,1), (3,0)]
489
+ sorted = [(3,0), (0,1), (1,2)]
490
+ arr sort_by: |a b| { a second <=> (b second) } . is: sorted
491
+ arr sort_by: 'second . is: sorted
492
+ }
493
+
494
+ it: "returns the array in groups of 3" with: 'in_groups_of: when: {
495
+ ['a,'b,'c] in_groups_of: 1 . is: [['a],['b],['c]]
496
+ array = 1 upto: 10
497
+ array in_groups_of: 3 . is: [[1,2,3], [4,5,6], [7,8,9], [10]]
498
+
499
+ (20,30,40) in_groups_of: 2 . is: [[20,30], [40]]
373
500
  }
374
501
  }