2017-04-02 18:13:14 +02:00
|
|
|
require_relative "helper"
|
2017-04-02 08:44:56 +02:00
|
|
|
|
2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
2018-07-19 15:30:36 +02:00
|
|
|
class TestBasicValues < MiniTest::Test
|
2018-06-29 21:46:39 +02:00
|
|
|
include RubyTests
|
2017-04-02 08:44:56 +02:00
|
|
|
|
2017-04-02 11:57:05 +02:00
|
|
|
def test_self
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( "self")
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal SelfExpression , lst.class
|
2017-04-02 11:57:05 +02:00
|
|
|
end
|
2017-04-02 08:44:56 +02:00
|
|
|
def test_nil
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( "nil")
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal NilConstant , lst.class
|
2017-04-02 08:44:56 +02:00
|
|
|
end
|
|
|
|
def test_false
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( "false")
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal FalseConstant , lst.class
|
2017-04-02 08:44:56 +02:00
|
|
|
end
|
|
|
|
def test_true
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( "true")
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal TrueConstant , lst.class
|
2017-04-02 08:44:56 +02:00
|
|
|
end
|
|
|
|
def test_integer
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( "123")
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal IntegerConstant , lst.class
|
2017-04-02 08:44:56 +02:00
|
|
|
end
|
|
|
|
def test_string
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( "'string'")
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal StringConstant , lst.class , lst.inspect
|
2017-04-02 08:44:56 +02:00
|
|
|
end
|
2017-04-02 09:43:22 +02:00
|
|
|
def test_sym
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( ":symbol")
|
2018-03-15 06:54:14 +01:00
|
|
|
assert_equal SymbolConstant , lst.class , lst.inspect
|
2017-04-02 09:43:22 +02:00
|
|
|
end
|
|
|
|
def test_dstr
|
2019-02-10 20:02:16 +01:00
|
|
|
assert_raises Ruby::ProcessError do
|
|
|
|
compile( '"interpolate #{self}"')
|
2017-04-02 09:43:22 +02:00
|
|
|
end
|
|
|
|
end
|
2017-04-02 12:24:09 +02:00
|
|
|
|
|
|
|
def test_scope
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( "begin ; 1 ; end")
|
2017-04-02 12:24:09 +02:00
|
|
|
assert_equal ScopeStatement , lst.class , lst.inspect
|
|
|
|
end
|
|
|
|
def test_scope_contents
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( "begin ; 1 ; end")
|
2017-04-02 12:24:09 +02:00
|
|
|
assert_equal 1 , lst.statements.first.value
|
|
|
|
end
|
2017-04-02 08:44:56 +02:00
|
|
|
end
|
2018-07-19 15:30:36 +02:00
|
|
|
class TestBasicTypes < MiniTest::Test
|
2018-06-29 21:46:39 +02:00
|
|
|
include RubyTests
|
|
|
|
|
2017-04-19 19:59:13 +02:00
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2017-04-19 19:59:13 +02:00
|
|
|
end
|
2018-07-20 19:53:35 +02:00
|
|
|
def compile_const( input )
|
2018-06-29 21:46:39 +02:00
|
|
|
lst = compile( input )
|
2018-07-20 19:53:35 +02:00
|
|
|
lst.class
|
2017-04-19 19:59:13 +02:00
|
|
|
end
|
|
|
|
def test_integer
|
2018-07-20 19:53:35 +02:00
|
|
|
assert_equal IntegerConstant , compile_const( "123")
|
2017-04-19 19:59:13 +02:00
|
|
|
end
|
2018-09-01 14:54:25 +02:00
|
|
|
def test_float
|
|
|
|
assert_equal FloatConstant , compile_const( "123.1")
|
|
|
|
end
|
2017-04-19 19:59:13 +02:00
|
|
|
def test_string
|
2018-07-20 19:53:35 +02:00
|
|
|
assert_equal StringConstant , compile_const( "'string'")
|
2017-04-19 19:59:13 +02:00
|
|
|
end
|
|
|
|
def test_sym
|
2018-07-20 19:53:35 +02:00
|
|
|
assert_equal SymbolConstant , compile_const( ":symbol")
|
2017-04-19 19:59:13 +02:00
|
|
|
end
|
2018-07-20 19:53:35 +02:00
|
|
|
def test_nil
|
|
|
|
assert_equal NilConstant , compile_const( "nil")
|
2018-05-17 08:49:01 +02:00
|
|
|
end
|
2018-07-20 19:53:35 +02:00
|
|
|
def test_false
|
|
|
|
assert_equal FalseConstant , compile_const( "false")
|
2018-05-17 08:49:01 +02:00
|
|
|
end
|
2018-07-20 19:53:35 +02:00
|
|
|
def test_true
|
|
|
|
assert_equal TrueConstant , compile_const( "true")
|
2018-05-17 08:49:01 +02:00
|
|
|
end
|
2017-04-19 19:59:13 +02:00
|
|
|
end
|
2019-10-03 23:36:49 +02:00
|
|
|
class TestBasicTypesSol < MiniTest::Test
|
2018-09-01 14:54:25 +02:00
|
|
|
include RubyTests
|
|
|
|
|
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-09-01 14:54:25 +02:00
|
|
|
end
|
|
|
|
def compile_const( input )
|
|
|
|
lst = compile( input )
|
2019-10-03 23:36:49 +02:00
|
|
|
lst.to_sol.to_s
|
2018-09-01 14:54:25 +02:00
|
|
|
end
|
|
|
|
def test_integer
|
|
|
|
assert_equal "123" , compile_const( "123")
|
|
|
|
end
|
|
|
|
def test_float
|
|
|
|
assert_equal "123.0" , compile_const( "123.0")
|
|
|
|
end
|
|
|
|
def test_string
|
|
|
|
assert_equal "'string'" , compile_const( "'string'")
|
|
|
|
end
|
|
|
|
def test_sym
|
2019-09-13 19:34:41 +02:00
|
|
|
assert_equal ":symbol" , compile_const( ":symbol")
|
2018-09-01 14:54:25 +02:00
|
|
|
end
|
|
|
|
def test_nil
|
|
|
|
assert_equal "nil" , compile_const( "nil")
|
|
|
|
end
|
|
|
|
def test_false
|
|
|
|
assert_equal "false" , compile_const( "false")
|
|
|
|
end
|
|
|
|
def test_true
|
|
|
|
assert_equal "true" , compile_const( "true")
|
|
|
|
end
|
|
|
|
end
|
2017-04-02 08:44:56 +02:00
|
|
|
end
|