add parser and basic test framework

that doesnt actually do anything. but WILL, great things, off course
This commit is contained in:
Torsten Ruger 2015-12-01 11:55:33 +02:00
parent b9d2508370
commit 27a7657842
9 changed files with 192 additions and 0 deletions

View File

@ -28,6 +28,7 @@ PATH
remote: .
specs:
salama (0.5.0)
parser (~> 2.2.0)
salama-object-file (~> 0.3)
soml-parser (~> 0.5)
@ -73,6 +74,8 @@ GEM
notiffany (0.0.8)
nenv (~> 0.1)
shellany (~> 0.0)
parser (2.2.3.0)
ast (>= 1.1, < 3.0)
parslet (1.7.1)
blankslate (>= 2.0, <= 4.0)
pry (0.10.2)

View File

@ -14,5 +14,6 @@ Gem::Specification.new do |s|
s.summary = 'Salama is a native object vm without any c, one day possibly a ruby vm'
s.add_dependency "soml-parser" , "~> 0.5"
s.add_dependency "parser" , "~> 2.2.0"
s.add_dependency "salama-object-file" , "~> 0.3"
end

15
test/melon/helper.rb Normal file
View File

@ -0,0 +1,15 @@
require_relative '../helper'
require "register/interpreter"
require "parser/ruby22"
module MelonTests
def setup
@parser = Parser::Ruby22
end
def check
assert true
puts @parser.parse @string_input
end
end

51
test/melon/test_adds.rb Normal file
View File

@ -0,0 +1,51 @@
require_relative 'helper'
class TestRubyAdds < MiniTest::Test
include MelonTests
def test_ruby_adds
@string_input = <<HERE
def fibo( n)
a = 0
b = 1
i = 1
while( i < n ) do
result = a + b
a = b
b = result
i+= 1
end
return result
end
HERE
@stdout = "Hello there"
check
end
def pest_ruby_adds_looping
@string_input = <<HERE
def fibo( n)
a = 0
b = 1
i = 1
while( i < n ) do
result = a + b
a = b
b = result
i+= 1
end
return result
end
counter = 100000
while(counter > 0) do
fibo(40)
counter -= 1
end
HERE
@length = 37
@stdout = "Hello Raisa, I am salama"
check
end
end

5
test/melon/test_all.rb Normal file
View File

@ -0,0 +1,5 @@
require_relative "test_loop"
require_relative "test_itos"
require_relative "test_calls"
require_relative "test_adds"
require_relative "test_hello"

45
test/melon/test_calls.rb Normal file
View File

@ -0,0 +1,45 @@
require_relative 'helper'
class TestRubyCalls < MiniTest::Test
include MelonTests
def test_ruby_calls
@string_input = <<HERE
def fibo_r( n )
if( n < 2 )
return n
else
return fibo_r(n - 1) + fibo_r(n - 2)
end
end
fibo 40
HERE
@stdout = "Hello there"
check
end
def pest_ruby_calls_looping
@string_input = <<HERE
def fibo_r( n )
if( n < 2 )
return n
else
return fibo_r(n - 1) + fibo_r(n - 2)
end
end
counter = 1000
while(counter > 0) do
fibo_r(20)
counter -= 1
end
HERE
@length = 37
@stdout = ""
check
end
end

27
test/melon/test_hello.rb Normal file
View File

@ -0,0 +1,27 @@
require_relative 'helper'
class TestRubyHello < MiniTest::Test
include MelonTests
def test_ruby_hello
@string_input = <<HERE
puts "Hello there"
HERE
@stdout = "Hello there"
check
end
def pest_ruby_hello_looping
@string_input = <<HERE
counter = 100000;
while(counter > 0) do
puts "Hello there"
STDOUT.flush
counter = counter - 1
end
HERE
@length = 37
@stdout = "Hello Raisa, I am salama"
check
end
end

28
test/melon/test_itos.rb Normal file
View File

@ -0,0 +1,28 @@
require_relative 'helper'
class TestRubyItos < MiniTest::Test
include MelonTests
def test_ruby_itos
@string_input = <<HERE
100000.to_s
HERE
@stdout = "Hello there"
check
end
def pest_ruby_itos_looping
@string_input = <<HERE
counter = 100000
while(counter > 0) do
str = counter.to_s
counter = counter - 1
end
str
HERE
@length = 37
@stdout = "Hello Raisa, I am salama"
check
end
end

17
test/melon/test_loop.rb Normal file
View File

@ -0,0 +1,17 @@
require_relative 'helper'
class TestRubyLoop < MiniTest::Test
include MelonTests
def test_ruby_loop
@string_input = <<HERE
counter = 100000
while(counter > 0) do
counter -= 1
end
HERE
@stdout = "Hello there"
check
end
end