1require 'dtrace/helper'
2
3module DTrace
4  class TestHashCreate < TestCase
5    def test_hash_new
6      trap_probe(probe, 'Hash.new') { |_,rbfile,saw|
7        saw = saw.map(&:split).find_all { |num, file, line|
8          file == rbfile && num == '0'
9        }
10        assert_operator saw.length, :>, 0
11      }
12    end
13
14    def test_hash_lit
15      trap_probe(probe, '{}') { |_,rbfile,saw|
16        saw = saw.map(&:split).find_all { |num, file, line|
17          file == rbfile && num == '0'
18        }
19        assert_operator saw.length, :>, 0
20      }
21    end
22
23    def test_hash_lit_elements
24      trap_probe(probe, '{ :foo => :bar }') { |_,rbfile,saw|
25        saw = saw.map(&:split).find_all { |num, file, line|
26          file == rbfile && num == '2'
27        }
28        assert_operator saw.length, :>, 0
29      }
30    end
31
32    def test_hash_lit_elements_string
33      trap_probe(probe, '{ :foo => :bar, :bar => "baz" }') { |_,rbfile,saw|
34        saw = saw.map(&:split).find_all { |num, file, line|
35          file == rbfile && num == '4'
36        }
37        assert_operator saw.length, :>, 0
38      }
39    end
40
41    private
42    def probe
43      <<-eoprobe
44ruby$target:::hash-create
45/arg1/
46{
47  printf("%d %s %d\\n", arg0, copyinstr(arg1), arg2);
48}
49      eoprobe
50    end
51  end
52end if defined?(DTrace::TestCase)
53