rVM 0.0.14 → 0.0.17

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.
Files changed (113) hide show
  1. data/README +4 -4
  2. data/bin/rvm +229 -0
  3. data/lib/rvm.rb +6 -6
  4. data/lib/rvm/acts_as_rvm_type.rb +26 -3
  5. data/lib/rvm/classes.rb +9 -15
  6. data/lib/rvm/classes/block.rb +8 -3
  7. data/lib/rvm/classes/class.rb +2 -2
  8. data/lib/rvm/classes/list.rb +1 -1
  9. data/lib/rvm/classes/null.rb +31 -0
  10. data/lib/rvm/classes/number.rb +4 -0
  11. data/lib/rvm/classes/object.rb +1 -1
  12. data/lib/rvm/classes/string.rb +6 -1
  13. data/lib/rvm/environment.rb +256 -0
  14. data/lib/rvm/functions.rb +9 -4
  15. data/lib/rvm/functions/array.rb +26 -2
  16. data/lib/rvm/functions/array/append.rb +31 -1
  17. data/lib/rvm/functions/array/at.rb +29 -1
  18. data/lib/rvm/functions/array/set_at.rb +29 -0
  19. data/lib/rvm/functions/association/assoc_get.rb +34 -0
  20. data/lib/rvm/functions/association/assoc_set.rb +32 -0
  21. data/lib/rvm/functions/bitwise.rb +3 -0
  22. data/lib/rvm/functions/bitwise/bitwise_and.rb +41 -0
  23. data/lib/rvm/functions/bitwise/bitwise_or.rb +41 -0
  24. data/lib/rvm/functions/bitwise/bitwise_xor.rb +41 -0
  25. data/lib/rvm/functions/collection/get.rb +37 -4
  26. data/lib/rvm/functions/collection/set.rb +37 -3
  27. data/lib/rvm/functions/collection/size.rb +33 -1
  28. data/lib/rvm/functions/general/cmp.rb +35 -7
  29. data/lib/rvm/functions/general/eq.rb +29 -0
  30. data/lib/rvm/functions/general/gt.rb +29 -0
  31. data/lib/rvm/functions/general/gte.rb +29 -0
  32. data/lib/rvm/functions/general/lt.rb +29 -0
  33. data/lib/rvm/functions/general/lte.rb +29 -0
  34. data/lib/rvm/functions/general/neq.rb +5 -0
  35. data/lib/rvm/functions/io/print.rb +38 -8
  36. data/lib/rvm/functions/list/align.rb +25 -1
  37. data/lib/rvm/functions/list/join.rb +27 -0
  38. data/lib/rvm/functions/list/map.rb +34 -0
  39. data/lib/rvm/functions/list/split.rb +31 -0
  40. data/lib/rvm/functions/logic/and.rb +36 -2
  41. data/lib/rvm/functions/logic/not.rb +27 -0
  42. data/lib/rvm/functions/logic/or.rb +32 -2
  43. data/lib/rvm/functions/math/add.rb +25 -0
  44. data/lib/rvm/functions/math/cos.rb +39 -0
  45. data/lib/rvm/functions/math/div.rb +25 -0
  46. data/lib/rvm/functions/math/mod.rb +41 -0
  47. data/lib/rvm/functions/math/mul.rb +25 -0
  48. data/lib/rvm/functions/math/neg.rb +25 -0
  49. data/lib/rvm/functions/math/power.rb +25 -0
  50. data/lib/rvm/functions/math/shl.rb +41 -0
  51. data/lib/rvm/functions/math/shr.rb +41 -0
  52. data/lib/rvm/functions/math/sin.rb +39 -0
  53. data/lib/rvm/functions/math/sub.rb +25 -0
  54. data/lib/rvm/functions/math/tan.rb +39 -0
  55. data/lib/rvm/functions/rails/print.rb +33 -3
  56. data/lib/rvm/interpreter.rb +405 -272
  57. data/lib/rvm/languages.rb +45 -11
  58. data/lib/rvm/languages/brainfuck.rb +15 -16
  59. data/lib/rvm/languages/ecma.rb +4 -1257
  60. data/lib/rvm/languages/ecma/compiler.rb +1353 -0
  61. data/lib/rvm/languages/ecma/core-math.js +84 -0
  62. data/lib/rvm/languages/math.rb +9 -16
  63. data/lib/rvm/languages/math/compiler.rb +9 -9
  64. data/lib/rvm/languages/math/tokenizer.rb +1 -1
  65. data/lib/rvm/languages/math/tree.rb +14 -14
  66. data/lib/rvm/library.rb +26 -18
  67. data/lib/rvm/optimisation.rb +109 -0
  68. data/lib/rvm/plugin.rb +109 -45
  69. data/lib/rvm/rails.rb +79 -54
  70. data/spec/classes/atom/association_spec.rb +8 -8
  71. data/spec/classes/atom/block_spec.rb +8 -5
  72. data/spec/classes/atom/boolean_spec.rb +1 -1
  73. data/spec/classes/atom/error_spec.rb +1 -1
  74. data/spec/classes/atom/list_spec.rb +1 -1
  75. data/spec/classes/atom/number_spec.rb +2 -2
  76. data/spec/classes/atom/string_spec.rb +1 -1
  77. data/spec/languages/ecma/ecma_spec.rb +94 -38
  78. data/spec/languages/ecma/json_spec.rb +4 -4
  79. data/spec/languages/math/compiler_spec.rb +5 -5
  80. data/spec/languages/math/tokenizer_spec.rb +1 -1
  81. data/spec/languages/math/tree_spec.rb +1 -1
  82. data/spec/{base → rvm}/class_spec.rb +2 -2
  83. data/spec/{base/interpreter → rvm}/enviroment_spec.rb +19 -9
  84. data/spec/{base → rvm}/function_spec.rb +2 -2
  85. data/spec/{functions → rvm/functions}/association/assoc_get_spec.rb +2 -2
  86. data/spec/{functions → rvm/functions}/association/assoc_set_spec.rb +2 -2
  87. data/spec/rvm/functions/collection/get_spec.rb +12 -0
  88. data/spec/rvm/functions/collection/set_spec.rb +10 -0
  89. data/spec/rvm/functions/collection/size_spec.rb +10 -0
  90. data/spec/{functions → rvm/functions}/list/split_spec.rb +3 -3
  91. data/spec/{functions → rvm/functions}/string/ansi_spec.rb +3 -3
  92. data/spec/{functions → rvm/functions}/string/capstr_spec.rb +3 -3
  93. data/spec/{functions → rvm/functions}/string/center_spec.rb +3 -3
  94. data/spec/{functions → rvm/functions}/string/ljust_spec.rb +3 -3
  95. data/spec/{functions → rvm/functions}/string/regmatch_spec.rb +3 -3
  96. data/spec/{functions → rvm/functions}/string/rjust_spec.rb +3 -3
  97. data/spec/{base → rvm}/interpreter/assignment_spec.rb +1 -1
  98. data/spec/rvm/interpreter/condition_spec.rb +103 -0
  99. data/spec/{base → rvm}/interpreter/constant_spec.rb +1 -1
  100. data/spec/rvm/interpreter/core_call_spec.rb +72 -0
  101. data/spec/{base → rvm}/interpreter/interpreter_spec.rb +1 -1
  102. data/spec/{base → rvm}/interpreter/parameter_spec.rb +1 -1
  103. data/spec/rvm/interpreter/sequence_spec.rb +47 -0
  104. data/spec/{base → rvm}/interpreter/variable_spec.rb +1 -1
  105. data/spec/{base → rvm}/plugin_spec.rb +2 -2
  106. metadata +66 -35
  107. data/lib/rake/helpers/code_statistics.rb +0 -167
  108. data/spec/base/interpreter/condition_spec.rb +0 -47
  109. data/spec/base/interpreter/function_call_spec.rb +0 -72
  110. data/spec/base/interpreter/sequence_spec.rb +0 -20
  111. data/spec/functions/collection/get_spec.rb +0 -12
  112. data/spec/functions/collection/set_spec.rb +0 -10
  113. data/spec/functions/collection/size_spec.rb +0 -10
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) +'/../../../lib/rvm'
2
- require File.dirname(__FILE__) +'/../../../lib/rvm/languages'
3
- require File.dirname(__FILE__) +'/../../../lib/rvm/languages/ecma'
1
+ require 'rvm'
2
+ require 'rvm/languages'
3
+ require 'rvm/languages/ecma'
4
4
 
