mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 23:16:42 +02:00
parent
cb4bc4d03c
commit
21ea290b34
8 changed files with 382 additions and 21 deletions
90
test/prism/static_inspect_test.rb
Normal file
90
test/prism/static_inspect_test.rb
Normal file
|
@ -0,0 +1,90 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative "test_helper"
|
||||
|
||||
return if Prism::BACKEND == :FFI
|
||||
|
||||
module Prism
|
||||
class StaticInspectTest < TestCase
|
||||
def test_false
|
||||
assert_equal "false", static_inspect("false")
|
||||
end
|
||||
|
||||
def test_float
|
||||
assert_equal "0.25", static_inspect("0.25")
|
||||
assert_equal "5.125", static_inspect("5.125")
|
||||
|
||||
assert_equal "0.0", static_inspect("0.0")
|
||||
assert_equal "-0.0", static_inspect("-0.0")
|
||||
|
||||
assert_equal "1.0e+100", static_inspect("1e100")
|
||||
assert_equal "-1.0e+100", static_inspect("-1e100")
|
||||
|
||||
assert_equal "Infinity", static_inspect("1e1000")
|
||||
assert_equal "-Infinity", static_inspect("-1e1000")
|
||||
end
|
||||
|
||||
def test_imaginary
|
||||
assert_equal "(0+1i)", static_inspect("1i")
|
||||
assert_equal "(0-1i)", static_inspect("-1i")
|
||||
end
|
||||
|
||||
def test_integer
|
||||
assert_equal "1000", static_inspect("1_0_0_0")
|
||||
assert_equal "10000000000000000000000000000", static_inspect("1_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0")
|
||||
end
|
||||
|
||||
def test_nil
|
||||
assert_equal "nil", static_inspect("nil")
|
||||
end
|
||||
|
||||
def test_rational
|
||||
assert_equal "(0/1)", static_inspect("0r")
|
||||
assert_equal "(1/1)", static_inspect("1r")
|
||||
assert_equal "(1/1)", static_inspect("1.0r")
|
||||
assert_equal "(77777/1000)", static_inspect("77.777r")
|
||||
end
|
||||
|
||||
def test_regular_expression
|
||||
assert_equal "/.*/", static_inspect("/.*/")
|
||||
assert_equal "/.*/i", static_inspect("/.*/i")
|
||||
assert_equal "/.*/", static_inspect("/.*/u")
|
||||
assert_equal "/.*/n", static_inspect("/.*/un")
|
||||
end
|
||||
|
||||
def test_source_encoding
|
||||
assert_equal "#<Encoding:UTF-8>", static_inspect("__ENCODING__")
|
||||
assert_equal "#<Encoding:Shift_JIS>", static_inspect("__ENCODING__", encoding: "Shift_JIS")
|
||||
end
|
||||
|
||||
def test_source_file
|
||||
assert_equal __FILE__.inspect, static_inspect("__FILE__", filepath: __FILE__)
|
||||
end
|
||||
|
||||
def test_source_line
|
||||
assert_equal "1", static_inspect("__LINE__")
|
||||
assert_equal "5", static_inspect("__LINE__", line: 5)
|
||||
end
|
||||
|
||||
def test_string
|
||||
assert_equal "\"\"", static_inspect('""', frozen_string_literal: true)
|
||||
assert_equal "\"Hello, World!\"", static_inspect('"Hello, World!"', frozen_string_literal: true)
|
||||
assert_equal "\"\\a\"", static_inspect("\"\\a\"", frozen_string_literal: true)
|
||||
end
|
||||
|
||||
def test_symbol
|
||||
assert_equal ":foo", static_inspect(":foo")
|
||||
assert_equal ":foo", static_inspect("%s[foo]")
|
||||
end
|
||||
|
||||
def test_true
|
||||
assert_equal "true", static_inspect("true")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def static_inspect(source, **options)
|
||||
Debug.static_inspect(source, **options)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,31 +6,31 @@ module Prism
|
|||
class StaticLiteralsTest < TestCase
|
||||
def test_static_literals
|
||||
assert_warning("1")
|
||||
assert_warning("0xA", "10")
|
||||
assert_warning("0o10", "8")
|
||||
assert_warning("0b10", "2")
|
||||
assert_warning("1_000")
|
||||
assert_warning((2**32).to_s(10), "0x#{(2**32).to_s(16)}")
|
||||
assert_warning((2**64).to_s(10), "0x#{(2**64).to_s(16)}")
|
||||
assert_warning("0xA", "10", "10")
|
||||
assert_warning("0o10", "8", "8")
|
||||
assert_warning("0b10", "2", "2")
|
||||
assert_warning("1_000", "1000", "1000")
|
||||
assert_warning((2**32).to_s(10), "0x#{(2**32).to_s(16)}", (2**32).to_s(10))
|
||||
assert_warning((2**64).to_s(10), "0x#{(2**64).to_s(16)}", (2**64).to_s(10))
|
||||
|
||||
refute_warning("1", "-1")
|
||||
refute_warning((2**32).to_s(10), "-0x#{(2**32).to_s(16)}")
|
||||
refute_warning((2**64).to_s(10), "-0x#{(2**64).to_s(16)}")
|
||||
|
||||
assert_warning("__LINE__", "2")
|
||||
assert_warning("3", "__LINE__")
|
||||
assert_warning("__LINE__", "2", "2")
|
||||
assert_warning("3", "__LINE__", "3")
|
||||
|
||||
assert_warning("1.0")
|
||||
assert_warning("1e2", "100.0")
|
||||
assert_warning("1e2", "100.0", "100.0")
|
||||
|
||||
assert_warning("1r")
|
||||
assert_warning("1.0r")
|
||||
assert_warning("1r", "1r", "(1/1)")
|
||||
assert_warning("1.0r", "1.0r", "(1/1)")
|
||||
|
||||
assert_warning("1i")
|
||||
assert_warning("1.0i")
|
||||
assert_warning("1i", "1i", "(0+1i)")
|
||||
assert_warning("1.0i", "1.0i", "(0+1.0i)")
|
||||
|
||||
assert_warning("1ri")
|
||||
assert_warning("1.0ri")
|
||||
assert_warning("1ri", "1ri", "(0+(1/1)*i)")
|
||||
assert_warning("1.0ri", "1.0ri", "(0+(1/1)*i)")
|
||||
|
||||
assert_warning("\"#{__FILE__}\"")
|
||||
assert_warning("\"foo\"")
|
||||
|
@ -41,12 +41,12 @@ module Prism
|
|||
refute_warning("/foo/", "/foo/i")
|
||||
|
||||
assert_warning(":foo")
|
||||
assert_warning("%s[foo]")
|
||||
assert_warning("%s[foo]", ":foo", ":foo")
|
||||
|
||||
assert_warning("true")
|
||||
assert_warning("false")
|
||||
assert_warning("nil")
|
||||
assert_warning("__ENCODING__")
|
||||
assert_warning("__ENCODING__", "__ENCODING__", "#<Encoding:UTF-8>")
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -71,10 +71,10 @@ module Prism
|
|||
warnings
|
||||
end
|
||||
|
||||
def assert_warning(left, right = left)
|
||||
def assert_warning(left, right = left, message = left)
|
||||
hash_keys, when_clauses = parse_warnings(left, right)
|
||||
|
||||
assert_include hash_keys.message, left
|
||||
assert_include hash_keys.message, message
|
||||
assert_include hash_keys.message, "line 3"
|
||||
assert_include when_clauses.message, "line 3"
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue