Lingua-EN-Titlecase-Simple

 view release on metacpan or  search on metacpan

t/titlecase.t  view on Meta::CPAN

#!/usr/bin/perl
use strict; use warnings;

use Test::More;
use if @ARGV != 0, 'IPC::Open2' => 'open2';
use if @ARGV == 0, 'Lingua::EN::Titlecase::Simple' => 'titlecase';
use Data::Dumper 'Dumper';
use constant TEXTMODE => ':encoding(UTF-8)';

sub pp { s/\A\$VAR1 = //, s/;\s*\z//, return $_ for Dumper $_[0]; }

defined &titlecase or *titlecase = sub {
	open2( my $cout, my $cin, @ARGV ) or die "Couldn't execute @ARGV\: $!\n";
	binmode $_, TEXTMODE for $cin, $cout;

	print { $cin } join "\n", @_;
	close $cin or die $!;

	chomp( my @result = readline $cout );
	close $cout or die $!;

	@result;
};

binmode DATA, TEXTMODE;

my @testcase =
	map [ split /\n/ ],
	do { local $/ = ""; <DATA> }; # $/ = "" is paragraph mode

plan tests => 0+@testcase;

my @result = titlecase( map $_->[0], @testcase );

for ( @testcase ) {
	my ( $input, $expect ) = @$_;
	is shift @result, $expect, pp $input;
}

__END__

For step-by-step directions email someone@gmail.com
For Step-by-Step Directions Email someone@gmail.com

2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'
2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'

Have you read “The Lottery”?
Have You Read “The Lottery”?

your hair[cut] looks (nice)
Your Hair[cut] Looks (Nice)

People probably won't put http://foo.com/bar/ in titles
People Probably Won't Put http://foo.com/bar/ in Titles

Scott Moritz and TheStreet.com’s million iPhone la‑la land
Scott Moritz and TheStreet.com’s Million iPhone La‑La Land

BlackBerry vs. iPhone
BlackBerry vs. iPhone

Notes and observations regarding Apple’s announcements from ‘The Beat Goes On’ special event
Notes and Observations Regarding Apple’s Announcements From ‘The Beat Goes On’ Special Event

Read markdown_rules.txt to find out how _underscores around words_ will be interpretted
Read markdown_rules.txt to Find Out How _Underscores Around Words_ Will Be Interpretted

Q&A with Steve Jobs: 'That's what happens in technology'
Q&A With Steve Jobs: 'That's What Happens in Technology'

What is AT&T's problem?
What Is AT&T's Problem?

Apple deal with AT&T falls through
Apple Deal With AT&T Falls Through

this v that
This v That

this vs that
This vs That

this v. that
This v. That

this vs. that
This vs. That



( run in 3.296 seconds using v1.01-cache-2.11-cpan-b301d465b3d )