mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-21 22:32:41 +01:00
Update PhutilCowsay.php to work for small cows
Summary: Update PhutilCowsay.php to work for small cows. In doing so, we also simplify the code to just use multiline regexps rather than trying to parse a line at a time. cowsay(cow='small'){{{What about me?}}} Test Plan: Check cowsay works for the built in non-perl cow: ``` cowsay(cow='companion'){{{Built in}}} ``` Test all the perl cows: ``` cowsay(cow='bunny'){{{Testing bunny}}} cowsay(cow='cower'){{{Testing cower}}} cowsay(cow='daemon'){{{Testing daemon}}} cowsay(cow='default'){{{Testing default}}} cowsay(cow='dragon-and-cow'){{{Testing dragon-and-cow}}} cowsay(cow='dragon'){{{Testing dragon}}} cowsay(cow='elephant'){{{Testing elephant}}} cowsay(cow='eyes'){{{Testing eyes}}} cowsay(cow='flaming-sheep'){{{Testing flaming-sheep}}} cowsay(cow='head-in'){{{Testing head-in}}} cowsay(cow='kitty'){{{Testing kitty}}} cowsay(cow='koala'){{{Testing koala}}} cowsay(cow='meow'){{{Testing meow}}} cowsay(cow='moofasa'){{{Testing moofasa}}} cowsay(cow='moose'){{{Testing moose}}} cowsay(cow='mutilated'){{{Testing mutilated}}} cowsay(cow='satanic'){{{Testing satanic}}} cowsay(cow='sheep'){{{Testing sheep}}} cowsay(cow='skeleton'){{{Testing skeleton}}} cowsay(cow='small'){{{Testing small}}} cowsay(cow='squirrel'){{{Testing squirrel}}} cowsay(cow='stegosaurus'){{{Testing stegosaurus}}} cowsay(cow='supermilker'){{{Testing supermilker}}} cowsay(cow='surgery'){{{Testing surgery}}} cowsay(cow='turkey'){{{Testing turkey}}} cowsay(cow='turtle'){{{Testing turtle}}} cowsay(cow='tux'){{{Testing tux}}} cowsay(cow='www'){{{Testing www}}} ``` Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Differential Revision: https://we.phorge.it/D25436
This commit is contained in:
parent
98d16d27cf
commit
5bc53cfe53
4 changed files with 39 additions and 24 deletions
|
@ -41,34 +41,29 @@ final class PhutilCowsay extends Phobject {
|
||||||
$template = $this->template;
|
$template = $this->template;
|
||||||
|
|
||||||
// Real ".cow" files are Perl scripts which define a variable called
|
// Real ".cow" files are Perl scripts which define a variable called
|
||||||
// "$the_cow". We aren't going to interpret Perl, so strip all this stuff
|
// "$the_cow". We aren't going to interpret Perl, so just get everything
|
||||||
// (and any comments in the file) away.
|
// between the EOC (End Of Cow) tokens. The initial EOC might be in
|
||||||
$template = phutil_split_lines($template, true);
|
// quotes, and might have a semicolon.
|
||||||
$keep = array();
|
// We apply regexp modifiers
|
||||||
$is_perl_cowfile = false;
|
// * 's' to make . match newlines within the EOC ... EOC block
|
||||||
foreach ($template as $key => $line) {
|
// * 'm' so we can use ^ to match start of line within the multiline string
|
||||||
if (preg_match('/^#/', $line)) {
|
$matches = null;
|
||||||
continue;
|
if (
|
||||||
}
|
preg_match('/\$the_cow/', $template) &&
|
||||||
if (preg_match('/^\s*\\$the_cow/', $line)) {
|
preg_match('/EOC[\'"]?;?.*?^(.*?)^EOC/sm', $template, $matches)
|
||||||
$is_perl_cowfile = true;
|
) {
|
||||||
continue;
|
$template = $matches[1];
|
||||||
}
|
|
||||||
if (preg_match('/^\s*EOC\s*$/', $line)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$keep[] = $line;
|
|
||||||
}
|
|
||||||
$template = implode('', $keep);
|
|
||||||
|
|
||||||
// Original .cow files are perl scripts which contain escaped sequences.
|
// Original .cow files are perl scripts which contain escaped sequences.
|
||||||
// We attempt to unescape here by replacing any character preceded by a
|
// We attempt to unescape here by replacing any character preceded by a
|
||||||
// backslash/escape with just that character.
|
// backslash/escape with just that character.
|
||||||
if ($is_perl_cowfile) {
|
|
||||||
$template = preg_replace(
|
$template = preg_replace(
|
||||||
'/\\\\(.)/',
|
'/\\\\(.)/',
|
||||||
'$1',
|
'$1',
|
||||||
$template);
|
$template);
|
||||||
|
} else {
|
||||||
|
// Text template. Just strip away comments.
|
||||||
|
$template = preg_replace('/^#.*$/', '', $template);
|
||||||
}
|
}
|
||||||
|
|
||||||
$token_patterns = array(
|
$token_patterns = array(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# test case for original perl-script cowfile
|
# test case for original perl-script cowfile
|
||||||
$the_cow =
|
$the_cow = <<EOC
|
||||||
$thoughts
|
$thoughts
|
||||||
$thoughts
|
$thoughts
|
||||||
/---\\__/---\\\\
|
/---\\__/---\\\\
|
||||||
|
@ -9,6 +9,7 @@ $the_cow =
|
||||||
/ ..--.. \\\\
|
/ ..--.. \\\\
|
||||||
| \\ .... / ||
|
| \\ .... / ||
|
||||||
\\---/--\\---//
|
\\---/--\\---//
|
||||||
|
EOC
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
{
|
{
|
||||||
"text": "I made a friend!",
|
"text": "I made a friend!",
|
||||||
|
|
7
src/utils/__tests__/cowsay/small.expect
Normal file
7
src/utils/__tests__/cowsay/small.expect
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
__________________
|
||||||
|
< How are my eyes? >
|
||||||
|
------------------
|
||||||
|
\ ,__,
|
||||||
|
\ (oo)____
|
||||||
|
(__) )\
|
||||||
|
||--|| *
|
12
src/utils/__tests__/cowsay/small.test
Normal file
12
src/utils/__tests__/cowsay/small.test
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
$eyes = ".." unless ($eyes);
|
||||||
|
$the_cow = <<EOC;
|
||||||
|
$thoughts ,__,
|
||||||
|
$thoughts ($eyes)____
|
||||||
|
(__) )\\
|
||||||
|
$tongue||--|| *
|
||||||
|
EOC
|
||||||
|
~~~~~~~~~~
|
||||||
|
{
|
||||||
|
"text": "How are my eyes?",
|
||||||
|
"eyes": "oo"
|
||||||
|
}
|
Loading…
Reference in a new issue