change test framework to use files for in and out (s-exp)

This commit is contained in:
Torsten Ruger 2015-09-18 21:55:02 +03:00
parent 396a843a5e
commit 22e3c59674
80 changed files with 946 additions and 13 deletions

View File

@ -0,0 +1,3 @@
FooBar
-- -- --
s(:list, [s(:module, "FooBar")])

View File

@ -0,0 +1,3 @@
foo
-- -- --
s(:list, [s(:name, "foo")])

View File

@ -0,0 +1,3 @@
foo_bar
-- -- --
s(:list, [s(:name, "foo_bar")])

View File

@ -0,0 +1,3 @@
_bar
-- -- --
s(:list, [s(:name, "_bar")])

View File

@ -0,0 +1,3 @@
42
-- -- --
s(:list, [s(:int, 42)])

View File

@ -0,0 +1,3 @@
"hello"
-- -- --
s(:list, [s(:string, "hello")])

View File

@ -0,0 +1,3 @@
"hello \nyou"
-- -- --
s(:list, [s(:string, "hello \\nyou")])

View File

@ -0,0 +1,7 @@
puts(3 , a )
-- -- --
s(:list, [s(:call,
s(:name, "puts"),
s(:arguments,
s(:int, 3),
s(:name, "a")))])

View File

@ -0,0 +1,7 @@
baz(42, foo)
-- -- --
s(:list, [s(:call,
s(:name, "baz"),
s(:arguments,
s(:int, 42),
s(:name, "foo")))])

View File

@ -0,0 +1,6 @@
puts( "hello")
-- -- --
s(:list, [s(:call,
s(:name, "puts"),
s(:arguments,
s(:string, "hello")))])

View File

@ -0,0 +1,7 @@
42.put()
-- -- --
s(:list, [s(:call,
s(:name, "put"),
s(:arguments),
s(:receiver,
s(:int, 42)))])

View File

@ -0,0 +1,6 @@
puts( 5)
-- -- --
s(:list, [s(:call,
s(:name, "puts"),
s(:arguments,
s(:int, 5)))])

View File

@ -0,0 +1,6 @@
foo(42)
-- -- --
s(:list, [s(:call,
s(:name, "foo"),
s(:arguments,
s(:int, 42)))])

View File

@ -0,0 +1,8 @@
Object.foo(42)
-- -- --
s(:list, [s(:call,
s(:name, "foo"),
s(:arguments,
s(:int, 42)),
s(:receiver,
s(:module, "Object")))])

View File

@ -0,0 +1,8 @@
my_my.foo(42)
-- -- --
s(:list, [s(:call,
s(:name, "foo"),
s(:arguments,
s(:int, 42)),
s(:receiver,
s(:name, "my_my")))])

View File

@ -0,0 +1,8 @@
self.foo(42)
-- -- --
s(:list, [s(:call,
s(:name, "foo"),
s(:arguments,
s(:int, 42)),
s(:receiver,
s(:name, "self")))])

View File

@ -0,0 +1,7 @@
"hello".puts()
-- -- --
s(:list, [s(:call,
s(:name, "puts"),
s(:arguments),
s(:receiver,
s(:string, "hello")))])

View File

@ -0,0 +1,10 @@
class Foo < Object
ofthen(3 , var)
end
-- -- --
s(:list, [s(:class, "Foo",
s(:module, "Object"), [s(:call,
s(:name, "ofthen"),
s(:arguments,
s(:int, 3),
s(:name, "var")))])])

View File

@ -0,0 +1,18 @@
class Pifi
ofthen(3 , var)
int ofthen(int n , ref m)
44
end
end
-- -- --
s(:list, [s(:class, "Pifi", nil, [s(:call,
s(:name, "ofthen"),
s(:arguments,
s(:int, 3),
s(:name, "var"))), s(:function, :int,
s(:name, "ofthen"),
s(:parameters,
s(:field, :int, :n),
s(:field, :ref, :m)),
s(:expressions,
s(:int, 44)))])])

View File

@ -0,0 +1,25 @@
class Ifi
int ofthen(int n)
if(0)
isit = 42
else
maybenot = 667
end
end
end
-- -- --
s(:list, [s(:class, "Ifi", nil, [s(:function, :int,
s(:name, "ofthen"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:if,
s(:condition,
s(:int, 0)),
s(:if_true,
s(:assign,
s(:name, "isit"),
s(:int, 42))),
s(:if_false, [s(:assign,
s(:name, "maybenot"),
s(:int, 667))]))))])])