5
5
  describe RVM::Languages::ECMA do
6
6
  def exec code
@@ -152,4 +152,4 @@ describe RVM::Languages::ECMA do
152
152
  }.should raise_error
153
153
  end
154
154
  end
155
- end
155
+ end if false
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), '/../../../lib/rvm/interpreter')
2
- require File.join(File.dirname(__FILE__), '/../../../lib/rvm/classes/number')
3
- require File.join(File.dirname(__FILE__), '/../../../lib/rvm/languages/math/compiler')
1
+ require 'rvm/interpreter'
2
+ require 'rvm/classes/number'
3
+ require 'rvm/languages/math/compiler'
4
4
  describe RVM::Languages::Math::Compiler do
5
5
  before do
6
6
  @c = RVM::Languages::Math::Compiler
@@ -20,11 +20,11 @@ describe RVM::Languages::Math::Compiler do
20
20
 
21
21
  it "should compile functions" do
22
22
  @c.compile({:type => :function, :op => "x", :params => []}).should be_instance_of(RVM::Interpreter::FunctionCall);
23
- @c.compile({:type => :function, :op => "-", :params => []}).should be_instance_of(RVM::Interpreter::FunctionCall);
23
+ @c.compile({:type => :function, :op => "-", :params => []}).should be_instance_of(RVM::Interpreter::CoreCall);
24
24
  end
