The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl

# Unit testing for PPI::Token::Pod

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
	no warnings 'once';
	$PPI::XS_DISABLE = 1;
	$PPI::Lexer::X_TOKENIZER ||= $ENV{X_TOKENIZER};
}
use Test::More tests => 9;
use Test::NoWarnings;
use PPI;


MERGE: {
	# Create the test fragments
	my $one = PPI::Token::Pod->new("=pod\n\nOne\n\n=cut\n");
	my $two = PPI::Token::Pod->new("=pod\n\nTwo");
	isa_ok( $one, 'PPI::Token::Pod' );
	isa_ok( $two, 'PPI::Token::Pod' );

	# Create the combined Pod
	my $merged = PPI::Token::Pod->merge($one, $two);
	isa_ok( $merged, 'PPI::Token::Pod' );
	is( $merged->content, "=pod\n\nOne\n\nTwo\n\n=cut\n", 'Merged POD looks ok' );
}


TOKENIZE: {
	foreach my $test (
		[ "=pod\n=cut", [ 'PPI::Token::Pod' ] ],
		[ "=pod\n=cut\n", [ 'PPI::Token::Pod' ] ],
		[ "=pod\n=cut\n\n", [ 'PPI::Token::Pod', 'PPI::Token::Whitespace' ] ],
		[ "=pod\n=Cut\n\n", [ 'PPI::Token::Pod' ] ],  # pod doesn't end, so no whitespace token
	) {
		my $T = PPI::Tokenizer->new( \$test->[0] );
		my @tokens = map { ref $_ } @{ $T->all_tokens };
		is_deeply( \@tokens, $test->[1], 'all tokens as expected' );
	}
}