View File

@ -0,0 +1,7 @@
class Foo < Object
int Foo.test()
43
end
end
-- -- --
{:expression_list=>[{:module_name=>"Foo", :derived_name=>s(:module, "Object"), :class_expressions=>[{:type=>"int", :receiver=>s(:module, "Foo"), :function_name=>s(:name, "test"), :parameter_list=>[], :expressions=>[s(:int, 43)], :end=>"end"}], :end=>"end"}]}

View File

@ -0,0 +1,11 @@
class Foo
module Boo
funcall(3 , var)
end
end
-- -- --
s(:list, [s(:class, "Foo", nil, [s(:module, "Boo", [s(:call,
s(:name, "funcall"),
s(:arguments,
s(:int, 3),
s(:name, "var")))])])])

View File

@ -0,0 +1,19 @@
class Opers
int foo(int x)
int abba = 5
abba + 5
end
end
-- -- --
s(:list, [s(:class, "Opers", nil, [s(:function, :int,
s(:name, "foo"),
s(:parameters,
s(:field, :int, :x)),
s(:expressions,
s(:name, "int"),
s(:assign,
s(:name, "abba"),
s(:int, 5)),
s(:operator, "+",
s(:name, "abba"),
s(:int, 5))))])])

View File

@ -0,0 +1,5 @@
class Foo
5
end
-- -- --
s(:list, [s(:class, "Foo", nil, [s(:int, 5)])])

View File

@ -0,0 +1,3 @@
[42, foo]
-- -- --
s(:list, [s(:array, [s(:int, 42), s(:name, "foo")])])

View File

@ -0,0 +1,8 @@
[ 3 + 4 , foo(22) ]
-- -- --
s(:list, [s(:array, [s(:operator, "+",
s(:int, 3),
s(:int, 4)), s(:call,
s(:name, "foo"),
s(:arguments,
s(:int, 22)))])])

View File

@ -0,0 +1,5 @@
{ foo => 33 }
-- -- --
s(:list, [s(:hash, [s(:assoc,
s(:name, "foo"),
s(:int, 33))])])

View File

@ -0,0 +1,5 @@
{ foo => true }
-- -- --
s(:list, [s(:hash, [s(:assoc,
s(:name, "foo"),
s(:true))])])

View File

@ -0,0 +1,7 @@
{foo => 33 , bar => 42}
-- -- --
s(:list, [s(:hash, [s(:assoc,
s(:name, "foo"),
s(:int, 33)), s(:assoc,
s(:name, "bar"),
s(:int, 42))])])

View File

@ -0,0 +1,3 @@
[42]
-- -- --
s(:list, [s(:array, [s(:int, 42)])])

View File

@ -0,0 +1,12 @@
if(0)
42
else
667
end
-- -- --
s(:list, [s(:if,
s(:condition,
s(:int, 0)),
s(:if_true,
s(:int, 42)),
s(:if_false, [s(:int, 667)]))])

View File

@ -0,0 +1,24 @@
if(3 > var)
Object.initialize(3)
else
var.new(33)
end
-- -- --
s(:list, [s(:if,
s(:condition,
s(:operator, ">",
s(:int, 3),
s(:name, "var"))),
s(:if_true,
s(:call,
s(:name, "initialize"),
s(:arguments,
s(:int, 3)),
s(:receiver,
s(:module, "Object")))),
s(:if_false, [s(:call,
s(:name, "new"),
s(:arguments,
s(:int, 33)),
s(:receiver,
s(:name, "var")))]))])

View File

@ -0,0 +1,10 @@
if(0)
42
end
-- -- --
s(:list, [s(:if,
s(:condition,
s(:int, 0)),
s(:if_true,
s(:int, 42)),
s(:if_false, nil))])

View File

@ -0,0 +1,17 @@
if(3 > var)
Object.initialize(3)
end
-- -- --
s(:list, [s(:if,
s(:condition,
s(:operator, ">",
s(:int, 3),
s(:name, "var"))),
s(:if_true,
s(:call,
s(:name, "initialize"),
s(:arguments,
s(:int, 3)),
s(:receiver,
s(:module, "Object")))),
s(:if_false, nil))])

View File

@ -0,0 +1,5 @@
a = 5
-- -- --
s(:list, [s(:assign,
s(:name, "a"),
s(:int, 5))])

View File

@ -0,0 +1,5 @@
a = 5
-- -- --
s(:list, [s(:assign,
s(:name, "a"),
s(:int, 5))])

View File