25
25
 
26
26
  it "should compile mathematical ooperators to function calls" do
27
- @c.compile({:type => :op, :op => "+", :left => {:type=>:number, :number=>"5"}, :right => {:type=>:number, :number=>"5"}}).should be_instance_of(RVM::Interpreter::FunctionCall);
27
+ @c.compile({:type => :op, :op => "+", :left => {:type=>:number, :number=>"5"}, :right => {:type=>:number, :number=>"5"}}).should be_instance_of(RVM::Interpreter::CoreCall);
28
28
  end
29
29
 
30
30
  it "should compile = operators to assignments if left side is a ident" do
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '/../../../lib/rvm/languages/math/tokenizer')
1
+ require 'rvm/languages/math/tokenizer'
2
2
  describe RVM::Languages::Math::Tokenizer do
3
3
  before do
4
4
  @t = RVM::Languages::Math::Tokenizer
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '/../../../lib/rvm/languages/math/tree')
1
+ require 'rvm/languages/math/tree'
2
2
  describe RVM::Languages::Math::Tree do
3
3
  before do
4
4
  @t = RVM::Languages::Math::Tree
@@ -1,5 +1,5 @@
1
- require 'lib/rvm/classes'
2
- require File.dirname(__FILE__) + '/helpers/plugin_helper'
1
+ require 'rvm/classes'
2
+ require 'spec/rvm/helpers/plugin_helper'
3
3
  require File.dirname(__FILE__) + '/helpers/class_helper'
4
4
 
5
5
  describe RVM::Classes do
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + '/../../../lib/rvm/interpreter'
1
+ require 'rvm/interpreter'
2
2
 
3
- shared_examples_for "a enviroment" do
3
+ shared_examples_for "a environment" do
4
4
  it "should get the locals" do
5
5
  @env['1'].val.should == 'one'
6
6
  end
@@ -15,15 +15,15 @@ shared_examples_for "a enviroment" do
15
15
  end
16
16
  end
17
17
 
18
- describe RVM::Interpreter::Enviroment do
18
+ describe RVM::Interpreter::Environment do
19
19
  before :each do
20
- @env = RVM::Interpreter::Enviroment.new({:params => [1,2], :locals => {'1' => 'one'}})
20
+ @env = RVM::Interpreter::Environment.new({:params => [1,2], :locals => {'1' => 'one'}})
21
21
  end
22
22
 
23
- it_should_behave_like "a enviroment"
23
+ it_should_behave_like "a environment"
24
24
 
25
25
  it "should autocast locals to variable storages on creation" do
