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.
- data/README.md +14 -14
- data/Rakefile +16 -4
- data/bin/fancy +3 -0
- data/bin/fspec +20 -0
- data/bin/fyi +27 -11
- data/bin/ifancy +1 -1
- data/boot/fancy_ext.rb +1 -0
- data/boot/fancy_ext/block_env.rb +1 -9
- data/boot/fancy_ext/delegator.rb +64 -0
- data/boot/fancy_ext/object.rb +4 -0
- data/boot/fancy_ext/thread.rb +4 -0
- data/boot/load.rb +5 -1
- data/boot/rbx-compiler/compiler/ast.rb +0 -1
- data/boot/rbx-compiler/compiler/ast/class_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/method_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/node.rb +10 -0
- data/boot/rbx-compiler/compiler/ast/ruby_args.rb +12 -0
- data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +2 -0
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/lexer.lex +5 -11
- data/boot/rbx-compiler/parser/parser.rb +16 -5
- data/boot/rbx-compiler/parser/parser.y +39 -24
- data/doc/api/fancy.css +1 -1
- data/doc/api/fancy.jsonp +1 -1
- data/doc/api/fdoc.js +22 -4
- data/doc/api/index.html +5 -6
- data/doc/api/jquery-ui.min.js +401 -0
- data/doc/api/jquery.tools.min.js +192 -0
- data/doc/api/themeswitchertool.js +250 -0
- data/doc/features.md +17 -0
- data/examples/actor_bunnies.fy +32 -0
- data/examples/actors.fy +26 -0
- data/examples/actors_primitive.fy +27 -0
- data/examples/actors_ring.fy +37 -0
- data/examples/armstrong_numbers.fy +1 -1
- data/examples/array.fy +7 -9
- data/examples/async_send.fy +1 -2
- data/examples/blocks.fy +4 -4
- data/examples/call_with_receiver.fy +1 -1
- data/examples/class.fy +1 -1
- data/examples/default_args.fy +4 -1
- data/examples/define_methods.fy +2 -2
- data/examples/echo.fy +1 -1
- data/examples/factorial.fy +1 -1
- data/examples/future_composition.fy +2 -2
- data/examples/futures.fy +0 -5
- data/examples/game_of_life.fy +1 -1
- data/examples/person.fy +1 -1
- data/lib/argv.fy +7 -2
- data/lib/array.fy +109 -42
- data/lib/block.fy +39 -14
- data/lib/boot.fy +2 -0
- data/lib/class.fy +2 -0
- data/lib/compiler/ast.fy +2 -1
- data/lib/compiler/ast/assign.fy +2 -3
- data/lib/compiler/ast/async_send.fy +1 -15
- data/lib/compiler/ast/class_def.fy +2 -1
- data/lib/compiler/ast/expression_list.fy +4 -5
- data/lib/compiler/ast/future_send.fy +1 -10
- data/lib/compiler/ast/goto.fy +46 -0
- data/lib/compiler/ast/identifier.fy +9 -7
- data/lib/compiler/ast/literals.fy +8 -1
- data/lib/compiler/ast/match.fy +14 -4
- data/lib/compiler/ast/message_send.fy +34 -6
- data/lib/compiler/ast/method_def.fy +6 -6
- data/lib/compiler/ast/node.fy +3 -3
- data/lib/compiler/ast/range.fy +1 -0
- data/lib/compiler/ast/script.fy +0 -2
- data/lib/compiler/ast/singleton_method_def.fy +2 -4
- data/lib/compiler/ast/string_interpolation.fy +17 -0
- data/lib/compiler/ast/super.fy +5 -4
- data/lib/compiler/ast/try_catch.fy +8 -6
- data/lib/compiler/ast/tuple_literal.fy +3 -2
- data/lib/compiler/command.fy +0 -1
- data/lib/compiler/compiler.fy +1 -5
- data/lib/compiler/stages.fy +6 -14
- data/lib/documentation.fy +57 -46
- data/lib/enumerable.fy +257 -23
- data/lib/enumerator.fy +122 -15
- data/lib/false_class.fy +10 -1
- data/lib/fancy_spec.fy +263 -61
- data/lib/fdoc.fy +11 -25
- data/lib/fiber.fy +11 -0
- data/lib/file.fy +8 -11
- data/lib/future.fy +84 -5
- data/lib/hash.fy +65 -14
- data/lib/integer.fy +35 -0
- data/lib/iteration.fy +54 -29
- data/lib/message.fy +6 -0
- data/lib/method.fy +0 -16
- data/lib/nil_class.fy +58 -8
- data/lib/number.fy +49 -22
- data/lib/object.fy +371 -65
- data/lib/package.fy +24 -1
- data/lib/package/installer.fy +5 -9
- data/lib/package/specification.fy +2 -2
- data/lib/parser/ext/lexer.lex +15 -11
- data/lib/parser/ext/parser.y +70 -23
- data/lib/parser/methods.fy +33 -14
- data/lib/proxy.fy +33 -3
- data/lib/range.fy +28 -0
- data/lib/rbx.fy +3 -1
- data/lib/rbx/actor.fy +53 -0
- data/lib/rbx/alpha.fy +31 -0
- data/lib/rbx/array.fy +21 -12
- data/lib/rbx/bignum.fy +6 -2
- data/lib/rbx/block.fy +23 -26
- data/lib/rbx/class.fy +54 -2
- data/lib/rbx/code_loader.fy +8 -4
- data/lib/rbx/date.fy +9 -0
- data/lib/rbx/directory.fy +18 -0
- data/lib/rbx/environment_variables.fy +1 -0
- data/lib/rbx/exception.fy +9 -2
- data/lib/rbx/fiber.fy +22 -4
- data/lib/rbx/file.fy +5 -5
- data/lib/rbx/fixnum.fy +5 -0
- data/lib/rbx/float.fy +11 -3
- data/lib/rbx/hash.fy +31 -16
- data/lib/rbx/integer.fy +1 -0
- data/lib/rbx/io.fy +17 -7
- data/lib/rbx/match_data.fy +15 -4
- data/lib/rbx/method.fy +40 -7
- data/lib/rbx/name_error.fy +4 -0
- data/lib/rbx/object.fy +92 -24
- data/lib/rbx/range.fy +20 -6
- data/lib/rbx/regexp.fy +11 -3
- data/lib/rbx/string.fy +51 -1
- data/lib/rbx/stringio.fy +17 -0
- data/lib/rbx/symbol.fy +15 -1
- data/lib/rbx/system.fy +20 -2
- data/lib/rbx/tcp_server.fy +4 -1
- data/lib/rbx/tcp_socket.fy +11 -0
- data/lib/rbx/time.fy +6 -0
- data/lib/rbx/tuple.fy +14 -5
- data/lib/set.fy +144 -29
- data/lib/stack.fy +42 -11
- data/lib/string.fy +118 -8
- data/lib/struct.fy +13 -3
- data/lib/symbol.fy +21 -2
- data/lib/thread_pool.fy +2 -1
- data/lib/true_class.fy +45 -7
- data/lib/tuple.fy +27 -9
- data/lib/version.fy +2 -2
- data/ruby_lib/fancy +43 -0
- data/ruby_lib/fdoc +23 -0
- data/ruby_lib/fspec +3 -0
- data/ruby_lib/fyi +3 -0
- data/ruby_lib/ifancy +3 -0
- data/tests/argv.fy +5 -9
- data/tests/array.fy +323 -196
- data/tests/assignment.fy +29 -29
- data/tests/block.fy +72 -59
- data/tests/class.fy +227 -138
- data/tests/control_flow.fy +83 -51
- data/tests/documentation.fy +8 -8
- data/tests/enumerable.fy +8 -0
- data/tests/enumerator.fy +47 -29
- data/tests/exception.fy +49 -32
- data/tests/file.fy +28 -28
- data/tests/fixnum.fy +170 -0
- data/tests/future.fy +24 -7
- data/tests/hash.fy +55 -38
- data/tests/method.fy +50 -43
- data/tests/nil_class.fy +37 -37
- data/tests/object.fy +152 -70
- data/tests/pattern_matching.fy +67 -31
- data/tests/range.fy +6 -6
- data/tests/set.fy +101 -4
- data/tests/stack.fy +14 -5
- data/tests/string.fy +115 -61
- data/tests/stringio.fy +18 -0
- data/tests/struct.fy +27 -0
- data/tests/symbol.fy +19 -6
- data/tests/true_class.fy +34 -34
- data/tests/tuple.fy +30 -12
- metadata +103 -81
- data/boot/rbx-compiler/compiler/ast/require.rb +0 -20
- data/examples/actor.fy +0 -37
- data/examples/curl_async.fy +0 -37
- data/lib/compiler/ast/require.fy +0 -15
- data/tests/number.fy +0 -135
- data/tests/parsing/sexp.fy +0 -50
data/tests/hash.fy
CHANGED
|
@@ -1,101 +1,118 @@
|
|
|
1
1
|
FancySpec describe: Hash with: {
|
|
2
|
-
it: "
|
|
2
|
+
it: "is empty on initialization" with: 'empty? when: {
|
|
3
3
|
hash = <[]>
|
|
4
|
-
hash size
|
|
5
|
-
hash empty?
|
|
4
|
+
hash size is: 0
|
|
5
|
+
hash empty? is: true
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
it: "
|
|
8
|
+
it: "is empty on initialization via Hash#new" with: 'size when: {
|
|
9
9
|
hash = Hash new
|
|
10
|
-
hash size
|
|
11
|
-
hash empty?
|
|
10
|
+
hash size is: 0
|
|
11
|
+
hash empty? is: true
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
it: "
|
|
14
|
+
it: "contains one entry" when: {
|
|
15
15
|
hash = <['foo => "bar"]>
|
|
16
|
-
hash size
|
|
17
|
-
hash empty?
|
|
16
|
+
hash size is: 1
|
|
17
|
+
hash empty? is: false
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
it: "
|
|
20
|
+
it: "contains 10 square values after 10 insertions" with: 'at: when: {
|
|
21
21
|
hash = Hash new
|
|
22
22
|
10 times: |i| {
|
|
23
23
|
hash at: i put: (i * i)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
10 times: |i| {
|
|
27
|
-
hash at: i .
|
|
27
|
+
hash at: i . is: (i * i)
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
it: "
|
|
31
|
+
it: "overrides the value for a given key" with: 'at: when: {
|
|
32
32
|
hash = <['foo => "bar"]>
|
|
33
|
-
hash at: 'foo .
|
|
33
|
+
hash at: 'foo . is: "bar"
|
|
34
34
|
hash at: 'foo put: 'foobarbaz
|
|
35
|
-
hash at: 'foo .
|
|
35
|
+
hash at: 'foo . is: 'foobarbaz
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
it: "
|
|
38
|
+
it: "returns all keys" with: 'keys when: {
|
|
39
39
|
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
|
40
|
-
hash keys
|
|
40
|
+
hash keys is =? ['foo, 'bar, 'foobar]
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
it: "
|
|
43
|
+
it: "returns all values" with: 'values when: {
|
|
44
44
|
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
|
45
|
-
hash values
|
|
45
|
+
hash values is =? ["bar", "baz", 112.21]
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
it: "
|
|
48
|
+
it: "returns value by the []-operator" with: '[] when: {
|
|
49
49
|
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
|
50
|
-
hash['foo]
|
|
51
|
-
hash['bar]
|
|
52
|
-
hash['foobar]
|
|
50
|
+
hash['foo] is: "bar"
|
|
51
|
+
hash['bar] is: "baz"
|
|
52
|
+
hash['foobar] is: 112.21
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
it: "
|
|
56
|
-
<['foo => "bar"]> ['bar] .
|
|
57
|
-
<[]> ['foobar] .
|
|
58
|
-
<['foo => "bar"]> [nil] .
|
|
55
|
+
it: "returns nil if the key isn't defined" with: '[] when: {
|
|
56
|
+
<['foo => "bar"]> ['bar] . is: nil
|
|
57
|
+
<[]> ['foobar] . is: nil
|
|
58
|
+
<['foo => "bar"]> [nil] . is: nil
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
it: "
|
|
61
|
+
it: "calls the Block for each key and value" with: 'each: when: {
|
|
62
62
|
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
|
63
63
|
hash each: |key val| {
|
|
64
|
-
val
|
|
64
|
+
val is: (hash[key])
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
it: "
|
|
68
|
+
it: "calls the Block with each key" with: 'each_key: when: {
|
|
69
69
|
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
|
70
70
|
count = 0
|
|
71
71
|
hash each_key: |key| {
|
|
72
|
-
key
|
|
72
|
+
key is: (hash keys[count])
|
|
73
73
|
count = count + 1
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
it: "
|
|
77
|
+
it: "calls the Block with each value" with: 'each_value: when: {
|
|
78
78
|
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
|
79
79
|
count = 0
|
|
80
80
|
hash each_value: |val| {
|
|
81
|
-
val
|
|
81
|
+
val is: (hash values[count])
|
|
82
82
|
count = count + 1
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
it: "
|
|
86
|
+
it: "calls Enumerable methods with each pair" when: {
|
|
87
87
|
hash = <['hello => "world", 'fancy => "is cool"]>
|
|
88
88
|
|
|
89
|
-
hash map: |pair| { pair[0] } .
|
|
89
|
+
hash map: |pair| { pair[0] } . is =? ['hello, 'fancy] # order does not matter
|
|
90
90
|
|
|
91
91
|
hash select: |pair| { pair[1] to_s includes?: "c" } .
|
|
92
|
-
|
|
92
|
+
is: [['fancy, "is cool"]]
|
|
93
93
|
|
|
94
94
|
hash reject: |pair| { pair[0] to_s includes?: "l" } .
|
|
95
|
-
map: 'second .
|
|
95
|
+
map: 'second . is: ["is cool"]
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
it: "
|
|
99
|
-
<['foo => "bar", 'bar => "baz"]> to_a
|
|
98
|
+
it: "returns an Array of the key-value pairs" with: 'to_a when: {
|
|
99
|
+
<['foo => "bar", 'bar => "baz"]> to_a is =? [['foo, "bar"], ['bar, "baz"]]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
it: "returns multiple values if given an array of keys" with: '[] when: {
|
|
103
|
+
hash = <['foo => 1, 'bar => "foobar", 'baz => 42, "hello world" => "hello!"]>
|
|
104
|
+
a, b, c = hash values_at: ('foo, 'bar, "hello world")
|
|
105
|
+
a is: 1
|
|
106
|
+
b is: "foobar"
|
|
107
|
+
c is: "hello!"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
it: "includes a key" with: 'includes?: when: {
|
|
111
|
+
h = <['foo => "bar", 'bar => "baz"]>
|
|
112
|
+
h includes?: 'foo . is: true
|
|
113
|
+
h includes?: 'bar . is: true
|
|
114
|
+
h includes?: "foo" . is: false
|
|
115
|
+
h includes?: "bar" . is: false
|
|
116
|
+
h includes?: nil . is: false
|
|
100
117
|
}
|
|
101
118
|
}
|
data/tests/method.fy
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
FancySpec describe: Method with: {
|
|
2
|
-
it: "
|
|
3
|
-
[1,2,3] method: "each:" . class
|
|
2
|
+
it: "returns a Method object" when: {
|
|
3
|
+
[1,2,3] method: "each:" . class is: Method
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
# it: "
|
|
6
|
+
# it: "returns the (correct) sender object of the MessageSend" when: {
|
|
7
7
|
# class SenderTest {
|
|
8
8
|
# def give_me_the_sender! {
|
|
9
9
|
# __sender__
|
|
@@ -11,10 +11,10 @@ FancySpec describe: Method with: {
|
|
|
11
11
|
# }
|
|
12
12
|
|
|
13
13
|
# x = SenderTest new
|
|
14
|
-
# x give_me_the_sender!
|
|
14
|
+
# x give_me_the_sender! is: self
|
|
15
15
|
# }
|
|
16
16
|
|
|
17
|
-
it: "
|
|
17
|
+
it: "returns the amount of arguments a Method takes" with: 'arity when: {
|
|
18
18
|
class Foo {
|
|
19
19
|
def no_args {
|
|
20
20
|
}
|
|
@@ -26,19 +26,19 @@ FancySpec describe: Method with: {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
Foo instance_method: 'no_args . arity
|
|
30
|
-
Foo instance_method: "one_arg:" . arity
|
|
31
|
-
Foo instance_method: "two:args:" . arity
|
|
32
|
-
Foo instance_method: "three:args:ok:" . arity
|
|
29
|
+
Foo instance_method: 'no_args . arity is: 0
|
|
30
|
+
Foo instance_method: "one_arg:" . arity is: 1
|
|
31
|
+
Foo instance_method: "two:args:" . arity is: 2
|
|
32
|
+
Foo instance_method: "three:args:ok:" . arity is: 3
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
it: "
|
|
35
|
+
it: "returns the return value" when: {
|
|
36
36
|
def foo: bar {
|
|
37
37
|
return "returning!"
|
|
38
38
|
bar # will never get executed
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
foo: "yay" .
|
|
41
|
+
foo: "yay" . is: "returning!"
|
|
42
42
|
|
|
43
43
|
# another example
|
|
44
44
|
|
|
@@ -49,8 +49,8 @@ FancySpec describe: Method with: {
|
|
|
49
49
|
0
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
f: 10 .
|
|
53
|
-
f: 9 .
|
|
52
|
+
f: 10 . is: 0
|
|
53
|
+
f: 9 . is: 100
|
|
54
54
|
|
|
55
55
|
# and another one
|
|
56
56
|
|
|
@@ -63,10 +63,10 @@ FancySpec describe: Method with: {
|
|
|
63
63
|
return 0
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
foo
|
|
66
|
+
foo is: 8
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
it: "
|
|
69
|
+
it: "returns only from block-scope not from method-scope" when: {
|
|
70
70
|
def self foo {
|
|
71
71
|
10 times: |i| {
|
|
72
72
|
i == 8 if_true: {
|
|
@@ -75,68 +75,75 @@ FancySpec describe: Method with: {
|
|
|
75
75
|
}
|
|
76
76
|
0
|
|
77
77
|
}
|
|
78
|
-
foo
|
|
78
|
+
foo is: 8
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
it: "
|
|
81
|
+
it: "returns locally (from block-scope not from method-scope" when: {
|
|
82
82
|
def self foo {
|
|
83
83
|
[1,2,3] select: |x| { return_local x != 3 }
|
|
84
84
|
}
|
|
85
|
-
foo
|
|
85
|
+
foo is: [1,2]
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
class Foo {
|
|
89
89
|
def bar {
|
|
90
90
|
}
|
|
91
|
-
def
|
|
91
|
+
def private_bar {
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
private: 'private_bar
|
|
94
|
+
def protected_bar {
|
|
94
95
|
}
|
|
96
|
+
protected: 'protected_bar
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
it: "
|
|
98
|
-
Foo instance_method: 'bar . public?
|
|
99
|
-
Foo instance_method: 'private_bar . public?
|
|
100
|
-
Foo instance_method: 'protected_bar . public?
|
|
99
|
+
it: "is public" with: 'public? when: {
|
|
100
|
+
Foo instance_method: 'bar . public? is: true
|
|
101
|
+
Foo instance_method: 'private_bar . public? is: false
|
|
102
|
+
Foo instance_method: 'protected_bar . public? is: false
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
it: "
|
|
104
|
-
Foo instance_method: 'bar . private?
|
|
105
|
-
Foo instance_method: 'private_bar . private?
|
|
106
|
-
Foo instance_method: 'protected_bar . private?
|
|
105
|
+
it: "is private" with: 'private? when: {
|
|
106
|
+
Foo instance_method: 'bar . private? is: false
|
|
107
|
+
Foo instance_method: 'private_bar . private? is: true
|
|
108
|
+
Foo instance_method: 'protected_bar . private? is: false
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
it: "
|
|
110
|
-
Foo instance_method: 'bar . protected?
|
|
111
|
-
Foo instance_method: 'private_bar . protected?
|
|
112
|
-
Foo instance_method: 'protected_bar . protected?
|
|
111
|
+
it: "is protected" with: 'protected? when: {
|
|
112
|
+
Foo instance_method: 'bar . protected? is: false
|
|
113
|
+
Foo instance_method: 'private_bar . protected? is: false
|
|
114
|
+
Foo instance_method: 'protected_bar . protected? is: true
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
it: "
|
|
117
|
+
it: "sets the default values for optional argument, when not passed in" when: {
|
|
116
118
|
def foo: arg1 bar: arg2 ("foo") baz: arg3 (nil) {
|
|
117
119
|
arg1 ++ arg2 ++ arg3
|
|
118
120
|
}
|
|
119
121
|
|
|
120
|
-
foo: "hello" bar: "world" baz: "!" .
|
|
121
|
-
foo: "hello" bar: "world" .
|
|
122
|
-
foo: "hello" .
|
|
122
|
+
foo: "hello" bar: "world" baz: "!" . is: "helloworld!"
|
|
123
|
+
foo: "hello" bar: "world" . is: "helloworld"
|
|
124
|
+
foo: "hello" . is: "hellofoo"
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
it: "
|
|
127
|
+
it: "has default values for all arguments, if none given" when: {
|
|
126
128
|
def a: arg1 ("foo") b: arg2 ("bar") c: arg3 ("baz") {
|
|
127
129
|
[arg1, arg2, arg3]
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
a: "hello" b: "world" c: "!" .
|
|
131
|
-
a: "hello" b: "world" .
|
|
132
|
-
a: "hello" .
|
|
133
|
-
a
|
|
132
|
+
a: "hello" b: "world" c: "!" . is: ["hello", "world", "!"]
|
|
133
|
+
a: "hello" b: "world" . is: ["hello", "world", "baz"]
|
|
134
|
+
a: "hello" . is: ["hello", "bar", "baz"]
|
|
135
|
+
a is: ["foo", "bar", "baz"]
|
|
134
136
|
}
|
|
135
137
|
|
|
136
|
-
it: "
|
|
138
|
+
it: "returns multiple values (as a Tuple)" when: {
|
|
137
139
|
def multiple_return_values: x {
|
|
138
140
|
(x, x + x, x + x + x)
|
|
139
141
|
}
|
|
140
|
-
val = multiple_return_values: 3 .
|
|
142
|
+
val = multiple_return_values: 3 . is: (3, 6, 9)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
it: "parses methods without a body and default args correctly" when: {
|
|
146
|
+
def fooaa: bar ("fo");
|
|
147
|
+
fooaa: 10
|
|
141
148
|
}
|
|
142
149
|
}
|
data/tests/nil_class.fy
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
1
|
FancySpec describe: NilClass with: {
|
|
2
|
-
it: "
|
|
3
|
-
nil and: true .
|
|
4
|
-
nil and: 'foo .
|
|
5
|
-
nil and: nil .
|
|
6
|
-
false and: true .
|
|
7
|
-
false and: 'foo .
|
|
8
|
-
false and: nil .
|
|
2
|
+
it: "is false for calling and: with any value" with: 'and: when: {
|
|
3
|
+
nil and: true . is: nil
|
|
4
|
+
nil and: 'foo . is: nil
|
|
5
|
+
nil and: nil . is: nil
|
|
6
|
+
false and: true . is: false
|
|
7
|
+
false and: 'foo . is: false
|
|
8
|
+
false and: nil . is: false
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
it: "
|
|
12
|
-
(nil && true)
|
|
13
|
-
(nil && 'foo)
|
|
14
|
-
(nil && nil)
|
|
15
|
-
(false && true)
|
|
16
|
-
(false && 'foo)
|
|
17
|
-
(false && nil)
|
|
11
|
+
it: "is nil/false for calling && with any value" with: '&& when: {
|
|
12
|
+
(nil && true) is: nil
|
|
13
|
+
(nil && 'foo) is: nil
|
|
14
|
+
(nil && nil) is: nil
|
|
15
|
+
(false && true) is: false
|
|
16
|
+
(false && 'foo) is: false
|
|
17
|
+
(false && nil) is: false
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
it: "
|
|
21
|
-
nil or: true .
|
|
22
|
-
nil or: 'foo .
|
|
20
|
+
it: "is true for calling or: with any non-nil value" with: 'or: when: {
|
|
21
|
+
nil or: true . is: true
|
|
22
|
+
nil or: 'foo . is: 'foo
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
it: "
|
|
26
|
-
nil or: nil .
|
|
27
|
-
nil or: false .
|
|
25
|
+
it: "is nil/false for calling or: with a nil/false value" with: 'or: when: {
|
|
26
|
+
nil or: nil . is: nil
|
|
27
|
+
nil or: false . is: false
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
it: "
|
|
31
|
-
(nil || true)
|
|
32
|
-
(nil || 'foo)
|
|
30
|
+
it: "is true for calling || with any non-nil value" with: '|| when: {
|
|
31
|
+
(nil || true) is: true
|
|
32
|
+
(nil || 'foo) is: 'foo
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
it: "
|
|
36
|
-
(nil || nil)
|
|
35
|
+
it: "is nil for calling || with a nil value" with: '|| when: {
|
|
36
|
+
(nil || nil) is: nil
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
it: "
|
|
40
|
-
nil if_true: { 'then } .
|
|
39
|
+
it: "does not call the block" with: 'if_true: when: {
|
|
40
|
+
nil if_true: { 'then } . is: nil
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
it: "
|
|
44
|
-
nil if_false: { 'false } .
|
|
43
|
+
it: "does not call the block" with: 'if_false: when: {
|
|
44
|
+
nil if_false: { 'false } . is: nil
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
it: "
|
|
48
|
-
nil nil?
|
|
47
|
+
it: "is nil" with: 'nil? when: {
|
|
48
|
+
nil nil? is: true
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
it: "
|
|
52
|
-
nil false?
|
|
51
|
+
it: "is false" with: 'false? when: {
|
|
52
|
+
nil false? is: false
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
it: "
|
|
56
|
-
nil true?
|
|
55
|
+
it: "is not true" with: 'true? when: {
|
|
56
|
+
nil true? is: false
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
it: "
|
|
60
|
-
nil if_nil: { 'is_nil } .
|
|
59
|
+
it: "calls the block if nil" with: 'if_nil: when: {
|
|
60
|
+
nil if_nil: { 'is_nil } . is: 'is_nil
|
|
61
61
|
}
|
|
62
62
|
}
|
data/tests/object.fy
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
FancySpec describe: Object with: {
|
|
2
|
-
it: "
|
|
2
|
+
it: "dynamically evaluates a message-send with no arguments" when: {
|
|
3
3
|
obj = 42
|
|
4
|
-
obj
|
|
4
|
+
obj receive_message: 'to_s . is: "42"
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
it: "
|
|
7
|
+
it: "dynamically evaluates a message-send with a list of arguments" when: {
|
|
8
8
|
obj = "hello, world"
|
|
9
|
-
obj
|
|
9
|
+
obj receive_message: 'from:to: with_params: [0,4] . is: "hello"
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
it: "
|
|
12
|
+
it: "dynamically defines slotvalues" when: {
|
|
13
13
|
obj = Object new
|
|
14
|
-
obj get_slot: 'foo .
|
|
14
|
+
obj get_slot: 'foo . is: nil
|
|
15
15
|
obj set_slot: 'foo value: "hello, world"
|
|
16
|
-
obj get_slot: 'foo .
|
|
16
|
+
obj get_slot: 'foo . is: "hello, world"
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
it: "
|
|
19
|
+
it: "undefines a singleton method" when: {
|
|
20
20
|
def self a_singleton_method {
|
|
21
21
|
"a singleton method!"
|
|
22
22
|
}
|
|
23
|
-
self a_singleton_method
|
|
23
|
+
self a_singleton_method is: "a singleton method!"
|
|
24
24
|
self undefine_singleton_method: 'a_singleton_method
|
|
25
|
-
{ self a_singleton_method }
|
|
25
|
+
{ self a_singleton_method } raises: NoMethodError
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
it: "
|
|
29
|
-
nil class
|
|
30
|
-
true class
|
|
31
|
-
"foo" class
|
|
32
|
-
'bar class
|
|
33
|
-
{ 'a_block } class
|
|
28
|
+
it: "returns its class" when: {
|
|
29
|
+
nil class is: NilClass
|
|
30
|
+
true class is: TrueClass
|
|
31
|
+
"foo" class is: String
|
|
32
|
+
'bar class is: Symbol
|
|
33
|
+
{ 'a_block } class is: Block
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
it: "
|
|
36
|
+
it: "calls unkown_message:with_params: when calling an undefined method" when: {
|
|
37
37
|
class UnknownMessage {
|
|
38
38
|
def unknown_message: message with_params: params {
|
|
39
39
|
"Got: " ++ message ++ " " ++ params
|
|
@@ -41,93 +41,102 @@ FancySpec describe: Object with: {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
obj = UnknownMessage new
|
|
44
|
-
obj this_is_not_defined: "It's true!" .
|
|
44
|
+
obj this_is_not_defined: "It's true!" . is: "Got: this_is_not_defined: It's true!"
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
it: "
|
|
48
|
-
3 to_s
|
|
49
|
-
'foo to_s
|
|
50
|
-
nil to_s
|
|
47
|
+
it: "returns a correct string representation" when: {
|
|
48
|
+
3 to_s is: "3"
|
|
49
|
+
'foo to_s is: "foo"
|
|
50
|
+
nil to_s is: ""
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
it: "
|
|
54
|
-
nil to_a
|
|
55
|
-
'foo to_a
|
|
56
|
-
<['foo => "bar", 'bar => "baz"]> to_a
|
|
53
|
+
it: "returns a correct array representation" when: {
|
|
54
|
+
nil to_a is: []
|
|
55
|
+
'foo to_a is: ['foo]
|
|
56
|
+
<['foo => "bar", 'bar => "baz"]> to_a is =? [['bar, "baz"], ['foo, "bar"]]
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
it: "
|
|
60
|
-
nil to_i
|
|
61
|
-
3 to_i
|
|
62
|
-
3.28437 to_i
|
|
59
|
+
it: "returns a correct fixnum representation" when: {
|
|
60
|
+
nil to_i is: 0
|
|
61
|
+
3 to_i is: 3
|
|
62
|
+
3.28437 to_i is: 3
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
it: "
|
|
66
|
-
Object new is_a?: Object .
|
|
67
|
-
"foo" is_a?: String .
|
|
68
|
-
"foo" is_a?: Object .
|
|
69
|
-
1123 is_a?: Fixnum .
|
|
70
|
-
1123 is_a?: Object .
|
|
71
|
-
132.123 is_a?: Float .
|
|
72
|
-
132.123 is_a?: Object .
|
|
65
|
+
it: "is an Object of the correct Class (or Superclass)" when: {
|
|
66
|
+
Object new is_a?: Object . is: true
|
|
67
|
+
"foo" is_a?: String . is: true
|
|
68
|
+
"foo" is_a?: Object . is: true
|
|
69
|
+
1123 is_a?: Fixnum . is: true
|
|
70
|
+
1123 is_a?: Object . is: true
|
|
71
|
+
132.123 is_a?: Float . is: true
|
|
72
|
+
132.123 is_a?: Object . is: true
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
# boolean messages
|
|
76
76
|
|
|
77
|
-
it: "
|
|
78
|
-
'foo and: 'bar .
|
|
77
|
+
it: "is true for calling and: with non-nil values" with: 'and: when: {
|
|
78
|
+
'foo and: 'bar . is: 'bar
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
it: "
|
|
82
|
-
'foo and: nil .
|
|
81
|
+
it: "is false for calling and: with a nil value" with: 'and: when: {
|
|
82
|
+
'foo and: nil . is: nil
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
it: "
|
|
86
|
-
('foo && 'bar)
|
|
85
|
+
it: "is true for calling && with non-nil values" with: '&& when: {
|
|
86
|
+
('foo && 'bar) is: 'bar
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
it: "
|
|
90
|
-
('foo && nil)
|
|
89
|
+
it: "is false for calling && with a nil value" with: '&& when: {
|
|
90
|
+
('foo && nil) is: nil
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
it: "
|
|
95
|
-
'foo or: 'bar .
|
|
96
|
-
'foo or: nil .
|
|
94
|
+
it: "is true for calling or: with any value" with: 'or: when: {
|
|
95
|
+
'foo or: 'bar . is: 'foo
|
|
96
|
+
'foo or: nil . is: 'foo
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
it: "
|
|
100
|
-
('foo || 'bar)
|
|
101
|
-
('foo || nil)
|
|
99
|
+
it: "is true for calling || with any value" with: '|| when: {
|
|
100
|
+
('foo || 'bar) is: 'foo
|
|
101
|
+
('foo || nil) is: 'foo
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
it: "is true if only one of them is not true" with: 'xor: when: {
|
|
105
|
+
true xor: false . is: true
|
|
106
|
+
false xor: false . is: false
|
|
107
|
+
nil xor: nil . is: false
|
|
108
|
+
false xor: false . is: false
|
|
109
|
+
false xor: nil . is: false
|
|
110
|
+
1 xor: nil . is: true
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
# end boolean messages
|
|
105
114
|
|
|
106
|
-
it: "
|
|
107
|
-
'foo nil?
|
|
108
|
-
1 nil?
|
|
109
|
-
"hello" nil?
|
|
115
|
+
it: "is not nil for non-nil values" with: 'nil? when: {
|
|
116
|
+
'foo nil? is: false
|
|
117
|
+
1 nil? is: false
|
|
118
|
+
"hello" nil? is: false
|
|
110
119
|
}
|
|
111
120
|
|
|
112
|
-
it: "
|
|
113
|
-
'foo false?
|
|
114
|
-
"hello, world" false?
|
|
121
|
+
it: "is not false for non-nil values" with: 'false? when: {
|
|
122
|
+
'foo false? is: false
|
|
123
|
+
"hello, world" false? is: false
|
|
115
124
|
}
|
|
116
125
|
|
|
117
|
-
it: "
|
|
118
|
-
'foo true?
|
|
119
|
-
"hello, world" true?
|
|
126
|
+
it: "is not true" with: 'true? when: {
|
|
127
|
+
'foo true? is: false
|
|
128
|
+
"hello, world" true? is: false
|
|
120
129
|
}
|
|
121
130
|
|
|
122
|
-
it: "
|
|
131
|
+
it: "returns the correct value" with: 'returning:do: when: {
|
|
123
132
|
returning: [] do: |arr| {
|
|
124
133
|
arr << 1
|
|
125
134
|
arr << 2
|
|
126
135
|
arr << 3
|
|
127
|
-
} .
|
|
136
|
+
} . is: [1,2,3]
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
it: "
|
|
139
|
+
it: "only calls a method if the receiver responds to it using a RespondsToProxy" with: 'if_responds? when: {
|
|
131
140
|
class SomeClass {
|
|
132
141
|
def some_method {
|
|
133
142
|
'it_works!
|
|
@@ -135,18 +144,91 @@ FancySpec describe: Object with: {
|
|
|
135
144
|
}
|
|
136
145
|
|
|
137
146
|
s = SomeClass new
|
|
138
|
-
s if_responds? some_method
|
|
139
|
-
s if_responds? some_undefined_method
|
|
147
|
+
s if_responds? some_method is: 'it_works!
|
|
148
|
+
s if_responds? some_undefined_method is: nil
|
|
140
149
|
}
|
|
141
150
|
|
|
142
|
-
it: "
|
|
143
|
-
`cat #{__FILE__}`
|
|
151
|
+
it: "calls the backtick: method when using the '`' syntax" with: 'backtick: when: {
|
|
152
|
+
`cat #{__FILE__}` is: (File read: __FILE__)
|
|
144
153
|
|
|
145
154
|
# override backticks
|
|
146
155
|
def backtick: str {
|
|
147
156
|
str + " - NOT!"
|
|
148
157
|
}
|
|
149
158
|
|
|
150
|
-
`ls -al`
|
|
159
|
+
`ls -al` is: "ls -al - NOT!"
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
it: "overrides true and does some wacky stuff" with: 'true when: {
|
|
163
|
+
class MyClass {
|
|
164
|
+
def true {
|
|
165
|
+
false
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
def do_wacky_things {
|
|
169
|
+
4 == 5
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
MyClass new do_wacky_things is: false
|
|
173
|
+
|
|
174
|
+
{
|
|
175
|
+
true is: false
|
|
176
|
+
} call_with_receiver: (MyClass new)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
it: "overrides nil" with: 'nil when: {
|
|
180
|
+
class MyClass {
|
|
181
|
+
def nil {
|
|
182
|
+
true
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
{ nil is: true } call_with_receiver: (MyClass new)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
it: "overrides false" with: 'false when: {
|
|
190
|
+
class MyClass2 {
|
|
191
|
+
def false {
|
|
192
|
+
true
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
{ false is: true } call_with_receiver: (MyClass2 new)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
it: "implicitly sends a message to self if no receiver is specified" when: {
|
|
200
|
+
def test { 42 }
|
|
201
|
+
test is: 42
|
|
202
|
+
self test is: 42
|
|
203
|
+
test is: (self test)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
it: "calls a given block in the context of the receiver (like a message cascade)" with: 'do: when: {
|
|
207
|
+
arr = []
|
|
208
|
+
arr do: {
|
|
209
|
+
<< 1
|
|
210
|
+
<< 2
|
|
211
|
+
<< 3
|
|
212
|
+
select!: 'even?
|
|
213
|
+
}
|
|
214
|
+
arr is: [2]
|
|
215
|
+
arr do: {
|
|
216
|
+
is: [2] # same
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
it: "returns a set of its slot names" with: 'slots when: {
|
|
221
|
+
class GotSlots {
|
|
222
|
+
def initialize {
|
|
223
|
+
@x, @y = 1, 2
|
|
224
|
+
}
|
|
225
|
+
def set_another_slot {
|
|
226
|
+
@z = 123
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
gs = GotSlots new
|
|
230
|
+
gs slots is: $ Set[['x, 'y]]
|
|
231
|
+
gs set_another_slot
|
|
232
|
+
gs slots is: $ Set[['x,'y,'z]]
|
|
151
233
|
}
|
|
152
234
|
}
|