summaryrefslogtreecommitdiff
path: root/test/-ext-/typeddata/test_typeddata.rb
blob: e32b030a35dffdc65b1fbfde99c217a08d4fbe79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: false
require 'test/unit'
require "-test-/typeddata"

class Test_TypedData < Test::Unit::TestCase
  def test_wrong_argtype
    assert_raise_with_message(TypeError, "wrong argument type false (expected typed_data)") {Bug::TypedData.check(false)}

    assert_raise_with_message(TypeError, "wrong argument type true (expected typed_data)") {Bug::TypedData.check(true)}

    assert_raise_with_message(TypeError, "wrong argument type Symbol (expected typed_data)") {Bug::TypedData.check(:e)}

    assert_raise_with_message(TypeError, "wrong argument type Integer (expected typed_data)") {Bug::TypedData.check(0)}

    assert_raise_with_message(TypeError, "wrong argument type String (expected typed_data)") {Bug::TypedData.check("a")}

    obj = eval("class C\u{1f5ff}; self; end").new
    assert_raise_with_message(TypeError, /C\u{1f5ff}/) {Bug::TypedData.check(obj)}
  end

  def test_deferred_free
    assert_ruby_status([], "#{<<-"begin;"}\n#{<<-"end;"}")
    require "-test-/typeddata"
    begin;
      n = 1 << 20
      Bug::TypedData.make(n)
    end;
  end
end