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/exception.fy
CHANGED
|
@@ -9,68 +9,85 @@ class Foo {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
FancySpec describe: StdError with: {
|
|
12
|
-
it: "
|
|
12
|
+
it: "raises an exception and catch it correctly" with: 'raise! when: {
|
|
13
13
|
try {
|
|
14
14
|
StdError new: "FAIL!" . raise!
|
|
15
|
-
nil
|
|
15
|
+
nil is: true # this is not occur
|
|
16
16
|
} catch StdError => ex {
|
|
17
|
-
ex message
|
|
17
|
+
ex message is: "FAIL!"
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
it: "
|
|
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" .
|
|
37
|
+
f bar: "Don't raise here" . is: 'no_error
|
|
24
38
|
try {
|
|
25
|
-
f bar: 'error .
|
|
39
|
+
f bar: 'error . is: 'no_error
|
|
26
40
|
} catch StdError => e {
|
|
27
|
-
e message
|
|
41
|
+
e message is: "Some Error"
|
|
28
42
|
}
|
|
29
43
|
}
|
|
30
44
|
|
|
31
|
-
# it: "
|
|
45
|
+
# it: "raises a NoMethodError" when: {
|
|
32
46
|
# s = 'symbol
|
|
33
47
|
# try {
|
|
34
48
|
# s this_method_doesnt_exist!
|
|
35
|
-
# nil
|
|
49
|
+
# nil is: true # is not execute
|
|
36
50
|
# } catch NoMethodError => err {
|
|
37
|
-
# err for_class
|
|
38
|
-
# err method_name
|
|
51
|
+
# err for_class is: Symbol
|
|
52
|
+
# err method_name is: "this_method_doesnt_exist!"
|
|
39
53
|
# }
|
|
40
54
|
# }
|
|
41
55
|
|
|
42
|
-
it: "
|
|
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
|
|
61
|
+
var is: 1234
|
|
48
62
|
}
|
|
49
63
|
}
|
|
50
64
|
|
|
51
|
-
it: "
|
|
65
|
+
it: "always evaluates the finally clause" when: {
|
|
66
|
+
set_in_finally = false
|
|
52
67
|
try {
|
|
53
68
|
x = 10 / 0 # ouch!
|
|
54
|
-
"This
|
|
69
|
+
"This is fail!" is: true # is not get here!
|
|
55
70
|
} catch ZeroDivisionError => err {
|
|
56
|
-
err message
|
|
71
|
+
err message is: "divided by 0"
|
|
57
72
|
} finally {
|
|
58
73
|
# this part gets always run :)
|
|
59
|
-
"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: "
|
|
81
|
+
it: "raises a StdError when raising a String" with: 'raise! when: {
|
|
64
82
|
msg = "A Custom Error!"
|
|
65
|
-
|
|
83
|
+
{
|
|
66
84
|
msg raise!
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
e message should == msg
|
|
85
|
+
} raises: StdError with: |e| {
|
|
86
|
+
e message is: msg
|
|
70
87
|
}
|
|
71
88
|
}
|
|
72
89
|
|
|
73
|
-
it: "
|
|
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
|
|
99
|
+
nil is: true # will fail
|
|
83
100
|
} catch MyError => e {
|
|
84
|
-
e message
|
|
101
|
+
e message is: "MyError message"
|
|
85
102
|
}
|
|
86
103
|
}
|
|
87
104
|
|
|
88
|
-
it: "
|
|
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
|
|
95
|
-
x
|
|
111
|
+
y is: 0
|
|
112
|
+
x is: 0
|
|
96
113
|
y = 2
|
|
97
114
|
retry
|
|
98
115
|
}
|
|
99
|
-
y
|
|
100
|
-
x
|
|
116
|
+
y is == 2
|
|
117
|
+
x is == 5
|
|
101
118
|
}
|
|
102
119
|
|
|
103
|
-
it: "
|
|
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
|
|
129
|
+
e message is: msg
|
|
113
130
|
}
|
|
114
131
|
}
|
|
115
132
|
}
|
data/tests/file.fy
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
FancySpec describe: File with: {
|
|
2
|
-
it: "
|
|
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
|
|
4
|
+
file modes is: ['read]
|
|
5
5
|
file close
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
it: "
|
|
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?
|
|
10
|
+
file open? is: true
|
|
11
11
|
file close
|
|
12
|
-
file open?
|
|
12
|
+
file open? is: false
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
it: "
|
|
16
|
-
{ file = File new }
|
|
15
|
+
it: "is closed when not correctly opened" with: 'open? when: {
|
|
16
|
+
{ file = File new } raises: ArgumentError
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
it: "
|
|
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 .
|
|
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]
|
|
34
|
-
lines[1]
|
|
35
|
-
lines
|
|
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 .
|
|
39
|
+
File exists?: filename . is: false
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
it: "
|
|
43
|
-
{ file = File open: "/foo/bar/baz" modes: ['read] }
|
|
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: "
|
|
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 .
|
|
57
|
-
File exists?: dirname .
|
|
58
|
-
File directory?: dirname .
|
|
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 .
|
|
62
|
-
File exists?: (filename ++ "-new") .
|
|
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: "
|
|
68
|
-
File directory?: "lib/" .
|
|
69
|
-
File directory?: "lib/rbx" .
|
|
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: "
|
|
73
|
-
File directory?: "src/Makefile" .
|
|
74
|
-
File directory?: "README" .
|
|
75
|
-
File directory?: "src/bootstrap/Makefile" .
|
|
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
|
}
|
data/tests/fixnum.fy
ADDED
|
@@ -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
|
+
}
|
data/tests/future.fy
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
FancySpec describe:
|
|
2
|
-
it: "
|
|
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?} &&
|
|
8
|
-
f is_a?:
|
|
9
|
-
f value is_a?: Fixnum .
|
|
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: "
|
|
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 .
|
|
38
|
+
val is_a?: Integer . is: true
|
|
22
39
|
}
|
|
23
40
|
|
|
24
41
|
fc await_all
|