convert to test case

This commit is contained in:
Torsten Ruger 2014-04-27 15:56:22 +03:00
parent d72c9a3bb0
commit 5423bc8f7e
3 changed files with 32 additions and 40 deletions

View File

@ -1,7 +0,0 @@
(puts("Usage: #{} SOURCE"); exit) if ARGV.empty?
require_relative 'helper'
require 'vm/compiler'
Thnad::Compiler.new(ARGV.first).compile

View File

@ -4,7 +4,7 @@ require_relative "helper"
#testing that parsing strings that we know to be correct returns the nodes we expect
# in a way the combination of test_parser and test_transform
class NodesCase < MiniTest::Test
class TestNodes < MiniTest::Test
def setup
@parser = Parser::Parser.new

View File

@ -1,69 +1,68 @@
require_relative 'helper'
require 'minitest/spec'
include Vm
class ParserTest < MiniTest::Test
describe Parser do
before do
def setup
@parser = Parser::Parser.new
end
it 'reads a number' do
input = '42 '
expected = {:number => '42'}
@parser.number.parse(input).must_equal expected
def check
is = @parser.parse(@@input)
assert is
assert_equal @expected , is
end
def test_number
@input = '42 '
@expected = {:number => '42'}
@parser = @parser.number
end
it 'reads a name' do
input = 'foo '
expected = {:name => 'foo'}
@parser.name.parse(input).must_equal expected
def test_name
@input = 'foo '
@expected = {:name => 'foo'}
@parser = @parser.name
end
it 'reads an argument list' do
input = '(42, foo)'
expected = {:args => [{:arg => {:number => '42'}},
def test_argument_list
@input = '(42, foo)'
@expected = {:args => [{:arg => {:number => '42'}},
{:arg => {:name => 'foo'}}]}
@parser.args.parse(input).must_equal expected
@parser = @parser.args
end
it 'reads a function call' do
input = 'baz(42, foo)'
expected = {:funcall => {:name => 'baz' },
def test_function_call
@input = 'baz(42, foo)'
@expected = {:funcall => {:name => 'baz' },
:args => [{:arg => {:number => '42'}},
{:arg => {:name => 'foo'}}]}
@parser.funcall.parse(input).must_equal expected
@parser = @parser.funcall
end
it 'reads a conditional' do
input = <<HERE
def test_conditional
@input = <<HERE
if (0) {
42
} else {
667
}
HERE
expected = {:cond => {:number => '0'},
@expected = {:cond => {:number => '0'},
:if_true => {:body => {:number => '42'}},
:if_false => {:body => {:number => '667'}}}
@parser.cond.parse(input).must_equal expected
@parser = @parser.cond
end
it 'reads a function definition' do
input = <<HERE
def test_function_definition
@input = <<HERE
function foo(x) {
5
}
HERE
expected = {:func => {:name => 'foo'},
@expected = {:func => {:name => 'foo'},
:params => {:param => {:name => 'x'}},
:body => {:number => '5'}}
@parser.func.parse(input).must_equal expected
@parser = @parser.func
end
end