26
- env = RVM::Interpreter::Enviroment.new({:params => [1,2], :locals => {'1' => 'one'}})
26
+ env = RVM::Interpreter::Environment.new({:params => [1,2], :locals => {'1' => 'one'}})
27
27
  env['1'].should be_kind_of(RVM::Interpreter::VariableStorage)
28
28
  end
29
29
 
@@ -32,14 +32,24 @@ describe RVM::Interpreter::Enviroment do
32
32
  @env.param(1).should be(2)
33
33
  end
34
34
 
35
+ it "should have a path" do
36
+ @env.path.should be_kind_of(Array)
37
+ end
38
+
39
+
35
40
  describe "(parented)" do
36
41
  before do
37
42
  @old_env = @env
38
- @env = RVM::Interpreter::Enviroment.new({}, @old_env)
43
+ @env = RVM::Interpreter::Environment.new({}, @old_env)
39
44
  end
40
45
 
41
- it_should_behave_like "a enviroment"
42
-
46
+ it_should_behave_like "a environment"
47
+
48
+ =begin
49
+ it "should have the same path as it's parrent" do
50
+ @env.path.should be(@old_env.path)
51
+ end
52
+ =end
43
53
  it "should apply changes to already set variables to the parent" do
44
54
  @env['1'].val.should == 'one'
45
55
  @env['1'] = 'ONE!'
@@ -1,5 +1,5 @@
1
- require 'lib/rvm/functions'
2
- require File.dirname(__FILE__) + '/helpers/plugin_helper'
1
+ require 'rvm/functions'
2
+ require 'spec/rvm/helpers/plugin_helper'
3
3
  require File.dirname(__FILE__) + '/helpers/function_helper'
4
4
 
5
5
  describe RVM::Functions do
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) +'/../../../lib/rvm/functions'
2
- require File.dirname(__FILE__) +'/../../../lib/rvm/functions/association/assoc_get'
1
+ require 'rvm/functions'
2
+ require 'rvm/functions/association/assoc_get'
3
3
 
4
4
  describe RVM::Functions::AssocGet do
5
5
  before(:each) do
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) +'/../../../lib/rvm/functions'
2
- require File.dirname(__FILE__) +'/../../../lib/rvm/functions/association/assoc_set'
1
+ require 'rvm/functions'
2
+ require 'rvm/functions/association/assoc_set'
3
3
 
4
4
  describe RVM::Functions::AssocSet do
5
5
  before(:each) do
@@ -0,0 +1,12 @@
1
+ require 'rvm/functions'
2
+ require 'rvm/functions/association/assoc_get'
3
+ require 'rvm/functions/array/at'
4
+ require 'rvm/functions/collection/get'
5
+
6
+ describe RVM::Functions::Get do
7
+ before(:each) do
8
+ @env = mock('env mock')
9
+ @function = RVM::Functions[:get]
10
+ end
11
+
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'rvm/functions'
2
+ require 'rvm/functions/collection/set'
3
+
4
+ describe RVM::Functions::Set do
5
+ before(:each) do
6
+ @env = mock('env mock')
7
+ @function = RVM::Functions[:set]
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'rvm/functions'
2
+ require 'rvm/functions/collection/size'
3
+
4
+ describe RVM::Functions::Set do
5
+ before(:each) do
6
+ @env = mock('env mock')
7
+ @function = RVM::Functions[:set]
8
+ end
9
+
10
+ end
@@ -1,6 +1,6 @@
1
- require 'lib/rvm/functions/list/split'
2
- require File.dirname(__FILE__) + '/../../base/helpers/plugin_helper'
3
- require File.dirname(__FILE__) + '/../../base/helpers/function_helper'
1
+ require 'spec/rvm/helpers/plugin_helper'
2
+ require 'spec/rvm/helpers/function_helper'
3
+ require 'rvm/functions/list/split'
4
4
 
5
5
  describe RVM::Functions::Split do
6
6
 
@@ -1,6 +1,6 @@
1
- require 'lib/rvm/functions/string/ansi'
2
- require File.dirname(__FILE__) + '/../../base/helpers/plugin_helper'
3
- require File.dirname(__FILE__) + '/../../base/helpers/function_helper'
1
+ require 'spec/rvm/helpers/plugin_helper'
2
+ require 'spec/rvm/helpers/function_helper'
3
+ require 'rvm/functions/string/ansi'
4
4
 