@ -0,0 +1,5 @@
a - b
-- -- --
s(:list, [s(:operator, "-",
s(:name, "a"),
s(:name, "b"))])

View File

@ -0,0 +1,5 @@
a - 5
-- -- --
s(:list, [s(:operator, "-",
s(:name, "a"),
s(:int, 5))])

View File

@ -0,0 +1,5 @@
a - "st"
-- -- --
s(:list, [s(:operator, "-",
s(:name, "a"),
s(:string, "st"))])

View File

@ -0,0 +1,5 @@
a == true
-- -- --
s(:list, [s(:operator, "==",
s(:name, "a"),
s(:true))])

View File

@ -0,0 +1,5 @@
5 / 3
-- -- --
s(:list, [s(:operator, "/",
s(:int, 5),
s(:int, 3))])

View File

@ -0,0 +1,5 @@
5 > 3
-- -- --
s(:list, [s(:operator, ">",
s(:int, 5),
s(:int, 3))])

View File

@ -0,0 +1,5 @@
5 - 3
-- -- --
s(:list, [s(:operator, "-",
s(:int, 5),
s(:int, 3))])

View File

@ -0,0 +1,5 @@
5 * 3
-- -- --
s(:list, [s(:operator, "*",
s(:int, 5),
s(:int, 3))])

View File

@ -0,0 +1,5 @@
5 + 3
-- -- --
s(:list, [s(:operator, "+",
s(:int, 5),
s(:int, 3))])

View File

@ -0,0 +1,5 @@
5 < 3
-- -- --
s(:list, [s(:operator, "<",
s(:int, 5),
s(:int, 3))])

View File

@ -0,0 +1,7 @@
2 + 3 * 4
-- -- --
s(:list, [s(:operator, "+",
s(:int, 2),
s(:operator, "*",
s(:int, 3),
s(:int, 4)))])

View File

@ -0,0 +1,7 @@
2 * 3 + 4
-- -- --
s(:list, [s(:operator, "+",
s(:operator, "*",
s(:int, 2),
s(:int, 3)),
s(:int, 4))])

View File

@ -0,0 +1,7 @@
2 + 3 + 4
-- -- --
s(:list, [s(:operator, "+",
s(:operator, "+",
s(:int, 2),
s(:int, 3)),
s(:int, 4))])

View File

@ -0,0 +1,5 @@
int String.length( ref x )
length
end
-- -- --
{:expression_list=>[{:type=>"int", :receiver=>s(:module, "String"), :function_name=>s(:name, "length"), :parameter_list=>[s(:field, :ref, :x)], :expressions=>[s(:name, "length")], :end=>"end"}]}

View File

@ -0,0 +1,49 @@
int fibonaccit(int n)
a = 0
b = 1
while( n > 1 )
tmp = a
a = b
b = tmp + b
puts(b)
n = n - 1
end
end
-- -- --
s(:list, [s(:function, :int,
s(:name, "fibonaccit"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:assign,
s(:name, "a"),
s(:int, 0)),
s(:assign,
s(:name, "b"),
s(:int, 1)),
s(:while,
s(:condition,
s(:operator, ">",
s(:name, "n"),
s(:int, 1))),
s(:expressions,
s(:assign,
s(:name, "tmp"),
s(:name, "a")),
s(:assign,
s(:name, "a"),
s(:name, "b")),
s(:assign,
s(:name, "b"),
s(:operator, "+",
s(:name, "tmp"),
s(:name, "b"))),
s(:call,
s(:name, "puts"),
s(:arguments,
s(:name, "b"))),
s(:assign,
s(:name, "n"),
s(:operator, "-",
s(:name, "n"),
s(:int, 1)))))))])

View File

@ -0,0 +1,23 @@
ref ofthen(int n)
if(0)
isit = 42
else
maybenot = 667
end
end
-- -- --
s(:list, [s(:function, :ref,
s(:name, "ofthen"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:if,
s(:condition,
s(:int, 0)),
s(:if_true,
s(:assign,
s(:name, "isit"),
s(:int, 42))),
s(:if_false, [s(:assign,
s(:name, "maybenot"),
s(:int, 667))]))))])

View File

@ -0,0 +1,9 @@
int foo()
5
end
-- -- --
s(:list, [s(:function, :int,
s(:name, "foo"),
s(:parameters),
s(:expressions,
s(:int, 5)))])

View File

