From 5afddb6703c8b41618fe9319020f9e7bac0e5faf Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 17 Feb 2014 15:58:59 -0800 Subject: [PATCH] Bring "Reverts X" to more general infrastructure and port unit tests Summary: Ref T3886. See D8261. This brings the "reverts x" phrase to modern infrastructure. It isn't actually called by the real parser yet, I'm going to do that in one go at the end so I can test everything more easily. This had unit tests; port most of them forward. Test Plan: Added and executed unit tests. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3886 Differential Revision: https://secure.phabricator.com/D8262 --- src/__phutil_library_map__.php | 6 +- ...DifferentialCustomFieldDependsOnParser.php | 2 +- .../DifferentialCustomFieldRevertsParser.php | 51 ++++++++++ ...tialCustomFieldDependsOnParserTestCase.php | 6 +- ...entialCustomFieldRevertsParserTestCase.php | 92 +++++++++++++++++++ .../DifferentialFreeformFieldTestCase.php | 31 ------- .../PhabricatorCustomFieldMonogramParser.php | 4 +- 7 files changed, 153 insertions(+), 39 deletions(-) create mode 100644 src/applications/differential/field/parser/DifferentialCustomFieldRevertsParser.php create mode 100644 src/applications/differential/field/parser/__tests__/DifferentialCustomFieldRevertsParserTestCase.php delete mode 100644 src/applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 5e7ed0be84..12cf628f35 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -358,6 +358,8 @@ phutil_register_library_map(array( 'DifferentialCustomFieldDependsOnParser' => 'applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php', 'DifferentialCustomFieldDependsOnParserTestCase' => 'applications/differential/field/parser/__tests__/DifferentialCustomFieldDependsOnParserTestCase.php', 'DifferentialCustomFieldNumericIndex' => 'applications/differential/storage/DifferentialCustomFieldNumericIndex.php', + 'DifferentialCustomFieldRevertsParser' => 'applications/differential/field/parser/DifferentialCustomFieldRevertsParser.php', + 'DifferentialCustomFieldRevertsParserTestCase' => 'applications/differential/field/parser/__tests__/DifferentialCustomFieldRevertsParserTestCase.php', 'DifferentialCustomFieldStorage' => 'applications/differential/storage/DifferentialCustomFieldStorage.php', 'DifferentialCustomFieldStringIndex' => 'applications/differential/storage/DifferentialCustomFieldStringIndex.php', 'DifferentialDAO' => 'applications/differential/storage/DifferentialDAO.php', @@ -387,7 +389,6 @@ phutil_register_library_map(array( 'DifferentialFieldSpecificationIncompleteException' => 'applications/differential/field/exception/DifferentialFieldSpecificationIncompleteException.php', 'DifferentialFieldValidationException' => 'applications/differential/field/exception/DifferentialFieldValidationException.php', 'DifferentialFreeformFieldSpecification' => 'applications/differential/field/specification/DifferentialFreeformFieldSpecification.php', - 'DifferentialFreeformFieldTestCase' => 'applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php', 'DifferentialGetWorkingCopy' => 'applications/differential/DifferentialGetWorkingCopy.php', 'DifferentialGitSVNIDFieldSpecification' => 'applications/differential/field/specification/DifferentialGitSVNIDFieldSpecification.php', 'DifferentialHostFieldSpecification' => 'applications/differential/field/specification/DifferentialHostFieldSpecification.php', @@ -2876,6 +2877,8 @@ phutil_register_library_map(array( 'DifferentialCustomFieldDependsOnParser' => 'PhabricatorCustomFieldMonogramParser', 'DifferentialCustomFieldDependsOnParserTestCase' => 'PhabricatorTestCase', 'DifferentialCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage', + 'DifferentialCustomFieldRevertsParser' => 'PhabricatorCustomFieldMonogramParser', + 'DifferentialCustomFieldRevertsParserTestCase' => 'PhabricatorTestCase', 'DifferentialCustomFieldStorage' => 'PhabricatorCustomFieldStorage', 'DifferentialCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', 'DifferentialDAO' => 'PhabricatorLiskDAO', @@ -2908,7 +2911,6 @@ phutil_register_library_map(array( 'DifferentialFieldSpecificationIncompleteException' => 'Exception', 'DifferentialFieldValidationException' => 'Exception', 'DifferentialFreeformFieldSpecification' => 'DifferentialFieldSpecification', - 'DifferentialFreeformFieldTestCase' => 'PhabricatorTestCase', 'DifferentialGitSVNIDFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialHostFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialHovercardEventListener' => 'PhabricatorEventListener', diff --git a/src/applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php b/src/applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php index adf0d5317d..e88a5d68be 100644 --- a/src/applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php +++ b/src/applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php @@ -26,7 +26,7 @@ final class DifferentialCustomFieldDependsOnParser } protected function getMonogramPattern() { - return 'D\d+'; + return '[Dd]\d+'; } } diff --git a/src/applications/differential/field/parser/DifferentialCustomFieldRevertsParser.php b/src/applications/differential/field/parser/DifferentialCustomFieldRevertsParser.php new file mode 100644 index 0000000000..02f1dbfe64 --- /dev/null +++ b/src/applications/differential/field/parser/DifferentialCustomFieldRevertsParser.php @@ -0,0 +1,51 @@ + 0, ), ), - 'depends on D123, D124' => array( + 'depends on D123, d124' => array( array( - 'match' => 'depends on D123, D124', + 'match' => 'depends on D123, d124', 'prefix' => 'depends on', 'infix' => '', - 'monograms' => array('D123', 'D124'), + 'monograms' => array('D123', 'd124'), 'suffix' => '', 'offset' => 0, ), diff --git a/src/applications/differential/field/parser/__tests__/DifferentialCustomFieldRevertsParserTestCase.php b/src/applications/differential/field/parser/__tests__/DifferentialCustomFieldRevertsParserTestCase.php new file mode 100644 index 0000000000..bb7a276319 --- /dev/null +++ b/src/applications/differential/field/parser/__tests__/DifferentialCustomFieldRevertsParserTestCase.php @@ -0,0 +1,92 @@ + array(), + + // Git default message. + 'This reverts commit 1234abcd.' => array( + array( + 'match' => 'reverts commit 1234abcd', + 'prefix' => 'reverts', + 'infix' => 'commit', + 'monograms' => array('1234abcd'), + 'suffix' => '', + 'offset' => 5, + ), + ), + + // Mercurial default message. + 'Backed out changeset 1234abcd.' => array( + array( + 'match' => 'Backed out changeset 1234abcd', + 'prefix' => 'Backed out', + 'infix' => 'changeset', + 'monograms' => array('1234abcd'), + 'suffix' => '', + 'offset' => 0, + ), + ), + + 'this undoes 1234abcd, 5678efab. they were bad' => array( + array( + 'match' => 'undoes 1234abcd, 5678efab', + 'prefix' => 'undoes', + 'infix' => '', + 'monograms' => array('1234abcd', '5678efab'), + 'suffix' => '', + 'offset' => 5, + ), + ), + + "Reverts 123" => array( + array( + 'match' => 'Reverts 123', + 'prefix' => 'Reverts', + 'infix' => '', + 'monograms' => array('123'), + 'suffix' => '', + 'offset' => 0, + ), + ), + + + "Reverts r123" => array( + array( + 'match' => 'Reverts r123', + 'prefix' => 'Reverts', + 'infix' => '', + 'monograms' => array('r123'), + 'suffix' => '', + 'offset' => 0, + ), + ), + + "Backs out commit\n99\n100" => array( + array( + 'match' => "Backs out commit\n99\n100", + 'prefix' => 'Backs out', + 'infix' => 'commit', + 'monograms' => array('99', '100'), + 'suffix' => '', + 'offset' => 0, + ), + ), + + "This doesn't revert anything" => array(), + 'nonrevert of r11' => array(), + "fixed a bug" => array(), + ); + + foreach ($map as $input => $expect) { + $parser = new DifferentialCustomFieldRevertsParser(); + $output = $parser->parseCorpus($input); + + $this->assertEqual($expect, $output, $input); + } + } + +} diff --git a/src/applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php b/src/applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php deleted file mode 100644 index 20b304aa40..0000000000 --- a/src/applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php +++ /dev/null @@ -1,31 +0,0 @@ - array('123'), - "Reverts r123" => array('r123'), - "Reverts ac382f2" => array('ac382f2'), - "Reverts r22, r23" => array('r22', 'r23'), - "Reverts D99" => array('D99'), - "Backs out commit\n99\n100" => array('99', '100'), - "undo change f9f9f8f8" => array('f9f9f8f8'), - "Backedout Changeset rX1234" => array('rX1234'), - "This doesn't revert anything" => array(), - 'nonrevert of r11' => array(), - "fixed a bug" => array(), - ); - - foreach ($map as $input => $expect) { - $actual = array_values( - DifferentialFreeformFieldSpecification::findRevertedCommits($input)); - - $this->assertEqual( - $expect, - $actual, - "Reverted commits in: {$input}"); - } - } - -} diff --git a/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php b/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php index 6e59f1d93e..0a4c2aba7f 100644 --- a/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php +++ b/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php @@ -27,7 +27,7 @@ abstract class PhabricatorCustomFieldMonogramParser '((?:'.$monogram_pattern.'[,\s]*)+)'. $suffix_regex. '(?:$|\b)'. - '/i'; + '/'; $matches = null; $ok = preg_match_all( @@ -65,7 +65,7 @@ abstract class PhabricatorCustomFieldMonogramParser $maybe_tail = $final ? '' : '\s+'; $maybe_optional = $optional ? '?' : ''; - return '(?:('.$parts.')'.$maybe_tail.')'.$maybe_optional; + return '(?i:('.$parts.')'.$maybe_tail.')'.$maybe_optional; } }