5
5
 
6
6
  describe RVM::Functions::Ansi do
@@ -1,6 +1,6 @@
1
- require 'lib/rvm/functions/string/capstr'
2
- require File.dirname(__FILE__) + '/../../base/helpers/plugin_helper'
3
- require File.dirname(__FILE__) + '/../../base/helpers/function_helper'
1
+ require 'spec/rvm/helpers/plugin_helper'
2
+ require 'spec/rvm/helpers/function_helper'
3
+ require 'rvm/functions/string/capstr'
4
4
 
5
5
 
6
6
  describe RVM::Functions::Capstr do
@@ -1,6 +1,6 @@
1
- require 'lib/rvm/functions/string/center'
2
- require File.dirname(__FILE__) + '/../../base/helpers/plugin_helper'
3
- require File.dirname(__FILE__) + '/../../base/helpers/function_helper'
1
+ require 'spec/rvm/helpers/plugin_helper'
2
+ require 'spec/rvm/helpers/function_helper'
3
+ require 'rvm/functions/string/center'
4
4
 
5
5
 
6
6
  describe RVM::Functions::Center do
@@ -1,6 +1,6 @@
1
- require 'lib/rvm/functions/string/ljust'
2
- require File.dirname(__FILE__) + '/../../base/helpers/plugin_helper'
3
- require File.dirname(__FILE__) + '/../../base/helpers/function_helper'
1
+ require 'spec/rvm/helpers/plugin_helper'
2
+ require 'spec/rvm/helpers/function_helper'
3
+ require 'rvm/functions/string/ljust'
4
4
 
5
5
 
6
6
  describe RVM::Functions::Ljust do
@@ -1,6 +1,6 @@
1
- require 'lib/rvm/functions/string/regmatch'
2
- require File.dirname(__FILE__) + '/../../base/helpers/plugin_helper'
3
- require File.dirname(__FILE__) + '/../../base/helpers/function_helper'
1
+ require File.dirname(__FILE__) + '/../../helpers/plugin_helper'
2
+ require File.dirname(__FILE__) + '/../../helpers/function_helper'
3
+ require 'rvm/functions/string/regmatch'
4
4
 
5
5
 
6
6
  describe RVM::Functions::Regmatch do
@@ -1,6 +1,6 @@
1
- require 'lib/rvm/functions/string/rjust'
2
- require File.dirname(__FILE__) + '/../../base/helpers/plugin_helper'
3
- require File.dirname(__FILE__) + '/../../base/helpers/function_helper'
1
+ require 'spec/rvm/helpers/plugin_helper'
2
+ require 'spec/rvm/helpers/function_helper'
3
+ require 'rvm/functions/string/rjust'
4
4
 
5
5
 
6
6
  describe RVM::Functions::Rjust do
@@ -1,4 +1,4 @@
1
- require 'lib/rvm/interpreter'
1
+ require 'rvm/interpreter'
2
2
 
3
3
  describe RVM::Interpreter::Assignment do
4
4
  before do
@@ -0,0 +1,103 @@
1
+ require 'rvm/interpreter'
2
+
3
+ describe RVM::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 = RVM::Interpreter.env
9
+ @object = RVM::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 = RVM::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 = RVM::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
@@ -1,4 +1,4 @@
1
- require 'lib/rvm/interpreter'
1
+ require 'rvm/interpreter'
2
2
 
3
3
  describe RVM::Interpreter::Constant do
4
4
  before do
@@ -0,0 +1,72 @@
1
+ require 'rvm/interpreter'
2
+ require 'rvm/classes/block'
3
+
4
+ class CoreMock < RVM::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 RVM::Interpreter::CoreCall
23
+ def fun
24
+ @fun
25
+ end
26
+
27
+ def fun= f
28
+ @fun = f
29
+ end
30
+ end
31
+
32
+ describe RVM::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 = RVM::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 = RVM::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 = RVM::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 = RVM::Interpreter::CoreCall.new(:mock, [@param1,@param2])
69
+ @object.==(@object).should be_true
70
+ end
71
+ end
72
+ end