@ -0,0 +1,17 @@
int foo(int x)
int abba = 5
abba + 5
end
-- -- --
s(:list, [s(:function, :int,
s(:name, "foo"),
s(:parameters,
s(:field, :int, :x)),
s(:expressions,
s(:name, "int"),
s(:assign,
s(:name, "abba"),
s(:int, 5)),
s(:operator, "+",
s(:name, "abba"),
s(:int, 5))))])

View File

@ -0,0 +1,16 @@
int retvar(ref n)
int i = 5
return i
end
-- -- --
s(:list, [s(:function, :int,
s(:name, "retvar"),
s(:parameters,
s(:field, :ref, :n)),
s(:expressions,
s(:name, "int"),
s(:assign,
s(:name, "i"),
s(:int, 5)),
s(:return,
s(:name, "i"))))])

View File

@ -0,0 +1,23 @@
int retvar(int n)
if( n > 5)
return 10
else
return 20
end
end
-- -- --
s(:list, [s(:function, :int,
s(:name, "retvar"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:if,
s(:condition,
s(:operator, ">",
s(:name, "n"),
s(:int, 5))),
s(:if_true,
s(:return,
s(:int, 10))),
s(:if_false, [s(:return,
s(:int, 20))]))))])

View File

@ -0,0 +1,25 @@
int retvar(int n )
while( n > 5)
n = n + 1
return n
end
end
-- -- --
s(:list, [s(:function, :int,
s(:name, "retvar"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:while,
s(:condition,
s(:operator, ">",
s(:name, "n"),
s(:int, 5))),
s(:expressions,
s(:assign,
s(:name, "n"),
s(:operator, "+",
s(:name, "n"),
s(:int, 1))),
s(:return,
s(:name, "n"))))))])

View File

@ -0,0 +1,11 @@
int foo( int n ,ref m)
n
end
-- -- --
s(:list, [s(:function, :int,
s(:name, "foo"),
s(:parameters,
s(:field, :int, :n),
s(:field, :ref, :m)),
s(:expressions,
s(:name, "n")))])

View File

@ -0,0 +1,28 @@
ref fibonaccit(int n)
a = 0
while(n)
some = 43
other = some * 4
end
end
-- -- --
s(:list, [s(:function, :ref,
s(:name, "fibonaccit"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:assign,
s(:name, "a"),
s(:int, 0)),
s(:while,
s(:condition,
s(:name, "n")),
s(:expressions,
s(:assign,
s(:name, "some"),
s(:int, 43)),
s(:assign,
s(:name, "other"),
s(:operator, "*",
s(:name, "some"),
s(:int, 4)))))))])

View File

@ -0,0 +1,10 @@
int foo(ref x)
5
end
-- -- --
s(:list, [s(:function, :int,
s(:name, "foo"),
s(:parameters,
s(:field, :ref, :x)),
s(:expressions,
s(:int, 5)))])

View File

@ -0,0 +1,7 @@
module Opers
abba = 5
end
-- -- --
s(:list, [s(:module, "Opers", [s(:assign,
s(:name, "abba"),
s(:int, 5))])])

View File

@ -0,0 +1,11 @@
module Foo
class Bar
funcall(3 , var)
end
end
-- -- --
s(:list, [s(:module, "Foo", [s(:class, "Bar", nil, [s(:call,
s(:name, "funcall"),
s(:arguments,
s(:int, 3),
s(:name, "var")))])])])

View File

@ -0,0 +1,19 @@
module Soho
ofthen(3 , var)
int ofthen(int n,ref m )
return 44
end
end
-- -- --
s(:list, [s(:module, "Soho", [s(:call,
s(:name, "ofthen"),
s(:arguments,
s(:int, 3),
s(:name, "var"))), s(:function, :int,
s(:name, "ofthen"),
s(:parameters,
s(:field, :int, :n),
s(:field, :ref, :m)),
s(:expressions,
s(:return,
s(:int, 44))))])])

View File

@ -0,0 +1,25 @@
module Foo
ref ofthen(int n)
if(0)
isit = 42
else
maybenot = 667
end
end
end
-- -- --
s(:list, [s(:module, "Foo", [s(:function, :ref,
s(:name, "ofthen"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:if,
s(:condition,
s(:int, 0)),
s(:if_true,
s(:assign,
s(:name, "isit"),
s(:int, 42))),
s(:if_false, [s(:assign,
s(:name, "maybenot"),
s(:int, 667))]))))])])

View File

