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