rVM 0.0.10 → 0.0.11
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/lib/rake/helpers/code_statistics.rb +167 -0
- data/lib/rvm/classes.rb +4 -0
- data/lib/rvm/classes/string.rb +1 -0
- data/lib/rvm/functions/array.rb +3 -0
- data/lib/rvm/functions/array/set_at.rb +0 -4
- data/lib/rvm/functions/collection/size.rb +2 -2
- data/lib/rvm/functions/logic/and.rb +1 -1
- data/lib/rvm/functions/logic/or.rb +2 -2
- data/lib/rvm/interpreter.rb +84 -44
- data/lib/rvm/languages/ecma.rb +581 -501
- data/spec/base/class_spec.rb +27 -0
- data/spec/base/function_spec.rb +25 -0
- data/spec/base/interpreter/assignment_spec.rb +22 -0
- data/spec/base/interpreter/condition_spec.rb +47 -0
- data/spec/base/interpreter/constant_spec.rb +31 -0
- data/spec/base/interpreter/enviroment_spec.rb +51 -0
- data/spec/base/interpreter/function_call_spec.rb +72 -0
- data/spec/base/interpreter/interpreter_spec.rb +11 -0
- data/spec/base/interpreter/parameter_spec.rb +24 -0
- data/spec/base/interpreter/sequence_spec.rb +20 -0
- data/spec/base/interpreter/variable_spec.rb +24 -0
- data/spec/base/plugin_spec.rb +10 -0
- data/spec/classes/atom/association_spec.rb +39 -0
- data/spec/classes/atom/block_spec.rb +27 -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/functions/association/assoc_get_spec.rb +41 -0
- data/spec/functions/association/assoc_set_spec.rb +43 -0
- data/spec/functions/collection/get_spec.rb +12 -0
- data/spec/functions/collection/set_spec.rb +10 -0
- data/spec/functions/collection/size_spec.rb +10 -0
- data/spec/functions/list/split_spec.rb +47 -0
- data/spec/functions/string/ansi_spec.rb +44 -0
- data/spec/functions/string/capstr_spec.rb +42 -0
- data/spec/functions/string/center_spec.rb +49 -0
- data/spec/functions/string/ljust_spec.rb +49 -0
- data/spec/functions/string/regmatch_spec.rb +52 -0
- data/spec/functions/string/rjust_spec.rb +49 -0
- data/spec/languages/ecma_spec.rb +337 -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 +42 -5
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) +'/../../../lib/rvm/functions'
|
2
|
+
require File.dirname(__FILE__) +'/../../../lib/rvm/functions/association/assoc_get'
|
3
|
+
|
4
|
+
describe RVM::Functions::AssocGet do
|
5
|
+
before(:each) do
|
6
|
+
@env = mock('env mock')
|
7
|
+
@function = RVM::Functions[:assoc_get]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should accept a usual function call with 2 parameters and get the value" do
|
11
|
+
params = [
|
12
|
+
p1 = mock('param 1 mock'),
|
13
|
+
p2 = mock('param 2 mock')
|
14
|
+
]
|
15
|
+
res = p1.should_receive(:[]).with(p2).and_return('result')
|
16
|
+
@function.execute(params, @env).should == 'result'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should accept a object call wiht 1 parameter and a object in env and get the value" do
|
20
|
+
params = [
|
21
|
+
p1 = mock('param 1 mock')
|
22
|
+
]
|
23
|
+
obj = mock('association mock')
|
24
|
+
@env.should_receive(:read_var_val).once.with(:self).and_return(obj)
|
25
|
+
obj.should_receive(:is_a?).once.with(RVM::Classes::Association).and_return(true)
|
26
|
+
res = obj.should_receive(:[]).with(p1).and_return('result')
|
27
|
+
@function.execute(params, @env).should == 'result'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return an error with more then 2 arguments" do
|
31
|
+
params = [1,2,3]
|
32
|
+
@function.execute(params, @env).should be_an_instance_of(RVM::Classes::Error)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
it "should return an error with no arguments" do
|
37
|
+
params = []
|
38
|
+
@function.execute(params, @env).should be_an_instance_of(RVM::Classes::Error)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) +'/../../../lib/rvm/functions'
|
2
|
+
require File.dirname(__FILE__) +'/../../../lib/rvm/functions/association/assoc_set'
|
3
|
+
|
4
|
+
describe RVM::Functions::AssocSet do
|
5
|
+
before(:each) do
|
6
|
+
@env = mock('env mock')
|
7
|
+
@function = RVM::Functions[:assoc_set]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should accept a usual function call with 3 parameters and return the value it sets" do
|
11
|
+
params = [
|
12
|
+
p1 = mock('param 1 mock'),
|
13
|
+
p2 = mock('param 2 mock'),
|
14
|
+
p3 = mock('param 3 mock')
|
15
|
+
]
|
16
|
+
p1.should_receive(:[]=).with(p2, p3).and_return(p3)
|
17
|
+
@function.execute(params, @env).should == p3
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should accept a object call wiht 2 parameter and a object in env and return the value it sets" do
|
21
|
+
params = [
|
22
|
+
p1 = mock('param 1 mock'),
|
23
|
+
p2 = mock('param 2 mock')
|
24
|
+
]
|
25
|
+
obj = mock('association mock')
|
26
|
+
@env.should_receive(:read_var_val).once.with(:self).and_return(obj)
|
27
|
+
obj.should_receive(:is_a?).once.with(RVM::Classes::Association).and_return(true)
|
28
|
+
res = obj.should_receive(:[]=).with(p1,p2).and_return(p2)
|
29
|
+
@function.execute(params, @env).should == p2
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return an error with more then 4 arguments" do
|
33
|
+
params = [1, 2, 3, 4]
|
34
|
+
@function.execute(params, @env).should be_an_instance_of(RVM::Classes::Error)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
it "should return an error with less then 2 arguments" do
|
39
|
+
params = [1]
|
40
|
+
@function.execute(params, @env).should be_an_instance_of(RVM::Classes::Error)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) +'/../../../lib/rvm/functions'
|
2
|
+
require File.dirname(__FILE__) +'/../../../lib/rvm/functions/association/assoc_get'
|
3
|
+
require File.dirname(__FILE__) +'/../../../lib/rvm/functions/array/at'
|
4
|
+
require File.dirname(__FILE__) +'/../../../lib/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 File.dirname(__FILE__) +'/../../../lib/rvm/functions'
|
2
|
+
require File.dirname(__FILE__) +'/../../../lib/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 File.dirname(__FILE__) +'/../../../lib/rvm/functions'
|
2
|
+
require File.dirname(__FILE__) +'/../../../lib/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
|
@@ -0,0 +1,47 @@
|
|
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'
|
4
|
+
|
5
|
+
describe RVM::Functions::Split do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@object = RVM::Functions::Split
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "(plugin)" do
|
12
|
+
it_should_behave_like "a plugin"
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "(function)" do
|
16
|
+
it_should_behave_like "a function"
|
17
|
+
|
18
|
+
it "should have a signature of string, string" do
|
19
|
+
@object.signature.should == [:string, :string]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have a type of :list" do
|
23
|
+
@object.data_type.should == :list
|
24
|
+
end
|
25
|
+
end
|
26
|
+
describe "(functionality)" do
|
27
|
+
before do
|
28
|
+
@env = mock('env mock')
|
29
|
+
@old_db = $DB
|
30
|
+
$DB = mock('db mock')
|
31
|
+
end
|
32
|
+
|
33
|
+
after do
|
34
|
+
$DB = @old_db
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have tests implemented" do
|
38
|
+
pending "This needs to be implemented, locate functions neeeeeeeds specs."
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not work with more then 3 and less the 2 params" do
|
42
|
+
@object.execute([1], nil).should be_instance_of(RVM::Classes::Error)
|
43
|
+
@object.execute([1,2,3,1], nil).should be_instance_of(RVM::Classes::Error)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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'
|
4
|
+
|
5
|
+
|
6
|
+
describe RVM::Functions::Ansi do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@object = RVM::Functions::Ansi
|
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 == [:string, :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" do
|
31
|
+
@object.execute([], nil).should be_instance_of(RVM::Classes::Error)
|
32
|
+
@object.execute([1], nil).should be_instance_of(RVM::Classes::Error)
|
33
|
+
@object.execute([1,2,3], nil).should be_instance_of(RVM::Classes::Error)
|
34
|
+
@object.execute([1,2,3,4], nil).should be_instance_of(RVM::Classes::Error)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should call the ansi function for the seclond with the first argument as parameter" do
|
38
|
+
arg1 = mock('arg mock')
|
39
|
+
arg1.should_receive(:ansi).once.with(1).and_return 'one'
|
40
|
+
@object.execute([1,arg1], nil).should == 'one'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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'
|
4
|
+
|
5
|
+
|
6
|
+
describe RVM::Functions::Capstr do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@object = RVM::Functions::Capstr
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
describe "(plugin)" do
|
14
|
+
it_should_behave_like "a plugin"
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "(function)" do
|
19
|
+
it_should_behave_like "a function"
|
20
|
+
|
21
|
+
it "should have a signature of string" do
|
22
|
+
@object.signature.should == [:string]
|
23
|
+
end
|
24
|
+
it "should have a type of boolean" do
|
25
|
+
@object.data_type.should == :string
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "(functionality)" do
|
30
|
+
|
31
|
+
it "should not work with more or less then 1 param" do
|
32
|
+
@object.execute([], nil).should be_instance_of(RVM::Classes::Error)
|
33
|
+
@object.execute([1,2], nil).should be_instance_of(RVM::Classes::Error)
|
34
|
+
@object.execute([1,2,3], nil).should be_instance_of(RVM::Classes::Error)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should capitalize the first letter" do
|
38
|
+
@object.execute(["abc"], nil).should == 'Abc'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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'
|
4
|
+
|
5
|
+
|
6
|
+
describe RVM::Functions::Center do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@object = RVM::Functions::Center
|
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 == [:string, :number, :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(RVM::Classes::Error)
|
32
|
+
@object.execute([1], nil).should be_instance_of(RVM::Classes::Error)
|
33
|
+
@object.execute([1,2,3,4], nil).should be_instance_of(RVM::Classes::Error)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should call the center function with one param if it is given" do
|
37
|
+
arg1 = mock('arg mock')
|
38
|
+
arg1.should_receive(:center).once.with(1).and_return 'center'
|
39
|
+
@object.execute([arg1,1], nil).should == 'center'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should call the center function with one two param if they are given" do
|
43
|
+
arg1 = mock('arg mock')
|
44
|
+
arg1.should_receive(:center).once.with(1,2).and_return 'center2'
|
45
|
+
@object.execute([arg1,1,2], nil).should == 'center2'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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'
|
4
|
+
|
5
|
+
|
6
|
+
describe RVM::Functions::Ljust do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@object = RVM::Functions::Ljust
|
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 == [:string, :number, :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(RVM::Classes::Error)
|
32
|
+
@object.execute([1], nil).should be_instance_of(RVM::Classes::Error)
|
33
|
+
@object.execute([1,2,3,4], nil).should be_instance_of(RVM::Classes::Error)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should call the ljust function with one param if it is given" do
|
37
|
+
arg1 = mock('arg mock')
|
38
|
+
arg1.should_receive(:ljust).once.with(1).and_return 'ljust'
|
39
|
+
@object.execute([arg1,1], nil).should == 'ljust'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should call the ljust function with one two param if they are given" do
|
43
|
+
arg1 = mock('arg mock')
|
44
|
+
arg1.should_receive(:ljust).once.with(1,2).and_return 'ljust'
|
45
|
+
@object.execute([arg1,1,2], nil).should == 'ljust'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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'
|
4
|
+
|
5
|
+
|
6
|
+
describe RVM::Functions::Regmatch do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@object = RVM::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 == [:string, :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(RVM::Classes::Error)
|
32
|
+
@object.execute([1], nil).should be_instance_of(RVM::Classes::Error)
|
33
|
+
@object.execute([1,2,3], nil).should be_instance_of(RVM::Classes::Error)
|
34
|
+
@object.execute([1,2,3,4], nil).should be_instance_of(RVM::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(RVM::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 'lib/rvm/functions/string/rjust'
|
2
|
+
require File.dirname(__FILE__) + '/../../base/helpers/plugin_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../base/helpers/function_helper'
|
4
|
+
|
5
|
+
|
6
|
+
describe RVM::Functions::Rjust do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@object = RVM::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 == [:string, :number, :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(RVM::Classes::Error)
|
32
|
+
@object.execute([1], nil).should be_instance_of(RVM::Classes::Error)
|
33
|
+
@object.execute([1,2,3,4], nil).should be_instance_of(RVM::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
|