Debian Codegraph @

ext/XS-APItest/t/cv_name.t

raw
1 use XS::APItest;
2 use Test::More tests => 30;
3 use feature "lexical_subs", "state";
4 no warnings "experimental::lexical_subs";
5
6 is (cv_name(\&foo), 'main::foo', 'cv_name with package sub');
7 is (cv_name(*{"foo"}{CODE}), 'main::foo',
8 'cv_name with package sub via glob');
9 is (cv_name(\*{"foo"}), 'main::foo', 'cv_name with typeglob');
10 is (cv_name(\"foo"), 'foo', 'cv_name with string');
11 state sub lex1;
12 is (cv_name(\&lex1), 'lex1', 'cv_name with lexical sub');
13
14 $ret = \cv_name(\&bar, $name);
15 is $ret, \$name, 'cv_name with package sub returns 2nd argument';
16 is ($name, 'main::bar', 'retval of cv_name with package sub & 2nd arg');
17 $ret = \cv_name(*{"bar"}{CODE}, $name);
18 is $ret, \$name, 'cv_name with package sub via glob returns 2nd argument';
19 is ($name, 'main::bar', 'retval of cv_name w/pkg sub via glob & 2nd arg');
20 $ret = \cv_name(\*{"bar"}, $name);
21 is $ret, \$name, 'cv_name with typeglob returns 2nd argument';
22 is ($name, 'main::bar', 'retval of cv_name with typeglob & 2nd arg');
23 $ret = \cv_name(\"bar", $name);
24 is $ret, \$name, 'cv_name with string returns 2nd argument';
25 is ($name, 'bar', 'retval of cv_name with string & 2nd arg');
26 state sub lex2;
27 $ret = \cv_name(\&lex2, $name);
28 is $ret, \$name, 'cv_name with lexical sub returns 2nd argument';
29 is ($name, 'lex2', 'retval of cv_name with lexical sub & 2nd arg');
30
31 # nq in test names means CV_NAME_NOTQUAL
32 is (cv_name(\&foo, undef, 1), 'foo', 'cv_name with package sub (nq)');
33 is (cv_name(*{"foo"}{CODE}, undef, 1), 'foo',
34 'cv_name with package sub via glob (nq)');
35 is (cv_name(\*{"foo"}, undef, 1), 'foo', 'cv_name with typeglob (nq)');
36 is (cv_name(\"foo", undef, 1), 'foo', 'cv_name with string (nq)');
37 is (cv_name(\&lex1, undef, 1), 'lex1', 'cv_name with lexical sub (nq)');
38
39 $ret = \cv_name(\&bar, $name, 1);
40 is $ret, \$name, 'cv_name with package sub returns 2nd argument (nq)';
41 is ($name, 'bar', 'retval of cv_name with package sub & 2nd arg (nq)');
42 $ret = \cv_name(*{"bar"}{CODE}, $name, 1);
43 is $ret, \$name, 'cv_name with package sub via glob returns 2nd arg (nq)';
44 is ($name, 'bar', 'retval of cv_name w/pkg sub via glob & 2nd arg (nq)');
45 $ret = \cv_name(\*{"bar"}, $name, 1);
46 is $ret, \$name, 'cv_name with typeglob returns 2nd argument (nq)';
47 is ($name, 'bar', 'retval of cv_name with typeglob & 2nd arg (nq)');
48 $ret = \cv_name(\"bar", $name, 1);
49 is $ret, \$name, 'cv_name with string returns 2nd argument (nq)';
50 is ($name, 'bar', 'retval of cv_name with string & 2nd arg (nq)');
51 $ret = \cv_name(\&lex2, $name, 1);
52 is $ret, \$name, 'cv_name with lexical sub returns 2nd argument (nq)';
53 is ($name, 'lex2', 'retval of cv_name with lexical sub & 2nd arg (nq)');