@ -0,0 +1,20 @@
module Opers
int foo(int x)
int abba = 5
return abba + 5
end
end
-- -- --
s(:list, [s(:module, "Opers", [s(:function, :int,
s(:name, "foo"),
s(:parameters,
s(:field, :int, :x)),
s(:expressions,
s(:name, "int"),
s(:assign,
s(:name, "abba"),
s(:int, 5)),
s(:return,
s(:operator, "+",
s(:name, "abba"),
s(:int, 5)))))])])

View File

@ -0,0 +1,5 @@
module Simple
5
end
-- -- --
s(:list, [s(:module, "Simple", [s(:int, 5)])])

View File

@ -0,0 +1,4 @@
return 42
-- -- --
s(:list, [s(:return,
s(:int, 42))])

View File

@ -0,0 +1,4 @@
return "hello"
-- -- --
s(:list, [s(:return,
s(:string, "hello"))])

View File

@ -0,0 +1,4 @@
return foo
-- -- --
s(:list, [s(:return,
s(:name, "foo"))])

View File

@ -0,0 +1,11 @@
class FooBo
Bar.call(35)
end
-- -- --
s(:list, [s(:class, "FooBo", nil, [s(:call,
s(:name, "call"),
s(:arguments,
s(:int, 35)),
s(:receiver,
s(:module, "Bar")))])])

View File

@ -0,0 +1,17 @@
int foo(ref x)
a = 5
end
foo( 3 )
-- -- --
s(:list, [s(:function, :int,
s(:name, "foo"),
s(:parameters,
s(:field, :ref, :x)),
s(:expressions,
s(:assign,
s(:name, "a"),
s(:int, 5)))), s(:call,
s(:name, "foo"),
s(:arguments,
s(:int, 3)))])

54
test/cases/root/fibo1.tst Normal file
View File

@ -0,0 +1,54 @@
int fibonaccit(int n)
a = 0
b = 1
while( n > 1 )
tmp = a
a = b
b = tmp + b
puts(b)
n = n - 1
end
end
fibonaccit( 10 )
-- -- --
s(:list, [s(:function, :int,
s(:name, "fibonaccit"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:assign,
s(:name, "a"),
s(:int, 0)),
s(:assign,
s(:name, "b"),
s(:int, 1)),
s(:while,
s(:condition,
s(:operator, ">",
s(:name, "n"),
s(:int, 1))),
s(:expressions,
s(:assign,
s(:name, "tmp"),
s(:name, "a")),
s(:assign,
s(:name, "a"),
s(:name, "b")),
s(:assign,
s(:name, "b"),
s(:operator, "+",
s(:name, "tmp"),
s(:name, "b"))),
s(:call,
s(:name, "puts"),
s(:arguments,
s(:name, "b"))),
s(:assign,
s(:name, "n"),
s(:operator, "-",
s(:name, "n"),
s(:int, 1))))))), s(:call,
s(:name, "fibonaccit"),
s(:arguments,
s(:int, 10)))])

View File

@ -0,0 +1,16 @@
module Fibo
a = 5 + foo
bar( b , a , r)
end
-- -- --
s(:list, [s(:module, "Fibo", [s(:assign,
s(:name, "a"),
s(:operator, "+",
s(:int, 5),
s(:name, "foo"))), s(:call,
s(:name, "bar"),
s(:arguments,
s(:name, "b"),
s(:name, "a"),
s(:name, "r")))])])

View File

@ -0,0 +1,24 @@
module Fibo
int fibonaccit(int n)
int a = 0
return a
end
fibonaccit( 10 )
end
-- -- --
s(:list, [s(:module, "Fibo", [s(:function, :int,
s(:name, "fibonaccit"),
s(:parameters,
s(:field, :int, :n)),
s(:expressions,
s(:name, "int"),
s(:assign,
s(:name, "a"),
s(:int, 0)),
s(:return,
s(:name, "a")))), s(:call,
s(:name, "fibonaccit"),
s(:arguments,
s(:int, 10)))])])

View File

@ -0,0 +1,12 @@
module FooBo
class Bar
a = 5 + foo
end
end
-- -- --
s(:list, [s(:module, "FooBo", [s(:class, "Bar", nil, [s(:assign,
s(:name, "a"),
s(:operator, "+",
s(:int, 5),
s(:name, "foo")))])])])

View File

