Skip to content

Commit 8162502

Browse files
committed
start adding tests for module support
1 parent 9ad566e commit 8162502

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

spec/fixtures/module/module.rubex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Foo
2+
class Bar
3+
def initialize
4+
end
5+
6+
def baz
7+
return "hello world"
8+
end
9+
end
10+
end
11+
12+
module Bar
13+
def self.a
14+
return "a"
15+
end
16+
17+
def b
18+
return "b"
19+
end
20+
end
21+
22+
module Outer
23+
module Inner
24+
def abc
25+
return "abc"
26+
end
27+
end
28+
end

spec/module_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'spec_helper'
2+
3+
describe Rubex do
4+
test_case = "module"
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}.#{os_extension}"
27+
28+
expect(Foo::Bar.new.baz).to eq("hello world")
29+
30+
include Bar
31+
expect(b).to eq("b")
32+
33+
include Outer::Inner
34+
expect(abc).to eq("abc")
35+
end
36+
end
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)