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