[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / test / dtrace / test_hash_create.rb
blob603ee218727c2cea175231de0022c69d56e726e8
1 # frozen_string_literal: false
2 require_relative 'helper'
4 module DTrace
5   class TestHashCreate < TestCase
6     def test_hash_new
7       trap_probe(probe, 'Hash.new') { |_,rbfile,saw|
8         saw = saw.map(&:split).find_all { |num, file, line|
9           file == rbfile && num == '0'
10         }
11         assert_operator saw.length, :>, 0
12       }
13     end
15     def test_hash_lit
16       trap_probe(probe, '{}') { |_,rbfile,saw|
17         saw = saw.map(&:split).find_all { |num, file, line|
18           file == rbfile && num == '0'
19         }
20         assert_operator saw.length, :>, 0
21       }
22     end
24     def test_hash_lit_elements
25       trap_probe(probe, '{ :foo => :bar }') { |_,rbfile,orig|
26         saw = orig.map(&:split).find_all { |num, file, line|
27           file == rbfile && num == '2'
28         }
29         assert_operator saw.length, :>, 0, orig
30       }
31     end
33     def test_hash_lit_elements_string
34       trap_probe(probe, '{ :foo => :bar, :bar => "baz" }') { |_,rbfile,saw|
35         saw = saw.map(&:split).find_all { |num, file, line|
36           file == rbfile && num == '4'
37         }
38         assert_operator saw.length, :>, 0
39       }
40     end
42     private
43     def probe
44       <<-eoprobe
45 ruby$target:::hash-create
46 /arg1/
48   printf("%d %s %d\\n", arg0, copyinstr(arg1), arg2);
50       eoprobe
51     end
52   end
53 end if defined?(DTrace::TestCase)