@ -0,0 +1,34 @@
while( n > 1)
tmp = a
a = b
b = tmp + b
puts(b)
n = n - 1
end
-- -- --
s(:list, [s(:while,
s(:condition,
s(:operator, ">",
s(:name, "n"),
s(:int, 1))),
s(:expressions,
s(:assign,
s(:name, "tmp"),
s(:name, "a")),
s(:assign,
s(:name, "a"),
s(:name, "b")),
s(:assign,
s(:name, "b"),
s(:operator, "+",
s(:name, "tmp"),
s(:name, "b"))),
s(:call,
s(:name, "puts"),
s(:arguments,
s(:name, "b"))),
s(:assign,
s(:name, "n"),
s(:operator, "-",
s(:name, "n"),
s(:int, 1)))))])

View File

@ -0,0 +1,16 @@
while(1)
tmp = a
puts(b)
end
-- -- --
s(:list, [s(:while,
s(:condition,
s(:int, 1)),
s(:expressions,
s(:assign,
s(:name, "tmp"),
s(:name, "a")),
s(:call,
s(:name, "puts"),
s(:arguments,
s(:name, "b")))))])

View File

@ -0,0 +1,22 @@
while(1)
tmp = String.new()
tmp.puts(i)
end
-- -- --
s(:list, [s(:while,
s(:condition,
s(:int, 1)),
s(:expressions,
s(:assign,
s(:name, "tmp"),
s(:call,
s(:name, "new"),
s(:arguments),
s(:receiver,
s(:module, "String")))),
s(:call,
s(:name, "puts"),
s(:arguments,
s(:name, "i")),
s(:receiver,
s(:name, "tmp")))))])

View File

@ -1,18 +1,14 @@
require_relative "setup"
require "parslet/convenience"
# remove the line numbers on assert fails, so it's easy to copy paste the result as the expected result
Parslet::Slice.class_eval do
def inspect
'"' + to_s + '"'
end
end
# Included in parser test will create tests methods
# Older test harness
module ParserHelper
def self.included(base)
base.send :include, InstanceMethods #provides helpers and setup
base.send :include, AST::Sexp
base.send :include, AST::if_true
base.send :extend, ClassMethods #gets the method creation going
end
@ -39,11 +35,36 @@ module ParserHelper
def check_ast
syntax = @parser.parse(@string_input)
is = @transform.apply(syntax)
#puts is.inspect
puts is.inspect
assert_equal @transform_output , is
end
def check_write test
dirname = decamelize(self.class.name)[10 .. -1]
test = test[5 .. -1]
syntax = @parser.parse_with_debug(@string_input)
out = Parser::Transform.new.apply(syntax).inspect
dir = File.dirname(__FILE__) + "/" + dirname
FileUtils.mkdir_p(dir) unless File.exists?(dir)
out_file = File.new(dir + "/" + test + ".tst", "w")
out_file.puts @string_input
out_file.puts "-- -- --"
out_file.puts out
out_file.close
end
def decamelize str
str.gsub(/(^|[a-z])([A-Z])/) do
($1.empty?)? $2 : "#{$1}_#{$2}"
end.downcase
end
def camelize str
str.gsub(/(^|_)([a-z])/) { $2.upcase }
end
end
module ClassMethods
# this creates test methods dynamically. For each test_* method we create
# three test_*[ast/parse/transf] methods that in turn check the three phases.
@ -51,12 +72,12 @@ module ParserHelper
def runnable_methods
tests = []
public_instance_methods(true).grep(/^test_/).map(&:to_s).each do |test|
["ast" , "transform" , "parse"].each do |what|
["write"].each do |what|
name = "#{test}_#{what}"
tests << name
self.send(:define_method, name ) do
send(test)
send("check_#{what}")
send("check_#{what}" , test)
end
end
end

View File

@ -1,2 +1,32 @@
require_relative "unit/test_all"
require_relative "roots/test_all"
require_relative "setup"
require "parslet/convenience"
require "ast/sexp"
class TestAll < MiniTest::Test
include AST::Sexp
def check_file file
inn , out = File.new(file).read.split("-- -- --")
sexp = eval(out)
syntax = Parser::Salama.new.parse_with_debug(inn)
result = Parser::Transform.new.apply(syntax)
assert_equal sexp , result
end
# this creates test methods dynamically. For each test_* method we create
# three test_*[ast/parse/transf] methods that in turn check the three phases.
# runnable_methods is called by minitest to determine which tests to run
def self.runnable_methods
puts "called"
all = Dir["test/cases/*/*.tst"]
puts "case #{all.length}"
tests =[]
all.each do |file|
name = file.sub("test/cases/","").sub("/","_").sub(".tst","")
tests << name
self.send(:define_method, name ) do
send("check_file" , file)
end
end
tests
end
end