fancy 0.3.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/AUTHORS +7 -0
- data/LICENSE +19 -0
- data/README +173 -0
- data/Rakefile +255 -0
- data/bin/fancy +40 -0
- data/bin/fdoc +23 -0
- data/bin/fyi +22 -0
- data/bin/ifancy +46 -0
- data/boot/README +12 -0
- data/boot/code_loader.rb +165 -0
- data/boot/compile.fy +3 -0
- data/boot/fancy_ext.rb +13 -0
- data/boot/fancy_ext/block_env.rb +29 -0
- data/boot/fancy_ext/class.rb +26 -0
- data/boot/fancy_ext/kernel.rb +12 -0
- data/boot/fancy_ext/module.rb +89 -0
- data/boot/fancy_ext/object.rb +34 -0
- data/boot/fancy_ext/string_helper.rb +10 -0
- data/boot/load.rb +72 -0
- data/boot/rbx-compiler/README +12 -0
- data/boot/rbx-compiler/compiler.rb +24 -0
- data/boot/rbx-compiler/compiler/ast.rb +23 -0
- data/boot/rbx-compiler/compiler/ast/README +11 -0
- data/boot/rbx-compiler/compiler/ast/array_literal.rb +13 -0
- data/boot/rbx-compiler/compiler/ast/assign.rb +57 -0
- data/boot/rbx-compiler/compiler/ast/block.rb +70 -0
- data/boot/rbx-compiler/compiler/ast/class_def.rb +35 -0
- data/boot/rbx-compiler/compiler/ast/expression_list.rb +57 -0
- data/boot/rbx-compiler/compiler/ast/hash_literal.rb +11 -0
- data/boot/rbx-compiler/compiler/ast/identifier.rb +120 -0
- data/boot/rbx-compiler/compiler/ast/match.rb +81 -0
- data/boot/rbx-compiler/compiler/ast/message_send.rb +71 -0
- data/boot/rbx-compiler/compiler/ast/method_def.rb +116 -0
- data/boot/rbx-compiler/compiler/ast/node.rb +6 -0
- data/boot/rbx-compiler/compiler/ast/range_literal.rb +22 -0
- data/boot/rbx-compiler/compiler/ast/require.rb +20 -0
- data/boot/rbx-compiler/compiler/ast/return.rb +29 -0
- data/boot/rbx-compiler/compiler/ast/ruby_args.rb +35 -0
- data/boot/rbx-compiler/compiler/ast/script.rb +56 -0
- data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +39 -0
- data/boot/rbx-compiler/compiler/ast/string_literal.rb +14 -0
- data/boot/rbx-compiler/compiler/ast/super.rb +25 -0
- data/boot/rbx-compiler/compiler/ast/try_catch_block.rb +220 -0
- data/boot/rbx-compiler/compiler/ast/tuple_literal.rb +33 -0
- data/boot/rbx-compiler/compiler/command.rb +39 -0
- data/boot/rbx-compiler/compiler/compiler.rb +83 -0
- data/boot/rbx-compiler/compiler/stages.rb +99 -0
- data/boot/rbx-compiler/parser.rb +2 -0
- data/boot/rbx-compiler/parser/README +15 -0
- data/boot/rbx-compiler/parser/Rakefile +54 -0
- data/boot/rbx-compiler/parser/extconf.rb +3 -0
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/fancy_parser.c +46 -0
- data/boot/rbx-compiler/parser/fancy_parser.h +8 -0
- data/boot/rbx-compiler/parser/lexer.lex +180 -0
- data/boot/rbx-compiler/parser/parser.rb +356 -0
- data/boot/rbx-compiler/parser/parser.y +711 -0
- data/boot/rsexp_pretty_printer.rb +76 -0
- data/doc/api/fancy.css +93 -0
- data/doc/api/fancy.jsonp +1 -0
- data/doc/api/fdoc.js +187 -0
- data/doc/api/index.html +57 -0
- data/doc/api/underscore-min.js +18 -0
- data/doc/features.md +228 -0
- data/examples/argv.fy +8 -0
- data/examples/arithmetic.fy +7 -0
- data/examples/armstrong_numbers.fy +33 -0
- data/examples/array.fy +52 -0
- data/examples/blocks.fy +15 -0
- data/examples/boolean.fy +24 -0
- data/examples/call_with_receiver.fy +9 -0
- data/examples/class.fy +68 -0
- data/examples/closures.fy +24 -0
- data/examples/constant_access.fy +15 -0
- data/examples/default_args.fy +17 -0
- data/examples/define_methods.fy +15 -0
- data/examples/documentation.fy +57 -0
- data/examples/documentation_formatters.fy +25 -0
- data/examples/echo.fy +16 -0
- data/examples/empty_catch.fy +4 -0
- data/examples/exception.fy +9 -0
- data/examples/factorial.fy +12 -0
- data/examples/fibonacci.fy +16 -0
- data/examples/files.fy +23 -0
- data/examples/finally.fy +5 -0
- data/examples/game_of_life.fy +148 -0
- data/examples/hashes.fy +7 -0
- data/examples/hello_world.fy +6 -0
- data/examples/html_generator.fy +54 -0
- data/examples/implicit_return.fy +3 -0
- data/examples/matchers.fy +6 -0
- data/examples/methods.fy +29 -0
- data/examples/nested_classes.fy +27 -0
- data/examples/nested_try.fy +9 -0
- data/examples/numbers.fy +12 -0
- data/examples/pattern_matching.fy +40 -0
- data/examples/person.fy +65 -0
- data/examples/project-euler/01.fy +8 -0
- data/examples/project-euler/02.fy +21 -0
- data/examples/project-euler/28.fy +33 -0
- data/examples/rbx/and_or.fy +7 -0
- data/examples/rbx/blocks.fy +22 -0
- data/examples/rbx/classes.fy +32 -0
- data/examples/rbx/hello.fy +8 -0
- data/examples/rbx/include.fy +12 -0
- data/examples/rbx/inherit.fy +11 -0
- data/examples/rbx/methods.fy +15 -0
- data/examples/rbx/nested_classes.fy +9 -0
- data/examples/rbx/require.fy +3 -0
- data/examples/rbx/strings.fy +5 -0
- data/examples/regex.fy +7 -0
- data/examples/require.fy +7 -0
- data/examples/retry.fy +12 -0
- data/examples/return.fy +13 -0
- data/examples/ruby_require.fy +7 -0
- data/examples/ruby_send.fy +3 -0
- data/examples/singleton_methods.fy +21 -0
- data/examples/stupid_quicksort.fy +12 -0
- data/examples/threads.fy +18 -0
- data/examples/tuple.fy +8 -0
- data/examples/webserver/webserver.fy +18 -0
- data/lib/argv.fy +36 -0
- data/lib/array.fy +207 -0
- data/lib/block.fy +88 -0
- data/lib/boot.fy +41 -0
- data/lib/class.fy +106 -0
- data/lib/compiler.fy +14 -0
- data/lib/compiler/ast.fy +40 -0
- data/lib/compiler/ast/assign.fy +96 -0
- data/lib/compiler/ast/block.fy +84 -0
- data/lib/compiler/ast/class_def.fy +33 -0
- data/lib/compiler/ast/expression_list.fy +47 -0
- data/lib/compiler/ast/identifier.fy +113 -0
- data/lib/compiler/ast/literals.fy +122 -0
- data/lib/compiler/ast/match.fy +88 -0
- data/lib/compiler/ast/message_send.fy +110 -0
- data/lib/compiler/ast/method_def.fy +90 -0
- data/lib/compiler/ast/node.fy +7 -0
- data/lib/compiler/ast/range.fy +16 -0
- data/lib/compiler/ast/require.fy +15 -0
- data/lib/compiler/ast/return.fy +23 -0
- data/lib/compiler/ast/script.fy +52 -0
- data/lib/compiler/ast/singleton_method_def.fy +35 -0
- data/lib/compiler/ast/super.fy +17 -0
- data/lib/compiler/ast/try_catch.fy +176 -0
- data/lib/compiler/ast/tuple_literal.fy +34 -0
- data/lib/compiler/command.fy +51 -0
- data/lib/compiler/compiler.fy +73 -0
- data/lib/compiler/stages.fy +81 -0
- data/lib/directory.fy +17 -0
- data/lib/documentation.fy +115 -0
- data/lib/enumerable.fy +269 -0
- data/lib/eval.fy +31 -0
- data/lib/fancy_spec.fy +202 -0
- data/lib/fdoc.fy +359 -0
- data/lib/fdoc_hook.fy +10 -0
- data/lib/file.fy +54 -0
- data/lib/hash.fy +56 -0
- data/lib/main.fy +80 -0
- data/lib/method.fy +22 -0
- data/lib/nil_class.fy +56 -0
- data/lib/number.fy +87 -0
- data/lib/object.fy +170 -0
- data/lib/package.fy +61 -0
- data/lib/package/dependency.fy +24 -0
- data/lib/package/installer.fy +180 -0
- data/lib/package/specification.fy +55 -0
- data/lib/package/uninstaller.fy +15 -0
- data/lib/parser.fy +4 -0
- data/lib/parser/ext/README +15 -0
- data/lib/parser/ext/ext.c +42 -0
- data/lib/parser/ext/ext.h +8 -0
- data/lib/parser/ext/extconf.rb +3 -0
- data/lib/parser/ext/lexer.lex +187 -0
- data/lib/parser/ext/parser.y +744 -0
- data/lib/parser/methods.fy +297 -0
- data/lib/rbx.fy +37 -0
- data/lib/rbx/array.fy +237 -0
- data/lib/rbx/bignum.fy +23 -0
- data/lib/rbx/block.fy +9 -0
- data/lib/rbx/class.fy +129 -0
- data/lib/rbx/code_loader.fy +192 -0
- data/lib/rbx/console.fy +63 -0
- data/lib/rbx/directory.fy +46 -0
- data/lib/rbx/documentation.fy +64 -0
- data/lib/rbx/environment_variables.fy +3 -0
- data/lib/rbx/exception.fy +30 -0
- data/lib/rbx/false_class.fy +58 -0
- data/lib/rbx/fiber.fy +25 -0
- data/lib/rbx/file.fy +191 -0
- data/lib/rbx/fixnum.fy +25 -0
- data/lib/rbx/float.fy +14 -0
- data/lib/rbx/hash.fy +38 -0
- data/lib/rbx/integer.fy +15 -0
- data/lib/rbx/io.fy +30 -0
- data/lib/rbx/match_data.fy +9 -0
- data/lib/rbx/method.fy +22 -0
- data/lib/rbx/name_error.fy +3 -0
- data/lib/rbx/no_method_error.fy +15 -0
- data/lib/rbx/object.fy +117 -0
- data/lib/rbx/range.fy +15 -0
- data/lib/rbx/regexp.fy +9 -0
- data/lib/rbx/string.fy +63 -0
- data/lib/rbx/symbol.fy +12 -0
- data/lib/rbx/system.fy +37 -0
- data/lib/rbx/tcp_server.fy +6 -0
- data/lib/rbx/tcp_socket.fy +7 -0
- data/lib/rbx/thread.fy +75 -0
- data/lib/rbx/tuple.fy +37 -0
- data/lib/set.fy +61 -0
- data/lib/stack.fy +51 -0
- data/lib/string.fy +58 -0
- data/lib/struct.fy +13 -0
- data/lib/symbol.fy +23 -0
- data/lib/true_class.fy +43 -0
- data/lib/tuple.fy +68 -0
- data/lib/version.fy +6 -0
- data/tests/argv.fy +13 -0
- data/tests/array.fy +343 -0
- data/tests/assignment.fy +53 -0
- data/tests/block.fy +103 -0
- data/tests/class.fy +409 -0
- data/tests/control_flow.fy +79 -0
- data/tests/documentation.fy +24 -0
- data/tests/exception.fy +115 -0
- data/tests/file.fy +86 -0
- data/tests/hash.fy +101 -0
- data/tests/method.fy +131 -0
- data/tests/nil_class.fy +55 -0
- data/tests/number.fy +128 -0
- data/tests/object.fy +125 -0
- data/tests/parsing/sexp.fy +50 -0
- data/tests/pattern_matching.fy +82 -0
- data/tests/range.fy +11 -0
- data/tests/set.fy +10 -0
- data/tests/stack.fy +22 -0
- data/tests/string.fy +102 -0
- data/tests/symbol.fy +17 -0
- data/tests/true_class.fy +63 -0
- data/tests/tuple.fy +21 -0
- data/tools/fancy-mode.el +63 -0
- metadata +321 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
FancySpec describe: "Control Flow" with: {
|
2
|
+
|
3
|
+
it: "should NOT call the block if not nil" for: 'if_nil: when: {
|
4
|
+
'foo if_nil: { 'is_nil } . should == nil
|
5
|
+
"hello, world" if_nil: { 'is_nil } . should == nil
|
6
|
+
}
|
7
|
+
|
8
|
+
it: "should work like if_true:" for: 'if:then: when: {
|
9
|
+
if: (4 < 5) then: {
|
10
|
+
4 < 5 should == true
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
it: "should work like if_true:else: " for: 'if:then:else: when: {
|
15
|
+
if: (4 < 5) then: {
|
16
|
+
4 < 5 should == true
|
17
|
+
} else: {
|
18
|
+
4 < 5 should == nil
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
it: "should work like while_true:" for: 'while:do: when: {
|
23
|
+
x = 0
|
24
|
+
while: { x < 10 } do: {
|
25
|
+
x < 10 should == true
|
26
|
+
x = x + 1
|
27
|
+
}
|
28
|
+
x == 10 should == true
|
29
|
+
}
|
30
|
+
|
31
|
+
it: "should work like while_false: " for: 'until:do: when: {
|
32
|
+
x = 0
|
33
|
+
until: { x == 10 } do: {
|
34
|
+
x < 10 should == true
|
35
|
+
x = x + 1
|
36
|
+
}
|
37
|
+
x == 10 should == true
|
38
|
+
}
|
39
|
+
|
40
|
+
it: "should work like if_false:: " for: 'unless:do: when: {
|
41
|
+
unless: (4 > 5) do: {
|
42
|
+
5 > 4 should == true
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
it: "should only call the block if it's a true-ish value" for: 'if_do: when: {
|
47
|
+
1 if_do: |num| {
|
48
|
+
num * 10
|
49
|
+
} . should == 10
|
50
|
+
|
51
|
+
nil if_do: {
|
52
|
+
"nope"
|
53
|
+
} . should == nil
|
54
|
+
|
55
|
+
false if_do: {
|
56
|
+
"nope again"
|
57
|
+
} . should == nil
|
58
|
+
}
|
59
|
+
|
60
|
+
it: "should call the then_block if it's a true-ish value and call the else_block otherwise" for: 'if_do:else: when: {
|
61
|
+
1 if_do: |num| {
|
62
|
+
num * 10
|
63
|
+
} else: {
|
64
|
+
nil
|
65
|
+
} . should == 10
|
66
|
+
|
67
|
+
nil if_do: {
|
68
|
+
"nope"
|
69
|
+
} else: {
|
70
|
+
"yup"
|
71
|
+
} . should == "yup"
|
72
|
+
|
73
|
+
false if_do: {
|
74
|
+
"nope again"
|
75
|
+
} else: {
|
76
|
+
"yup again"
|
77
|
+
} . should == "yup again"
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
FancySpec describe: "Documentations" with: {
|
2
|
+
it: "should display the documentation for a method" when: {
|
3
|
+
documentation = "Array#each: iterates over its elements, calling a given block with each element."
|
4
|
+
Array new method: "each:" . documentation: documentation
|
5
|
+
Array new method: "each:" . documentation . docs first should == documentation
|
6
|
+
}
|
7
|
+
|
8
|
+
it: "should define a documenation string for a class and method" when: {
|
9
|
+
class ClassWithDoc {
|
10
|
+
"This class has a documentation! Yay!"
|
11
|
+
def foo {
|
12
|
+
"bar!"
|
13
|
+
nil
|
14
|
+
}
|
15
|
+
}
|
16
|
+
ClassWithDoc documentation should_not == ""
|
17
|
+
ClassWithDoc documentation should == "This class has a documentation! Yay!"
|
18
|
+
ClassWithDoc new method: 'foo . documentation docs should == ["bar!"]
|
19
|
+
}
|
20
|
+
|
21
|
+
it: "should have a documentation string for a method" when: {
|
22
|
+
Array new method: "first" . documentation should_not be: 'nil?
|
23
|
+
}
|
24
|
+
}
|
data/tests/exception.fy
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
class Foo {
|
2
|
+
def bar: x {
|
3
|
+
(x == 'error) . if_true: {
|
4
|
+
StdError new: "Some Error" . raise!
|
5
|
+
} else: {
|
6
|
+
'no_error
|
7
|
+
}
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
FancySpec describe: StdError with: {
|
12
|
+
it: "should raise an exception and catch it correctly" for: 'raise! when: {
|
13
|
+
try {
|
14
|
+
StdError new: "FAIL!" . raise!
|
15
|
+
nil should == true # this should not occur
|
16
|
+
} catch StdError => ex {
|
17
|
+
ex message should == "FAIL!"
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
it: "should raise an exception inside a method and catch it correctly" when: {
|
22
|
+
f = Foo new
|
23
|
+
f bar: "Don't raise here" . should == 'no_error
|
24
|
+
try {
|
25
|
+
f bar: 'error . should == 'no_error
|
26
|
+
} catch StdError => e {
|
27
|
+
e message should == "Some Error"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
# it: "should raise a NoMethodError" when: {
|
32
|
+
# s = 'symbol
|
33
|
+
# try {
|
34
|
+
# s this_method_doesnt_exist!
|
35
|
+
# nil should == true # should not execute
|
36
|
+
# } catch NoMethodError => err {
|
37
|
+
# err for_class should == Symbol
|
38
|
+
# err method_name should == "this_method_doesnt_exist!"
|
39
|
+
# }
|
40
|
+
# }
|
41
|
+
|
42
|
+
it: "should have access to variables in exception handlers defined in the surrounding scope" when: {
|
43
|
+
var = 1234
|
44
|
+
try {
|
45
|
+
var wont_work!
|
46
|
+
} catch NoMethodError => err {
|
47
|
+
var should == 1234
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
it: "should always evaluate the finally clause" when: {
|
52
|
+
try {
|
53
|
+
x = 10 / 0 # ouch!
|
54
|
+
"This should fail!" should == true # should not get here!
|
55
|
+
} catch ZeroDivisionError => err {
|
56
|
+
err message should == "divided by 0"
|
57
|
+
} finally {
|
58
|
+
# this part gets always run :)
|
59
|
+
"It works!" should == "It works!"
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
it: "should raise a StdError when raising a String" for: 'raise! when: {
|
64
|
+
msg = "A Custom Error!"
|
65
|
+
try {
|
66
|
+
msg raise!
|
67
|
+
msg should_not == msg # this should not get executed
|
68
|
+
} catch StdError => e {
|
69
|
+
e message should == msg
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
# it: "should raise and catch a custom exception correctly" for: 'raise! when: {
|
74
|
+
# class MyError : StdError{
|
75
|
+
# def initialize {
|
76
|
+
# super initialize: "MyError message"
|
77
|
+
# }
|
78
|
+
# }
|
79
|
+
|
80
|
+
# try {
|
81
|
+
# MyError new raise!
|
82
|
+
# nil should == true # will fail
|
83
|
+
# } catch MyError => e {
|
84
|
+
# e message should == "MyError message"
|
85
|
+
# }
|
86
|
+
# }
|
87
|
+
|
88
|
+
it: "should restart itself after being fixed in a catch clause" when: {
|
89
|
+
y = 0
|
90
|
+
x = 0
|
91
|
+
try {
|
92
|
+
x = 10 / y
|
93
|
+
} catch ZeroDivisionError => e {
|
94
|
+
y should == 0
|
95
|
+
x should == 0
|
96
|
+
y = 2
|
97
|
+
retry
|
98
|
+
}
|
99
|
+
y should == 2
|
100
|
+
x should == 5
|
101
|
+
}
|
102
|
+
|
103
|
+
it: "should always execute the finally block when defined" when: {
|
104
|
+
try {
|
105
|
+
msg = "Reraise a new Exception :P"
|
106
|
+
try {
|
107
|
+
10 / 0 # ZeroDivisionError
|
108
|
+
} finally {
|
109
|
+
msg raise!
|
110
|
+
}
|
111
|
+
} catch StdError => e {
|
112
|
+
e message should == msg
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
data/tests/file.fy
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
FancySpec describe: File with: {
|
2
|
+
it: "should return an array with the openmodes symbols" for: 'open:modes: when: {
|
3
|
+
file = File open: "README" modes: ['read]
|
4
|
+
file modes should == ['read]
|
5
|
+
file close
|
6
|
+
}
|
7
|
+
|
8
|
+
it: "should be open after opening it and closed after closing" for: 'close when: {
|
9
|
+
file = File open: "README" modes: ['read]
|
10
|
+
file open? should == true
|
11
|
+
file close
|
12
|
+
file open? should == false
|
13
|
+
}
|
14
|
+
|
15
|
+
# it: "should be closed when not correctly opened" for: 'open? when: {
|
16
|
+
# file = File new
|
17
|
+
# file open? should == nil
|
18
|
+
# file close
|
19
|
+
# file open? should == nil
|
20
|
+
# }
|
21
|
+
|
22
|
+
it: "should write and read from a file correctly" for: 'writeln: when: {
|
23
|
+
filename = "/tmp/read_write_test.txt"
|
24
|
+
file = File open: filename modes: ['write]
|
25
|
+
file writeln: "hello, world!"
|
26
|
+
file writeln: "line number two"
|
27
|
+
file close
|
28
|
+
|
29
|
+
File exists?: filename . should == true
|
30
|
+
|
31
|
+
file = File open: filename modes: ['read]
|
32
|
+
lines = []
|
33
|
+
2 times: {
|
34
|
+
lines << (file readln)
|
35
|
+
}
|
36
|
+
lines[0] should == "hello, world!\n"
|
37
|
+
lines[1] should == "line number two\n"
|
38
|
+
lines should == ["hello, world!\n", "line number two\n"]
|
39
|
+
|
40
|
+
# delete file
|
41
|
+
File delete: filename
|
42
|
+
File exists?: filename . should == false
|
43
|
+
}
|
44
|
+
|
45
|
+
it: "should raise an IOError exception when trying to open an invalid file" when: {
|
46
|
+
try {
|
47
|
+
file = File open: "/foo/bar/baz" modes: ['read]
|
48
|
+
nil should == true # this shouldn't execute
|
49
|
+
} catch IOError => e {
|
50
|
+
#e filename should == "/foo/bar/baz"
|
51
|
+
#e modes should == ['read]
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
it: "should rename a File" when: {
|
56
|
+
dirname = "tmp/"
|
57
|
+
filename = dirname ++ "foobar"
|
58
|
+
|
59
|
+
Directory create: dirname
|
60
|
+
|
61
|
+
File open: filename modes: ['write] with: |f| {
|
62
|
+
f writeln: "testing!"
|
63
|
+
}
|
64
|
+
|
65
|
+
Directory exists?: dirname . should == true
|
66
|
+
File exists?: dirname . should == true
|
67
|
+
File directory?: dirname . should == true
|
68
|
+
|
69
|
+
File rename: filename to: (filename ++ "-new")
|
70
|
+
File exists?: filename . should == false
|
71
|
+
File exists?: (filename ++ "-new") . should == true
|
72
|
+
File delete: (filename ++ "-new")
|
73
|
+
Directory delete: "tmp/"
|
74
|
+
}
|
75
|
+
|
76
|
+
it: "should be a directory" for: 'directory?: when: {
|
77
|
+
File directory?: "lib/" . should == true
|
78
|
+
File directory?: "lib/rbx" . should == true
|
79
|
+
}
|
80
|
+
|
81
|
+
it: "should NOT be a directory" for: 'directory?: when: {
|
82
|
+
File directory?: "src/Makefile" . should == false
|
83
|
+
File directory?: "README" . should == false
|
84
|
+
File directory?: "src/bootstrap/Makefile" . should == false
|
85
|
+
}
|
86
|
+
}
|
data/tests/hash.fy
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
FancySpec describe: Hash with: {
|
2
|
+
it: "should be empty on initialization" for: 'empty? when: {
|
3
|
+
hash = <[]>
|
4
|
+
hash size should == 0
|
5
|
+
hash empty? should == true
|
6
|
+
}
|
7
|
+
|
8
|
+
it: "should be empty on initialization via Hash#new" for: 'size when: {
|
9
|
+
hash = Hash new
|
10
|
+
hash size should == 0
|
11
|
+
hash empty? should == true
|
12
|
+
}
|
13
|
+
|
14
|
+
it: "should contain one entry" when: {
|
15
|
+
hash = <['foo => "bar"]>
|
16
|
+
hash size should == 1
|
17
|
+
hash empty? should == false
|
18
|
+
}
|
19
|
+
|
20
|
+
it: "should contain 10 square values after 10 insertions" for: 'at: when: {
|
21
|
+
hash = Hash new
|
22
|
+
10 times: |i| {
|
23
|
+
hash at: i put: (i * i)
|
24
|
+
}
|
25
|
+
|
26
|
+
10 times: |i| {
|
27
|
+
hash at: i . should == (i * i)
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
it: "should override the value for a given key" for: 'at: when: {
|
32
|
+
hash = <['foo => "bar"]>
|
33
|
+
hash at: 'foo . should == "bar"
|
34
|
+
hash at: 'foo put: 'foobarbaz
|
35
|
+
hash at: 'foo . should == 'foobarbaz
|
36
|
+
}
|
37
|
+
|
38
|
+
it: "should return all keys" for: 'keys when: {
|
39
|
+
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
40
|
+
hash keys should =? ['foo, 'bar, 'foobar]
|
41
|
+
}
|
42
|
+
|
43
|
+
it: "should return all values" for: 'values when: {
|
44
|
+
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
45
|
+
hash values should =? ["bar", "baz", 112.21]
|
46
|
+
}
|
47
|
+
|
48
|
+
it: "should return value by the []-operator" for: "[]" when: {
|
49
|
+
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
50
|
+
hash['foo] should == "bar"
|
51
|
+
hash['bar] should == "baz"
|
52
|
+
hash['foobar] should == 112.21
|
53
|
+
}
|
54
|
+
|
55
|
+
it: "should call the Block for each key and value" for: 'each: when: {
|
56
|
+
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
57
|
+
hash each: |key val| {
|
58
|
+
val should == (hash[key])
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
it: "should call the Block with each key" for: 'each_key: when: {
|
63
|
+
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
64
|
+
count = 0
|
65
|
+
hash each_key: |key| {
|
66
|
+
key should == (hash keys[count])
|
67
|
+
count = count + 1
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
it: "should call the Block with each value" for: 'each_value: when: {
|
72
|
+
hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]>
|
73
|
+
count = 0
|
74
|
+
hash each_value: |val| {
|
75
|
+
val should == (hash values[count])
|
76
|
+
count = count + 1
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
it: "should call most Enumerable methods with each pair" when: {
|
81
|
+
hash = <['hello => "world", 'fancy => "is cool"]>
|
82
|
+
|
83
|
+
hash map: |pair| { pair[0] } . should =? ['hello, 'fancy] # order does not matter
|
84
|
+
|
85
|
+
hash select: |pair| { pair[1] to_s includes?: "c" } .
|
86
|
+
should == [['fancy, "is cool"]]
|
87
|
+
|
88
|
+
hash reject: |pair| { pair[0] to_s includes?: "l" } .
|
89
|
+
map: 'second . should == ["is cool"]
|
90
|
+
}
|
91
|
+
|
92
|
+
it: "should return nil if the key isn't defined" when: {
|
93
|
+
<['foo => "bar"]> ['bar] . should == nil
|
94
|
+
<[]> ['foobar] . should == nil
|
95
|
+
<['foo => "bar"]> [nil] . should == nil
|
96
|
+
}
|
97
|
+
|
98
|
+
it: "should return an Array of the key-value pairs" when: {
|
99
|
+
<['foo => "bar", 'bar => "baz"]> to_a should =? [['foo, "bar"], ['bar, "baz"]]
|
100
|
+
}
|
101
|
+
}
|
data/tests/method.fy
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
FancySpec describe: Method with: {
|
2
|
+
it: "should return a Method object" when: {
|
3
|
+
[1,2,3] method: "each:" . class should == Method
|
4
|
+
}
|
5
|
+
|
6
|
+
# it: "should return the (correct) sender object of the MessageSend" when: {
|
7
|
+
# class SenderTest {
|
8
|
+
# def give_me_the_sender! {
|
9
|
+
# __sender__
|
10
|
+
# }
|
11
|
+
# }
|
12
|
+
|
13
|
+
# x = SenderTest new
|
14
|
+
# x give_me_the_sender! should == self
|
15
|
+
# }
|
16
|
+
|
17
|
+
# it: "should return the amount of arguments a Method takes" for: 'argcount when: {
|
18
|
+
# class Foo {
|
19
|
+
# def no_args {
|
20
|
+
# }
|
21
|
+
# def one_arg: yo {
|
22
|
+
# }
|
23
|
+
# def two: a args: b {
|
24
|
+
# }
|
25
|
+
# def three: a args: b ok: c {
|
26
|
+
# }
|
27
|
+
# }
|
28
|
+
|
29
|
+
# Foo method: 'no_args . argcount should == 0
|
30
|
+
# Foo method: "one_arg:" . argcount should == 1
|
31
|
+
# Foo method: "two:args:" . argcount should == 2
|
32
|
+
# Foo method: "three:args:ok:" . argcount should == 3
|
33
|
+
# }
|
34
|
+
|
35
|
+
# it: "should return the return value" when: {
|
36
|
+
# def foo: bar {
|
37
|
+
# return "returning!"
|
38
|
+
# bar # will never get executed
|
39
|
+
# }
|
40
|
+
|
41
|
+
# foo: "yay" . should == "returning!"
|
42
|
+
|
43
|
+
# # another example
|
44
|
+
|
45
|
+
# def f: x {
|
46
|
+
# x < 10 if_true: {
|
47
|
+
# return 100
|
48
|
+
# }
|
49
|
+
# 0
|
50
|
+
# }
|
51
|
+
|
52
|
+
# f: 10 . should == 0
|
53
|
+
# f: 9 . should == 100
|
54
|
+
|
55
|
+
# # and another one
|
56
|
+
|
57
|
+
# def foo {
|
58
|
+
# 10 times: |i| {
|
59
|
+
# i == 8 if_true: {
|
60
|
+
# return i # nested return
|
61
|
+
# }
|
62
|
+
# }
|
63
|
+
# return 0
|
64
|
+
# }
|
65
|
+
|
66
|
+
# self foo should == 8
|
67
|
+
# }
|
68
|
+
|
69
|
+
it: "should return only from block-scope not from method-scope" when: {
|
70
|
+
def self foo {
|
71
|
+
10 times: |i| {
|
72
|
+
i == 8 if_true: {
|
73
|
+
return i
|
74
|
+
}
|
75
|
+
}
|
76
|
+
0
|
77
|
+
}
|
78
|
+
self foo should == 8
|
79
|
+
}
|
80
|
+
|
81
|
+
# it: "should return locally (from block-scope not from method-scope" when: {
|
82
|
+
# def self foo {
|
83
|
+
# [1,2,3] select: |x| { return_local x != 3 }
|
84
|
+
# }
|
85
|
+
# self foo should == [1,2]
|
86
|
+
# }
|
87
|
+
|
88
|
+
# class Foo {
|
89
|
+
# def bar {
|
90
|
+
# }
|
91
|
+
# def private private_bar {
|
92
|
+
# }
|
93
|
+
# def protected protected_bar {
|
94
|
+
# }
|
95
|
+
# }
|
96
|
+
|
97
|
+
# it: "should be public" for: 'public? when: {
|
98
|
+
# Foo method: 'bar . public? should == true
|
99
|
+
# Foo method: 'private_bar . public? should == nil
|
100
|
+
# Foo method: 'protected_bar . public? should == nil
|
101
|
+
# }
|
102
|
+
|
103
|
+
# it: "should be private" for: 'private? when: {
|
104
|
+
# Foo method: 'bar . private? should == nil
|
105
|
+
# Foo method: 'private_bar . private? should == true
|
106
|
+
# Foo method: 'protected_bar . private? should == nil
|
107
|
+
# }
|
108
|
+
|
109
|
+
# it: "should be protected" for: 'protected? when: {
|
110
|
+
# Foo method: 'bar . protected? should == nil
|
111
|
+
# Foo method: 'private_bar . protected? should == nil
|
112
|
+
# Foo method: 'protected_bar . protected? should == true
|
113
|
+
# }
|
114
|
+
|
115
|
+
it: "should set the default values for optional argument, when not passed in" when: {
|
116
|
+
def foo: arg1 bar: arg2 ("foo") baz: arg3 (nil) {
|
117
|
+
arg1 ++ arg2 ++ arg3
|
118
|
+
}
|
119
|
+
|
120
|
+
foo: "hello" bar: "world" baz: "!" . should == "helloworld!"
|
121
|
+
foo: "hello" bar: "world" . should == "helloworld"
|
122
|
+
foo: "hello" . should == "hellofoo"
|
123
|
+
}
|
124
|
+
|
125
|
+
it: "should return multiple values (as a Tuple)" when: {
|
126
|
+
def multiple_return_values: x {
|
127
|
+
(x, x + x, x + x + x)
|
128
|
+
}
|
129
|
+
val = multiple_return_values: 3 . should == (3, 6, 9)
|
130
|
+
}
|
131
|
+
}
|