rubex 0.0.1 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +14 -0
- data/CONTRIBUTING.md +101 -0
- data/HISTORY.md +3 -0
- data/README.md +112 -297
- data/REFERENCE.md +753 -0
- data/Rakefile +4 -1
- data/TUTORIAL.md +234 -0
- data/bin/rubex +1 -1
- data/docs/_config.yml +1 -0
- data/docs/index.html +1 -0
- data/examples/c_struct_interface/c_struct_interface.rb +6 -0
- data/examples/c_struct_interface/c_struct_interface.rubex +47 -0
- data/examples/linked_list/linked_list.rubex +39 -0
- data/examples/linked_list/rb_linked_list.rb +8 -0
- data/examples/rcsv wrapper/rcsv/README.md +1 -0
- data/examples/rcsv wrapper/rcsv/Rakefile +7 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/extconf.rb +3 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/rcsv.c +302 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/rcsv.rubex +124 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv.rb +8 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv.so +0 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv/version.rb +1 -0
- data/examples/rcsv wrapper/rcsv/rcsv.gemspec +27 -0
- data/examples/rcsv wrapper/rcsv/spec/rcsv.csv +5 -0
- data/examples/rcsv wrapper/rcsv/spec/rcsv_spec.rb +17 -0
- data/examples/rcsv wrapper/rcsv/spec/spec_helper.rb +6 -0
- data/{spec/fixtures/basic_ruby_method/Makefile → examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/Makefile } +20 -20
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/rcsv.o +0 -0
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/rcsv.so +0 -0
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/stage/lib/rcsv.so +0 -0
- data/lib/rubex.rb +6 -50
- data/lib/rubex/ast.rb +1 -3
- data/lib/rubex/ast/expression.rb +1257 -8
- data/lib/rubex/ast/node.rb +226 -28
- data/lib/rubex/ast/statement.rb +1162 -35
- data/lib/rubex/ast/top_statement.rb +815 -0
- data/lib/rubex/code_writer.rb +103 -26
- data/lib/rubex/compiler.rb +72 -0
- data/lib/rubex/compiler_config.rb +19 -0
- data/lib/rubex/constants.rb +145 -8
- data/lib/rubex/data_type.rb +667 -4
- data/lib/rubex/error.rb +15 -0
- data/lib/rubex/helpers.rb +154 -0
- data/lib/rubex/lexer.rex +186 -22
- data/lib/rubex/lexer.rex.rb +261 -35
- data/lib/rubex/parser.racc +876 -28
- data/lib/rubex/parser.racc.rb +2845 -90
- data/lib/rubex/rake_task.rb +34 -0
- data/lib/rubex/symbol_table/entry.rb +17 -3
- data/lib/rubex/symbol_table/scope.rb +298 -25
- data/lib/rubex/version.rb +1 -1
- data/rubex.gemspec +11 -3
- data/spec/basic_ruby_method_spec.rb +15 -21
- data/spec/binding_ptr_args_spec.rb +33 -0
- data/spec/bitwise_operators_spec.rb +40 -0
- data/spec/blocks_spec.rb +35 -0
- data/spec/c_bindings_spec.rb +36 -0
- data/spec/c_constants_spec.rb +33 -0
- data/spec/c_function_ptrs_spec.rb +38 -0
- data/spec/c_functions_spec.rb +35 -0
- data/spec/c_struct_interface_spec.rb +38 -0
- data/spec/call_by_reference_spec.rb +33 -0
- data/spec/class_methods_spec.rb +33 -0
- data/spec/class_spec.rb +40 -0
- data/spec/comments_spec.rb +33 -0
- data/spec/default_args_spec.rb +37 -0
- data/spec/error_handling_spec.rb +42 -0
- data/spec/examples_spec.rb +52 -0
- data/spec/expressions_spec.rb +33 -0
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.rubex +2 -0
- data/spec/fixtures/binding_ptr_args/binding_ptr_args.rubex +30 -0
- data/spec/fixtures/bitwise_operators/bitwise_operators.rubex +40 -0
- data/spec/fixtures/blocks/blocks.rubex +11 -0
- data/spec/fixtures/c_bindings/c_bindings.rubex +58 -0
- data/spec/fixtures/c_constants/c_constants.rubex +7 -0
- data/spec/fixtures/c_function_ptrs/c_function_ptrs.rubex +52 -0
- data/spec/fixtures/c_functions/c_functions.rubex +25 -0
- data/spec/fixtures/c_struct_interface/c_struct_interface.rubex +34 -0
- data/spec/fixtures/call_by_reference/call_by_reference.rubex +30 -0
- data/spec/fixtures/class/class.rubex +20 -0
- data/spec/fixtures/class_methods/class_methods.rubex +12 -0
- data/spec/fixtures/comments/comments.rubex +9 -0
- data/spec/fixtures/default_args/default_args.rubex +11 -0
- data/spec/fixtures/error_handling/error_handling.rubex +54 -0
- data/spec/fixtures/examples/array_to_hash.rubex +14 -0
- data/spec/fixtures/examples/rcsv.csv +5 -0
- data/spec/fixtures/examples/rcsv.rubex +329 -0
- data/spec/fixtures/expressions/expressions.rubex +10 -0
- data/spec/fixtures/if_else/if_else.rubex +77 -0
- data/spec/fixtures/implicit_lib_include/implicit_lib_include.rubex +15 -0
- data/spec/fixtures/init_ruby_objects_with_literal_syntax/init_ruby_objects_with_literal_syntax.rubex +17 -0
- data/spec/fixtures/loops/loops.rubex +33 -0
- data/spec/fixtures/recursion/recursion.rubex +9 -0
- data/spec/fixtures/ruby_constant_method_calls/ruby_constant_method_calls.rubex +17 -0
- data/spec/fixtures/ruby_operators/ruby_operators.rubex +29 -0
- data/spec/fixtures/ruby_raise/ruby_raise.rubex +13 -0
- data/spec/fixtures/ruby_strings/ruby_strings.rubex +19 -0
- data/spec/fixtures/ruby_strings/string_blank_bm.rb +37 -0
- data/spec/fixtures/ruby_symbols/ruby_symbols.rubex +12 -0
- data/spec/fixtures/ruby_types/ruby_types.rubex +15 -0
- data/spec/fixtures/statement_expression/statement_expression.rubex +23 -0
- data/spec/fixtures/static_array/static_array.rubex +20 -0
- data/spec/fixtures/string_literals/string_literals.rubex +15 -0
- data/spec/fixtures/struct/struct.rubex +82 -0
- data/spec/fixtures/typecasting/typecasting.rubex +23 -0
- data/spec/fixtures/var_declarations/var_declarations.rubex +39 -0
- data/spec/if_else_spec.rb +39 -0
- data/spec/implicit_lib_include_spec.rb +33 -0
- data/spec/init_ruby_objects_with_literal_syntax_spec.rb +39 -0
- data/spec/loops_spec.rb +34 -0
- data/spec/recursion_spec.rb +35 -0
- data/spec/ruby_constant_method_calls_spec.rb +35 -0
- data/spec/ruby_operators_spec.rb +40 -0
- data/spec/ruby_raise_spec.rb +35 -0
- data/spec/ruby_strings_spec.rb +33 -0
- data/spec/ruby_symbols_spec.rb +37 -0
- data/spec/ruby_types_spec.rb +35 -0
- data/spec/spec_helper.rb +54 -1
- data/spec/statement_expression_spec.rb +34 -0
- data/spec/static_array_spec.rb +33 -0
- data/spec/string_literals_spec.rb +34 -0
- data/spec/struct_spec.rb +36 -0
- data/spec/typecasting_spec.rb +38 -0
- data/spec/var_declarions_spec.rb +35 -0
- metadata +255 -29
- data/lib/rubex/ast/argument_list.rb +0 -20
- data/lib/rubex/ast/c_base_type.rb +0 -11
- data/lib/rubex/ast/ruby_method_def.rb +0 -84
- data/spec/fixtures/basic_ruby_method/basic.rb +0 -3
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.c +0 -16
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.o +0 -0
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.so +0 -0
- data/spec/fixtures/basic_ruby_method/extconf.rb +0 -3
@@ -1,40 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
include Rubex::AST
|
2
3
|
|
3
4
|
describe Rubex do
|
4
|
-
|
5
|
+
test_case = 'basic_ruby_method'
|
6
|
+
|
7
|
+
context "Case : #{test_case}" do
|
5
8
|
before do
|
6
|
-
@path =
|
7
|
-
include Rubex::AST
|
9
|
+
@path = path_str test_case
|
8
10
|
end
|
9
11
|
|
10
12
|
context ".ast" do
|
11
13
|
it "returns a valid Abstract Syntax Tree" do
|
12
|
-
|
13
|
-
arguments.push CBaseType.new('i32', 'b')
|
14
|
-
arguments.push CBaseType.new('i32', 'a')
|
15
|
-
method = RubyMethodDef.new('addition', arguments)
|
16
|
-
expr = Expression::Addition.new 'a', 'b'
|
17
|
-
statements = Statement::Return.new expr
|
18
|
-
node = Node.new method
|
19
|
-
|
20
|
-
# TODO: Define == method on all nodes of AST.
|
21
|
-
# expect(Rubex.ast(@path)).to eq(node)
|
14
|
+
t = Rubex::Compiler.ast @path + ".rubex"
|
22
15
|
end
|
23
16
|
end
|
24
17
|
|
25
18
|
context ".compile" do
|
26
19
|
it "generates valid C code" do
|
27
|
-
Rubex.compile @path, true
|
20
|
+
t, c, e = Rubex::Compiler.compile @path + ".rubex", test: true
|
28
21
|
end
|
29
22
|
end
|
30
23
|
|
31
|
-
context "
|
32
|
-
it "
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
24
|
+
context "Black Box testing" do
|
25
|
+
it "compiles and checks for valid output" do
|
26
|
+
setup_and_teardown_compiled_files(test_case) do
|
27
|
+
dir = dir_str test_case
|
28
|
+
require_relative "#{dir}/#{test_case}.so"
|
29
|
+
expect(addition(4,5)).to eq(9)
|
30
|
+
end
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
40
|
-
end
|
34
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = "binding_ptr_args"
|
5
|
+
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
10
|
+
|
11
|
+
context ".ast" do
|
12
|
+
it "generates the AST." do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile" do
|
18
|
+
it "compiles to C." do
|
19
|
+
t, c, e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Black Box testing" do
|
24
|
+
it "compiles and checks for valid output" do
|
25
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
26
|
+
require_relative "#{dir}/#{test_case}.so"
|
27
|
+
|
28
|
+
expect(test_function("hello")).to eq(104)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rubex::AST
|
3
|
+
|
4
|
+
describe Rubex do
|
5
|
+
test_case = 'bitwise_operators'
|
6
|
+
|
7
|
+
context "Case : #{test_case}" do
|
8
|
+
before do
|
9
|
+
@path = path_str test_case
|
10
|
+
end
|
11
|
+
|
12
|
+
context ".ast" do
|
13
|
+
it "returns a valid Abstract Syntax Tree" do
|
14
|
+
t = Rubex::Compiler.ast @path + ".rubex"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context ".compile" do
|
19
|
+
it "generates valid C code" do
|
20
|
+
t, c, e = Rubex::Compiler.compile @path + ".rubex", test: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Black Box testing" do
|
25
|
+
it "compiles and checks for valid output" do
|
26
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
27
|
+
require_relative "#{dir}/#{test_case}.so"
|
28
|
+
|
29
|
+
cls = BitWise.new
|
30
|
+
expect(cls.wise_or).to eq(3)
|
31
|
+
expect(cls.wise_and).to eq(1)
|
32
|
+
expect(cls.wise_compli).to eq(-5)
|
33
|
+
expect(cls.wise_xor).to eq(0)
|
34
|
+
expect(cls.wise_lshift).to eq(6)
|
35
|
+
expect(cls.wise_rshift).to eq(2)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/blocks_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = 'blocks'
|
5
|
+
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
10
|
+
|
11
|
+
context ".ast" do
|
12
|
+
it "generates the AST" do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile", focus: true do
|
18
|
+
it "compiles to valid C file" do
|
19
|
+
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Black Box testing", focus: true do
|
24
|
+
it "compiles and checks for valid output" do
|
25
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
26
|
+
require_relative "#{dir}/#{test_case}.so"
|
27
|
+
|
28
|
+
block_scene do |num|
|
29
|
+
expect([1,2,3,4,5,6].include?(num)).to eq(true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = "c_bindings"
|
5
|
+
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
10
|
+
|
11
|
+
context ".ast" do
|
12
|
+
it "generates the AST" do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile" do
|
18
|
+
it "compiles to valid C file" do
|
19
|
+
t,c,e = Rubex::Compiler.compile((@path + '.rubex'), test: true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Black Box testing" do
|
24
|
+
it "compiles and checks for valid output" do
|
25
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
26
|
+
require_relative "#{dir}/#{test_case}.so"
|
27
|
+
|
28
|
+
expect(maths(3,5,"hello")).to be_within(0.001).of(300.763)
|
29
|
+
expect(stray_cos).to be_within(0.001).of(-0.210)
|
30
|
+
expect(A.new.ruby_cos).to be_within(0.001).of(-0.210)
|
31
|
+
expect(RMath.new.ruby_sin(90)).to be_within(0.001).of(0.893)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = "c_constants"
|
5
|
+
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
10
|
+
|
11
|
+
context ".ast" do
|
12
|
+
it "generates a valid AST" do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile", focus: true do
|
18
|
+
it "compiles to valid C code" do
|
19
|
+
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Black Box testing", focus: true do
|
24
|
+
it "compiles and checks for valid output" do
|
25
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
26
|
+
require_relative "#{dir}/#{test_case}.so"
|
27
|
+
|
28
|
+
expect(have_ruby_h).to eq(1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rubex::AST
|
3
|
+
|
4
|
+
describe Rubex do
|
5
|
+
test_case = 'c_function_ptrs'
|
6
|
+
|
7
|
+
context "Case : #{test_case}" do
|
8
|
+
before do
|
9
|
+
@path = path_str test_case
|
10
|
+
end
|
11
|
+
|
12
|
+
context ".ast" do
|
13
|
+
it "returns a valid Abstract Syntax Tree" do
|
14
|
+
t = Rubex::Compiler.ast @path + ".rubex"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context ".compile", focus: true do
|
19
|
+
it "generates valid C code" do
|
20
|
+
t, c, e = Rubex::Compiler.compile @path + ".rubex", test: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Black Box testing", focus: true do
|
25
|
+
it "compiles and checks for valid output" do
|
26
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
27
|
+
require_relative "#{dir}/#{test_case}.so"
|
28
|
+
|
29
|
+
cls = CFunctionPtrs.new
|
30
|
+
|
31
|
+
expect(cls.test_c_function_pointers(true)) .to eq(5)
|
32
|
+
expect(cls.test_c_function_pointers(false)).to eq(7)
|
33
|
+
expect(cls.test_pass_by_name).to eq(17)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = 'c_functions'
|
5
|
+
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
10
|
+
|
11
|
+
context ".ast" do
|
12
|
+
it "generates the AST" do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile" do
|
18
|
+
it "compiles to valid C file" do
|
19
|
+
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Black Box testing" do
|
24
|
+
it "compiles and checks for valid output" do
|
25
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
26
|
+
require_relative "#{dir}/#{test_case}.so"
|
27
|
+
|
28
|
+
c = CFunctions.new
|
29
|
+
expect(c.pure_ruby_method).to eq(50)
|
30
|
+
expect { c.first_c_function(1,2) }.to raise_error(NoMethodError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rubex::AST
|
3
|
+
|
4
|
+
describe Rubex do
|
5
|
+
test_case = 'c_struct_interface'
|
6
|
+
|
7
|
+
context "Case : #{test_case}" do
|
8
|
+
before do
|
9
|
+
@path = path_str test_case
|
10
|
+
end
|
11
|
+
|
12
|
+
context ".ast" do
|
13
|
+
it "returns a valid Abstract Syntax Tree" do
|
14
|
+
t = Rubex::Compiler.ast @path + ".rubex"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context ".compile", focus: true do
|
19
|
+
it "generates valid C code" do
|
20
|
+
t, c, e = Rubex::Compiler.compile @path + ".rubex", test: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Black Box testing", focus: true do
|
25
|
+
it "compiles and checks for valid output" do
|
26
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
27
|
+
require_relative "#{dir}/#{test_case}.so"
|
28
|
+
id = 44
|
29
|
+
m = Music.new("Animals as Leaders", "CAFO", id)
|
30
|
+
|
31
|
+
expect(m.artist).to eq("Animals as Leaders")
|
32
|
+
expect(m.title) .to eq("CAFO")
|
33
|
+
expect(m.id) .to eq(id)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = 'call_by_reference'
|
5
|
+
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
10
|
+
|
11
|
+
context ".ast" do
|
12
|
+
it "generates the AST" do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile" do
|
18
|
+
it "compiles to valid C file" do
|
19
|
+
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Black Box testing" do
|
24
|
+
it "compiles and checks for valid output" do
|
25
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
26
|
+
require_relative "#{dir}/#{test_case}.so"
|
27
|
+
|
28
|
+
expect(CallByReference.new.ref_call).to eq(4)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = 'class_methods'
|
5
|
+
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
10
|
+
|
11
|
+
context ".ast" do
|
12
|
+
it "generates the AST" do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile" do
|
18
|
+
it "compiles to valid C file" do
|
19
|
+
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Black Box testing" do
|
24
|
+
it "compiles and checks for valid output" do
|
25
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
26
|
+
require_relative "#{dir}/#{test_case}.so"
|
27
|
+
|
28
|
+
expect(Bhau.say_what("hello there!")).to eq(10)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/class_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = 'class'
|
5
|
+
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
10
|
+
|
11
|
+
context ".ast" do
|
12
|
+
it "generates the AST" do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile", focus: true do
|
18
|
+
it "compiles to valid C file" do
|
19
|
+
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Black Box testing", focus: true do
|
24
|
+
it "compiles and checks for valid output" do
|
25
|
+
setup_and_teardown_compiled_files(test_case) do |dir|
|
26
|
+
require_relative "#{dir}/#{test_case}.so"
|
27
|
+
|
28
|
+
k = Kustom.new
|
29
|
+
expect(k.bye).to eq("Bye world!")
|
30
|
+
|
31
|
+
k2 = Kustom2.new
|
32
|
+
expect(k2.hello).to eq("This is a prelude.Hello world!")
|
33
|
+
|
34
|
+
expect(Kustom2.ancestors[1]).to eq(Kustom)
|
35
|
+
expect(RandomRubyError.ancestors[1]).to eq(StandardError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|