AmberVM 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- data/README +38 -0
- data/bin/ambervm +278 -0
- data/lib/amber/acts_as_rvm_type.rb +157 -0
- data/lib/amber/classes/association.rb +36 -0
- data/lib/amber/classes/block.rb +52 -0
- data/lib/amber/classes/boolean.rb +40 -0
- data/lib/amber/classes/class.rb +50 -0
- data/lib/amber/classes/error.rb +22 -0
- data/lib/amber/classes/list.rb +96 -0
- data/lib/amber/classes/null.rb +35 -0
- data/lib/amber/classes/number.rb +95 -0
- data/lib/amber/classes/object.rb +56 -0
- data/lib/amber/classes/string.rb +79 -0
- data/lib/amber/classes.rb +113 -0
- data/lib/amber/environment.rb +251 -0
- data/lib/amber/fukubukuro/ecma_core.rb +409 -0
- data/lib/amber/fukubukuro.rb +866 -0
- data/lib/amber/functions/all.rb +3 -0
- data/lib/amber/functions/array/append.rb +50 -0
- data/lib/amber/functions/array/at.rb +50 -0
- data/lib/amber/functions/array/set_at.rb +50 -0
- data/lib/amber/functions/array.rb +30 -0
- data/lib/amber/functions/association/assoc_get.rb +55 -0
- data/lib/amber/functions/association/assoc_set.rb +56 -0
- data/lib/amber/functions/bitwise/bitwise_and.rb +41 -0
- data/lib/amber/functions/bitwise/bitwise_not.rb +41 -0
- data/lib/amber/functions/bitwise/bitwise_or.rb +41 -0
- data/lib/amber/functions/bitwise/bitwise_xor.rb +41 -0
- data/lib/amber/functions/bitwise.rb +3 -0
- data/lib/amber/functions/collection/get.rb +66 -0
- data/lib/amber/functions/collection/set.rb +67 -0
- data/lib/amber/functions/collection/size.rb +54 -0
- data/lib/amber/functions/general/cmp.rb +43 -0
- data/lib/amber/functions/general/eq.rb +45 -0
- data/lib/amber/functions/general/gt.rb +45 -0
- data/lib/amber/functions/general/gte.rb +45 -0
- data/lib/amber/functions/general/lt.rb +45 -0
- data/lib/amber/functions/general/lte.rb +45 -0
- data/lib/amber/functions/general/neq.rb +45 -0
- data/lib/amber/functions/general/type.rb +43 -0
- data/lib/amber/functions/general.rb +3 -0
- data/lib/amber/functions/io/print.rb +45 -0
- data/lib/amber/functions/io.rb +3 -0
- data/lib/amber/functions/list/align.rb +73 -0
- data/lib/amber/functions/list/join.rb +45 -0
- data/lib/amber/functions/list/map.rb +58 -0
- data/lib/amber/functions/list/split.rb +55 -0
- data/lib/amber/functions/list.rb +3 -0
- data/lib/amber/functions/logic/and.rb +55 -0
- data/lib/amber/functions/logic/not.rb +40 -0
- data/lib/amber/functions/logic/or.rb +50 -0
- data/lib/amber/functions/logic.rb +3 -0
- data/lib/amber/functions/math/abs.rb +39 -0
- data/lib/amber/functions/math/acos.rb +39 -0
- data/lib/amber/functions/math/add.rb +40 -0
- data/lib/amber/functions/math/asin.rb +39 -0
- data/lib/amber/functions/math/atan.rb +39 -0
- data/lib/amber/functions/math/ceil.rb +39 -0
- data/lib/amber/functions/math/cos.rb +39 -0
- data/lib/amber/functions/math/dec.rb +39 -0
- data/lib/amber/functions/math/div.rb +44 -0
- data/lib/amber/functions/math/exp.rb +39 -0
- data/lib/amber/functions/math/floor.rb +39 -0
- data/lib/amber/functions/math/inc.rb +39 -0
- data/lib/amber/functions/math/log.rb +39 -0
- data/lib/amber/functions/math/mod.rb +41 -0
- data/lib/amber/functions/math/mul.rb +43 -0
- data/lib/amber/functions/math/neg.rb +43 -0
- data/lib/amber/functions/math/power.rb +43 -0
- data/lib/amber/functions/math/rand.rb +36 -0
- data/lib/amber/functions/math/round.rb +39 -0
- data/lib/amber/functions/math/shl.rb +41 -0
- data/lib/amber/functions/math/shr.rb +41 -0
- data/lib/amber/functions/math/sin.rb +39 -0
- data/lib/amber/functions/math/sub.rb +43 -0
- data/lib/amber/functions/math/tan.rb +39 -0
- data/lib/amber/functions/math.rb +3 -0
- data/lib/amber/functions/objects/send.rb +22 -0
- data/lib/amber/functions/rails/print.rb +44 -0
- data/lib/amber/functions/rails.rb +3 -0
- data/lib/amber/functions/string/ansi.rb +24 -0
- data/lib/amber/functions/string/capstr.rb +23 -0
- data/lib/amber/functions/string/center.rb +25 -0
- data/lib/amber/functions/string/chr.rb +16 -0
- data/lib/amber/functions/string/ljust.rb +26 -0
- data/lib/amber/functions/string/regmatch.rb +34 -0
- data/lib/amber/functions/string/rjust.rb +26 -0
- data/lib/amber/functions/string.rb +3 -0
- data/lib/amber/functions.rb +103 -0
- data/lib/amber/interpreter.rb +1380 -0
- data/lib/amber/languages/brainfuck.rb +153 -0
- data/lib/amber/languages/ecma/compiler.rb +1661 -0
- data/lib/amber/languages/ecma/core-math.js +67 -0
- data/lib/amber/languages/ecma/core-objects.js +57 -0
- data/lib/amber/languages/ecma.rb +9 -0
- data/lib/amber/languages/ecma_fuku/compiler.rb +1622 -0
- data/lib/amber/languages/ecma_fuku/core-math.js +67 -0
- data/lib/amber/languages/ecma_fuku/core-objects.js +56 -0
- data/lib/amber/languages/ecma_fuku.rb +13 -0
- data/lib/amber/languages/math/compiler.rb +70 -0
- data/lib/amber/languages/math/tokenizer.rb +69 -0
- data/lib/amber/languages/math/tree.rb +110 -0
- data/lib/amber/languages/math.rb +26 -0
- data/lib/amber/languages.rb +99 -0
- data/lib/amber/library.rb +79 -0
- data/lib/amber/optimisation.rb +299 -0
- data/lib/amber/plugin.rb +337 -0
- data/lib/amber/rails.rb +90 -0
- data/lib/amber.rb +106 -0
- data/spec/amber/class_spec.rb +27 -0
- data/spec/amber/enviroment_spec.rb +61 -0
- data/spec/amber/function_spec.rb +25 -0
- data/spec/amber/functions/association/assoc_get_spec.rb +41 -0
- data/spec/amber/functions/association/assoc_set_spec.rb +43 -0
- data/spec/amber/functions/collection/get_spec.rb +12 -0
- data/spec/amber/functions/collection/set_spec.rb +10 -0
- data/spec/amber/functions/collection/size_spec.rb +10 -0
- data/spec/amber/functions/list/split_spec.rb +47 -0
- data/spec/amber/functions/string/ansi_spec.rb +44 -0
- data/spec/amber/functions/string/capstr_spec.rb +42 -0
- data/spec/amber/functions/string/center_spec.rb +49 -0
- data/spec/amber/functions/string/ljust_spec.rb +49 -0
- data/spec/amber/functions/string/regmatch_spec.rb +52 -0
- data/spec/amber/functions/string/rjust_spec.rb +49 -0
- data/spec/amber/interpreter/assignment_spec.rb +22 -0
- data/spec/amber/interpreter/condition_spec.rb +103 -0
- data/spec/amber/interpreter/constant_spec.rb +31 -0
- data/spec/amber/interpreter/core_call_spec.rb +72 -0
- data/spec/amber/interpreter/interpreter_spec.rb +11 -0
- data/spec/amber/interpreter/parameter_spec.rb +24 -0
- data/spec/amber/interpreter/sequence_spec.rb +47 -0
- data/spec/amber/interpreter/variable_spec.rb +24 -0
- data/spec/amber/plugin_spec.rb +10 -0
- data/spec/classes/atom/association_spec.rb +39 -0
- data/spec/classes/atom/block_spec.rb +25 -0
- data/spec/classes/atom/boolean_spec.rb +67 -0
- data/spec/classes/atom/error_spec.rb +43 -0
- data/spec/classes/atom/list_spec.rb +68 -0
- data/spec/classes/atom/number_spec.rb +132 -0
- data/spec/classes/atom/string_spec.rb +175 -0
- data/spec/languages/ecma/ecma_array_spec.rb +79 -0
- data/spec/languages/ecma/ecma_closure_spec.rb +38 -0
- data/spec/languages/ecma/ecma_literals_spec.rb +71 -0
- data/spec/languages/ecma/ecma_objects_spec.rb +165 -0
- data/spec/languages/ecma/ecma_old_spec.rb +540 -0
- data/spec/languages/ecma/ecma_spec.rb +64 -0
- data/spec/languages/ecma_fuku/ecma_array_spec.rb +61 -0
- data/spec/languages/ecma_fuku/ecma_closure_spec.rb +33 -0
- data/spec/languages/ecma_fuku/ecma_function_spec.rb +84 -0
- data/spec/languages/ecma_fuku/ecma_literals_spec.rb +55 -0
- data/spec/languages/ecma_fuku/ecma_objects_spec.rb +133 -0
- data/spec/languages/ecma_fuku/ecma_old_spec.rb +415 -0
- data/spec/languages/ecma_fuku/ecma_operator_spec.rb +33 -0
- data/spec/languages/ecma_fuku/ecma_spec.rb +52 -0
- data/spec/languages/math/compiler_spec.rb +49 -0
- data/spec/languages/math/tokenizer_spec.rb +73 -0
- data/spec/languages/math/tree_spec.rb +153 -0
- metadata +225 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../helpers/plugin_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../../helpers/function_helper'
|
3
|
+
require 'amber/functions/string/regmatch'
|
4
|
+
|
5
|
+
|
6
|
+
describe AmberVM::Functions::Regmatch do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@object = AmberVM::Functions::Regmatch
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "(plugin)" do
|
13
|
+
it_should_behave_like "a plugin"
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "(function)" do
|
18
|
+
it_should_behave_like "a function"
|
19
|
+
|
20
|
+
it "should have a signature of string, string" do
|
21
|
+
@object.signature.should == [AmberVM::Classes::String, AmberVM::Classes::String]
|
22
|
+
end
|
23
|
+
it "should have a type of boolean" do
|
24
|
+
@object.data_type.should == :boolean
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "(functionality)" do
|
29
|
+
|
30
|
+
it "should not work with exactly 2" do
|
31
|
+
@object.execute([], nil).should be_instance_of(AmberVM::Classes::Error)
|
32
|
+
@object.execute([1], nil).should be_instance_of(AmberVM::Classes::Error)
|
33
|
+
@object.execute([1,2,3], nil).should be_instance_of(AmberVM::Classes::Error)
|
34
|
+
@object.execute([1,2,3,4], nil).should be_instance_of(AmberVM::Classes::Error)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should retrn an error if the param is not a valid regexp" do
|
38
|
+
@object.execute(['*','*'], nil).should be_instance_of(AmberVM::Classes::Error)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return true if the regular expressiom matches" do
|
42
|
+
@object.execute(['*','.'], nil).is_true?.should be_true
|
43
|
+
@object.execute(['1','\d'], nil).is_true?.should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return false if the regular expression does not matches" do
|
47
|
+
@object.execute(['*','a'], nil).is_true?.should be_false
|
48
|
+
@object.execute(['abc','\d'], nil).is_true?.should be_false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec/amber/helpers/plugin_helper'
|
2
|
+
require 'spec/amber/helpers/function_helper'
|
3
|
+
require 'amber/functions/string/rjust'
|
4
|
+
|
5
|
+
|
6
|
+
describe AmberVM::Functions::Rjust do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@object = AmberVM::Functions::Rjust
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "(plugin)" do
|
13
|
+
it_should_behave_like "a plugin"
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "(function)" do
|
18
|
+
it_should_behave_like "a function"
|
19
|
+
|
20
|
+
it "should have a signature of string, string" do
|
21
|
+
@object.signature.should == [AmberVM::Classes::String, AmberVM::Classes::Number, AmberVM::Classes::String]
|
22
|
+
end
|
23
|
+
it "should have a type of boolean" do
|
24
|
+
@object.data_type.should == :string
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "(functionality)" do
|
29
|
+
|
30
|
+
it "should not work with less then 2 params or more then 3" do
|
31
|
+
@object.execute([], nil).should be_instance_of(AmberVM::Classes::Error)
|
32
|
+
@object.execute([1], nil).should be_instance_of(AmberVM::Classes::Error)
|
33
|
+
@object.execute([1,2,3,4], nil).should be_instance_of(AmberVM::Classes::Error)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should call the rjust function with one param if it is given" do
|
37
|
+
arg1 = mock('arg mock')
|
38
|
+
arg1.should_receive(:rjust).once.with(1).and_return 'rjust'
|
39
|
+
@object.execute([arg1,1], nil).should == 'rjust'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should call the rjust function with one two param if they are given" do
|
43
|
+
arg1 = mock('arg mock')
|
44
|
+
arg1.should_receive(:rjust).once.with(1,2).and_return 'rjust'
|
45
|
+
@object.execute([arg1,1,2], nil).should == 'rjust'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'amber/interpreter'
|
2
|
+
|
3
|
+
describe AmberVM::Interpreter::Assignment do
|
4
|
+
before do
|
5
|
+
@variable = mock('variable mock')
|
6
|
+
@value = mock('value mock')
|
7
|
+
@env = mock('env mock')
|
8
|
+
@object = AmberVM::Interpreter::Assignment.new(@variable, @value)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have the type of it's value" do
|
12
|
+
@value.should_receive(:data_type).with(no_args).once.and_return(:example)
|
13
|
+
@object.data_type.should == :example
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should execute first the name then the value and store it in env" do
|
17
|
+
@variable.should_receive(:execute).with(@env).once.and_return(@variable)
|
18
|
+
@variable.should_receive(:val=).with('value').once.and_return('value')
|
19
|
+
@value.should_receive(:execute).with(@env).once.and_return('value')
|
20
|
+
@object.execute(@env).should == 'value'
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'amber/interpreter'
|
2
|
+
|
3
|
+
describe AmberVM::Interpreter::Condition do
|
4
|
+
before do
|
5
|
+
@true_case = mock('true case mock')
|
6
|
+
@false_case = mock('false case mock')
|
7
|
+
@condition = mock('condition mock')
|
8
|
+
@env = AmberVM::Interpreter.env
|
9
|
+
@object = AmberVM::Interpreter::Condition.new(@condition, @true_case, @false_case)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should execute the condition if true execute the true case, retring it's value" do
|
13
|
+
result = mock('result mock')
|
14
|
+
result.should_receive(:is_true?).with(no_args).once.and_return(true)
|
15
|
+
@true_case.should_receive(:execute).with(@env).once.and_return('true case')
|
16
|
+
@condition.should_receive(:execute).with(@env).once.and_return(result)
|
17
|
+
@object.execute(@env).should == 'true case'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should execute the condition if false execute the false case, retring it's value" do
|
21
|
+
result = mock('result mock')
|
22
|
+
result.should_receive(:is_true?).with(no_args).once.and_return(false)
|
23
|
+
@false_case.should_receive(:execute).with(@env).once.and_return('false case')
|
24
|
+
@condition.should_receive(:execute).with(@env).once.and_return(result)
|
25
|
+
@object.execute(@env).should == 'false case'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should execute the condition if false and no false condition is given return nil" do
|
29
|
+
@object = AmberVM::Interpreter::Condition.new(@condition, @true_case)
|
30
|
+
result = mock('result mock')
|
31
|
+
result.should_receive(:is_true?).with(no_args).once.and_return(false)
|
32
|
+
@condition.should_receive(:execute).with(@env).once.and_return(result)
|
33
|
+
@object.execute(@env).should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return the type of it's cases if they are the same" do
|
37
|
+
@true_case.should_receive(:data_type).with(no_args).once.and_return('type1')
|
38
|
+
@false_case.should_receive(:data_type).with(no_args).at_least(:once).and_return('type1')
|
39
|
+
@object.data_type.should == 'type1'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return the :any type if the types are not the same" do
|
43
|
+
@true_case.should_receive(:data_type).with(no_args).once.and_return('type1')
|
44
|
+
@false_case.should_receive(:data_type).with(no_args).once.and_return('type2')
|
45
|
+
@object.data_type.should == :any
|
46
|
+
end
|
47
|
+
=begin
|
48
|
+
|
49
|
+
it "should use path 0 for the true case" do
|
50
|
+
result = mock('result mock')
|
51
|
+
result.should_receive(:is_true?).with(no_args).once.and_return(true)
|
52
|
+
path = mock('Path mock')
|
53
|
+
|
54
|
+
@env.should_receive(:path).twice.and_return(path)
|
55
|
+
path.should_receive(:<<).with(0).once
|
56
|
+
path.should_receive(:pop).with(no_args).once.and_return(0)
|
57
|
+
|
58
|
+
@true_case.should_receive(:execute).with(@env).once.and_return('true case')
|
59
|
+
@condition.should_receive(:execute).with(@env).once.and_return(result)
|
60
|
+
@object.execute(@env).should == 'true case'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should use path 1 for the false case" do
|
64
|
+
result = mock('result mock')
|
65
|
+
result.should_receive(:is_true?).with(no_args).once.and_return(false)
|
66
|
+
path = mock('Path mock')
|
67
|
+
|
68
|
+
@env.should_receive(:path).twice.and_return(path)
|
69
|
+
path.should_receive(:<<).with(1).once
|
70
|
+
path.should_receive(:pop).with(no_args).once.and_return(1)
|
71
|
+
|
72
|
+
@false_case.should_receive(:execute).with(@env).once.and_return('false case')
|
73
|
+
@condition.should_receive(:execute).with(@env).once.and_return(result)
|
74
|
+
@object.execute(@env).should == 'false case'
|
75
|
+
end
|
76
|
+
|
77
|
+
=begin
|
78
|
+
it "should add add a new layer to path when called" do
|
79
|
+
@path = mock('path mock')
|
80
|
+
@object = AmberVM::Interpreter::Sequence.new([@part1])
|
81
|
+
@part1.should_receive(:execute).with(@env, nil).once
|
82
|
+
@env.should_receive(:path).with(no_args).exactly(4).times.and_return(@path)
|
83
|
+
@path.should_receive(:<<).with(0).once
|
84
|
+
@path.should_receive(:pop).with(no_args).twice.and_return(0)
|
85
|
+
@path.should_receive(:<<).with(1).once
|
86
|
+
@object.execute(@env)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should skip parts according to the path" do
|
90
|
+
@part2.should_receive(:execute).with(@env, nil).once
|
91
|
+
@env.should_receive(:path).with(no_args).exactly(6).times.and_return([1])
|
92
|
+
@object.execute(@env, [1])
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should hand down the path to the next executor" do
|
96
|
+
@part2.should_receive(:execute).with(@env, [2]).once
|
97
|
+
@env.should_receive(:path).with(no_args).exactly(6).times.and_return([1])
|
98
|
+
@object.execute(@env, [1,2])
|
99
|
+
end
|
100
|
+
=end
|
101
|
+
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'amber/interpreter'
|
2
|
+
|
3
|
+
describe AmberVM::Interpreter::Constant do
|
4
|
+
before do
|
5
|
+
@value = mock('value mock')
|
6
|
+
@env = AmberVM::Interpreter.env
|
7
|
+
@object = AmberVM::Interpreter::Constant.new(@value)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return the value when executed." do
|
11
|
+
@object.execute(@env).should be(@value)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have the data type of it's value" do
|
15
|
+
@value.should_receive(:data_type).with(no_args).once.and_return(:example)
|
16
|
+
@object.data_type.should == :example
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should compare with other constants based on the value" do
|
20
|
+
@object.==(@object).should be_true
|
21
|
+
object2 = AmberVM::Interpreter::Constant.new(@value)
|
22
|
+
@object.==(object2).should be_true
|
23
|
+
object3 = AmberVM::Interpreter::Constant.new(1)
|
24
|
+
@object.==(object3).should be_false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not compare to other types" do
|
28
|
+
@object.==(1).should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'amber/interpreter'
|
2
|
+
require 'amber/classes/block'
|
3
|
+
|
4
|
+
class CoreMock < AmberVM::Functions::Function
|
5
|
+
register_for :mock
|
6
|
+
class << self
|
7
|
+
def call *args
|
8
|
+
'result'
|
9
|
+
end
|
10
|
+
def execargs
|
11
|
+
@execargs
|
12
|
+
end
|
13
|
+
def data_type
|
14
|
+
:type
|
15
|
+
end
|
16
|
+
def execargs=v
|
17
|
+
@execargs = v
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class AmberVM::Interpreter::CoreCall
|
23
|
+
def fun
|
24
|
+
@fun
|
25
|
+
end
|
26
|
+
|
27
|
+
def fun= f
|
28
|
+
@fun = f
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe AmberVM::Interpreter::CoreCall do
|
33
|
+
before do
|
34
|
+
@param1 = mock('param 1 mock')
|
35
|
+
@param2 = mock('param 2 mock')
|
36
|
+
@fun = mock('Core mock')
|
37
|
+
@env = mock('env mock')
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "(execution)" do
|
41
|
+
before do
|
42
|
+
@object = AmberVM::Interpreter::CoreCall.new(:mock, [@param1,@param2])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "shold execute it's params when the Core.execargs returns true" do
|
46
|
+
CoreMock.execargs = true
|
47
|
+
@object = AmberVM::Interpreter::CoreCall.new('mock', [@param1,@param2])
|
48
|
+
@param1.should_receive(:execute).once.with(@env).and_return('param 1')
|
49
|
+
@param2.should_receive(:execute).once.with(@env).and_return('param 2')
|
50
|
+
@object.execute(@env).should == 'result'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "shold not execute it's params when the Core.execargs returns false" do
|
54
|
+
CoreMock.execargs = false
|
55
|
+
@object = AmberVM::Interpreter::CoreCall.new('mock', [@param1,@param2])
|
56
|
+
@object.execute(@env).should == 'result'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return the data type of the Core" do
|
60
|
+
@object.data_type.should == :type
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not compare with random objects" do
|
64
|
+
@object.==(1).should be_false
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should compare with other Core if args and params are true it is the same" do
|
68
|
+
@object = AmberVM::Interpreter::CoreCall.new(:mock, [@param1,@param2])
|
69
|
+
@object.==(@object).should be_true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'amber/interpreter'
|
2
|
+
|
3
|
+
describe AmberVM::Interpreter do
|
4
|
+
|
5
|
+
it "should create a constant" do
|
6
|
+
c = AmberVM::Interpreter.const(:string, 'wobble')
|
7
|
+
c.should be_instance_of(AmberVM::Interpreter::Constant)
|
8
|
+
c.value.should be_instance_of(AmberVM::Classes[:string])
|
9
|
+
c.value.should == 'wobble'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'amber/interpreter'
|
2
|
+
|
3
|
+
describe AmberVM::Interpreter::Parameter do
|
4
|
+
before do
|
5
|
+
@value = mock('value mock')
|
6
|
+
@num = mock('name mock')
|
7
|
+
@env = mock('env mock')
|
8
|
+
@object = AmberVM::Interpreter::Parameter.new(@num)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should give the values type if name is a constant" do
|
12
|
+
@object.data_type.should == :any
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return the correct value and store it's type" do
|
16
|
+
@num.should_receive(:execute).with(@env).once.and_return(0)
|
17
|
+
@env.should_receive(:param).with(0).once.and_return(@value)
|
18
|
+
@value.should_receive(:data_type).with(no_args).once.and_return(:type)
|
19
|
+
@object.execute(@env).should be(@value)
|
20
|
+
@object.data_type.should == :type
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'amber/interpreter'
|
2
|
+
|
3
|
+
describe AmberVM::Interpreter::Sequence do
|
4
|
+
=begin
|
5
|
+
before do
|
6
|
+
@part1 = mock('part1 mock')
|
7
|
+
@part2 = mock('part2 mock')
|
8
|
+
@env = mock('env mock')
|
9
|
+
|
10
|
+
@object = AmberVM::Interpreter::Sequence.new([@part1,@part2])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should execute each part after another" do
|
14
|
+
@part1.should_receive(:execute).with(@env, nil).once
|
15
|
+
@part2.should_receive(:execute).with(@env, nil).once
|
16
|
+
@env.should_receive(:path).with(no_args).exactly(6).times.and_return([1])
|
17
|
+
@object.execute(@env)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a data_type of :any" do
|
21
|
+
@object.data_type.should == :any
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should add add a new layer to path when called" do
|
25
|
+
@path = mock('path mock')
|
26
|
+
@object = AmberVM::Interpreter::Sequence.new([@part1])
|
27
|
+
@part1.should_receive(:execute).with(@env, nil).once
|
28
|
+
@env.should_receive(:path).with(no_args).exactly(4).times.and_return(@path)
|
29
|
+
@path.should_receive(:<<).with(0).once
|
30
|
+
@path.should_receive(:pop).with(no_args).twice.and_return(0)
|
31
|
+
@path.should_receive(:<<).with(1).once
|
32
|
+
@object.execute(@env)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should skip parts according to the path" do
|
36
|
+
@part2.should_receive(:execute).with(@env, nil).once
|
37
|
+
@env.should_receive(:path).with(no_args).exactly(6).times.and_return([1])
|
38
|
+
@object.execute(@env, [1])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should hand down the path to the next executor" do
|
42
|
+
@part2.should_receive(:execute).with(@env, [2]).once
|
43
|
+
@env.should_receive(:path).with(no_args).exactly(6).times.and_return([1])
|
44
|
+
@object.execute(@env, [1,2])
|
45
|
+
end
|
46
|
+
=end
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'amber/interpreter'
|
2
|
+
|
3
|
+
describe AmberVM::Interpreter::Variable do
|
4
|
+
before do
|
5
|
+
@value = mock('value mock')
|
6
|
+
@name = mock('name mock')
|
7
|
+
@env = mock('env mock')
|
8
|
+
@object = AmberVM::Interpreter::Variable.new(@name)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should give the values type if name is a constant" do
|
12
|
+
@object.data_type.should == :any
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return the correct value and store it's type" do
|
16
|
+
@name.should_receive(:execute).with(@env).once.and_return('name')
|
17
|
+
@env.should_receive(:[]).with('name').once.and_return(@value)
|
18
|
+
@value.should_receive(:val).with(no_args).once
|
19
|
+
@object.execute(@env).should be(@value)
|
20
|
+
@object.data_type.should == :any
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'amber/classes'
|
2
|
+
require 'amber/classes/association'
|
3
|
+
require 'amber/functions/association/assoc_get'
|
4
|
+
require 'amber/functions/association/assoc_set'
|
5
|
+
require 'amber/functions/collection/size'
|
6
|
+
|
7
|
+
describe AmberVM::Classes::Association do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@assoc = AmberVM::Classes::Association.new
|
11
|
+
@assoc['key'] = 'value'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should craete with no arguments"
|
15
|
+
|
16
|
+
it "should create with an hash"
|
17
|
+
|
18
|
+
it "should allow you to read values" do
|
19
|
+
@assoc['key'].should == 'value'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow you to write values" do
|
23
|
+
@assoc['key'].should == 'value'
|
24
|
+
@assoc['key'] = 'another value'
|
25
|
+
@assoc['key'].should == 'another value'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should publish a get method" do
|
29
|
+
@assoc.functions.keys.should include('get')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should publish a set method" do
|
33
|
+
@assoc.functions.keys.should include('set')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should publich a size method" do
|
37
|
+
@assoc.functions.keys.should include('size')
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$: << 'lib'
|
2
|
+
require 'amber/classes'
|
3
|
+
require 'amber/interpreter'
|
4
|
+
describe AmberVM::Classes::Block do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@env = AmberVM::Interpreter.env
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should create with a value" do
|
11
|
+
b = AmberVM::Classes::Block.new(nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return true to a execargs call" do
|
15
|
+
b = AmberVM::Classes::Block.new(nil)
|
16
|
+
b.execargs.should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should do nothign on execution" do
|
20
|
+
code = mock('code mock')
|
21
|
+
b = AmberVM::Classes::Block.new(code)
|
22
|
+
b.execute(@env).should be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "amber/classes/boolean"
|
2
|
+
describe AmberVM::Classes::Boolean do
|
3
|
+
|
4
|
+
|
5
|
+
it "shoulds creat with a bool value" do
|
6
|
+
b = AmberVM::Classes::Boolean.new(true)
|
7
|
+
b.is_true?.should be_true
|
8
|
+
b = AmberVM::Classes::Boolean.new(false)
|
9
|
+
b.is_true?.should be_false
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create with nil" do
|
13
|
+
b = AmberVM::Classes::Boolean.new(nil)
|
14
|
+
b.is_true?.should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should use is_true? if existing" do
|
18
|
+
val = mock('value mock')
|
19
|
+
val.should_receive(:respond_to?).once.with(:is_true?).and_return(true)
|
20
|
+
val.should_receive(:is_true?).once.with(no_args).and_return(false)
|
21
|
+
b = AmberVM::Classes::Boolean.new(val)
|
22
|
+
b.is_true?.should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have the data type :boolean" do
|
26
|
+
b = AmberVM::Classes::Boolean.new(true)
|
27
|
+
b.data_type.should == :boolean
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup
|
31
|
+
super
|
32
|
+
@Boolean = AmberVM::Classes::Boolean
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_class
|
36
|
+
assert(@Boolean)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_creation
|
40
|
+
assert(@Boolean.new(@Boolean), "Create not nil object bool")
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_compare
|
44
|
+
assert_equal(@Boolean.new(true),@Boolean.new(true))
|
45
|
+
assert_equal(@Boolean.new(false),@Boolean.new(false))
|
46
|
+
assert_equal(@Boolean.new(false),@Boolean.new(nil))
|
47
|
+
assert_equal(@Boolean.new(true),@Boolean.new(self))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_creation_is_true
|
51
|
+
assert(@Boolean)
|
52
|
+
assert(b1 = @Boolean.new(true), "Create true bool.")
|
53
|
+
assert(b2 = @Boolean.new(false), "Create false bool.")
|
54
|
+
assert(b3 = @Boolean.new(nil), "Create nil bool.")
|
55
|
+
assert(b4 = @Boolean.new(b1), "Create is_true? object bool.")
|
56
|
+
assert(b5 = @Boolean.new(b2), "Create not is_true? object bool.")
|
57
|
+
assert(b6 = @Boolean.new(@Boolean), "Create not nil object bool.")
|
58
|
+
|
59
|
+
assert(b1.is_true?, "Test if true is true.")
|
60
|
+
assert(!b2.is_true?, "Test if false is false.")
|
61
|
+
assert(!b3.is_true?, "Test if nis is false.")
|
62
|
+
assert(b4.is_true?, "Test if a is_true? object is true.")
|
63
|
+
assert(!b5.is_true?, "Test if a not is_true? object is false.")
|
64
|
+
assert(b6.is_true?, "Test if not null object is true.")
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "amber/classes/error"
|
2
|
+
describe AmberVM::Classes::Error do
|
3
|
+
|
4
|
+
describe "(creation)" do
|
5
|
+
|
6
|
+
it "should create with an integer" do
|
7
|
+
e = AmberVM::Classes::Error.new(1,"Test error")
|
8
|
+
e.should be
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create with an integer" do
|
12
|
+
e = AmberVM::Classes::Error.new(1.2,"Test error")
|
13
|
+
e.should be
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should create with with odd stuff" do
|
17
|
+
e = AmberVM::Classes::Error.new(nil,"Test error")
|
18
|
+
e.should be
|
19
|
+
e = AmberVM::Classes::Error.new("muhaha","Test error")
|
20
|
+
e.should be
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "(usage)" do
|
26
|
+
it "shuld convert to a error string" do
|
27
|
+
e = AmberVM::Classes::Error.new(1,"Test error.")
|
28
|
+
e.to_s.should == "#1 Test error."
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should prevent double positive error numbers" do
|
32
|
+
e = AmberVM::Classes::Error.new(-3,"Test error.")
|
33
|
+
e.to_s.should == "#-3 Test error."
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return false for is_true?." do
|
37
|
+
e = AmberVM::Classes::Error.new(1,"Test error.")
|
38
|
+
e.is_true?.should be_false
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|