Eshu

 view release on metacpan or  search on metacpan

t/26-xs-advanced.t  view on Meta::CPAN

	INPUT:
	buf
	CODE:
		RETVAL = do_process(SvPV_nolen(buf), len);
	OUTPUT:
		RETVAL
END

	my $got = Eshu->indent_xs($input);
	is($got, $expected, 'XSUB with INPUT section');
}

# XSUB with nested C control flow in CODE
{
	my $input = <<'END';
MODULE = Foo  PACKAGE = Foo

int
count_matches(str, pat)
const char * str
const char * pat
CODE:
int count = 0;
const char *p = str;
while (*p) {
if (*p == *pat) {
count++;
}
p++;
}
RETVAL = count;
OUTPUT:
RETVAL
END

	my $expected = <<'END';
MODULE = Foo  PACKAGE = Foo

int
count_matches(str, pat)
	const char * str
	const char * pat
	CODE:
		int count = 0;
		const char *p = str;
		while (*p) {
			if (*p == *pat) {
				count++;
			}
			p++;
		}
		RETVAL = count;
	OUTPUT:
		RETVAL
END

	my $got = Eshu->indent_xs($input);
	is($got, $expected, 'XSUB with nested C control flow in CODE');
}

# XSUB with PPCODE (list context)
{
	my $input = <<'END';
MODULE = Foo  PACKAGE = Foo

void
get_pair(self)
SV * self
PPCODE:
XPUSHs(sv_2mortal(newSVpvs("key")));
XPUSHs(sv_2mortal(newSViv(42)));
END

	my $expected = <<'END';
MODULE = Foo  PACKAGE = Foo

void
get_pair(self)
	SV * self
	PPCODE:
		XPUSHs(sv_2mortal(newSVpvs("key")));
		XPUSHs(sv_2mortal(newSViv(42)));
END

	my $got = Eshu->indent_xs($input);
	is($got, $expected, 'XSUB with PPCODE for list context');
}

done_testing();



( run in 0.683 second using v1.01-cache-2.11-cpan-5511b514fd6 )