1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-11 07:11:04 +01:00

Fix Lipsum generators for Differential Revisions and Pastes

Summary:
When generating test data to solve a bug I have encountered, I noticed Lipsum was not working correctly for Differential Revisions and Pastes.

It seemed like they weren't updated after some refactoring. This fixes that by updating them.

Test Plan: Run Lipsum for all objects, and note that it has much less failure.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D19534
This commit is contained in:
Kenneth Endfinger 2018-07-23 15:05:32 -05:00
parent 77d7bb7af0
commit 6b6e1f0ba8
No known key found for this signature in database
GPG key ID: 218FB54BEB42FFEC
2 changed files with 34 additions and 24 deletions

View file

@ -48,10 +48,12 @@ final class PhabricatorDifferentialRevisionTestDataGenerator
public function generateDiff($author) { public function generateDiff($author) {
$paste_generator = new PhabricatorPasteTestDataGenerator(); $paste_generator = new PhabricatorPasteTestDataGenerator();
$languages = $paste_generator->supportedLanguages; $languages = $paste_generator->getSupportedLanguages();
$lang = array_rand($languages); $language = array_rand($languages);
$code = $paste_generator->generateContent($lang); $spec = $languages[$language];
$altcode = $paste_generator->generateContent($lang);
$code = $paste_generator->generateContent($spec);
$altcode = $paste_generator->generateContent($spec);
$newcode = $this->randomlyModify($code, $altcode); $newcode = $this->randomlyModify($code, $altcode);
$diff = id(new PhabricatorDifferenceEngine()) $diff = id(new PhabricatorDifferenceEngine())
->generateRawDiffFromFileContent($code, $newcode); ->generateRawDiffFromFileContent($code, $newcode);

View file

@ -22,9 +22,11 @@ final class PhabricatorPasteTestDataGenerator
PhabricatorPasteTitleTransaction::TRANSACTIONTYPE, PhabricatorPasteTitleTransaction::TRANSACTIONTYPE,
$name); $name);
if (strlen($language) > 0) {
$xactions[] = $this->newTransaction( $xactions[] = $this->newTransaction(
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE, PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE,
$language); $language);
}
$xactions[] = $this->newTransaction( $xactions[] = $this->newTransaction(
PhabricatorPasteContentTransaction::TRANSACTIONTYPE, PhabricatorPasteContentTransaction::TRANSACTIONTYPE,
@ -43,9 +45,8 @@ final class PhabricatorPasteTestDataGenerator
return new PhabricatorPasteTransaction(); return new PhabricatorPasteTransaction();
} }
private function newPasteContent() { public function getSupportedLanguages() {
$languages = array( return array(
'txt' => array(),
'php' => array( 'php' => array(
'content' => 'PhutilPHPCodeSnippetContextFreeGrammar', 'content' => 'PhutilPHPCodeSnippetContextFreeGrammar',
), ),
@ -53,7 +54,20 @@ final class PhabricatorPasteTestDataGenerator
'content' => 'PhutilJavaCodeSnippetContextFreeGrammar', 'content' => 'PhutilJavaCodeSnippetContextFreeGrammar',
), ),
); );
}
public function generateContent($spec) {
$content_generator = idx($spec, 'content');
if (!$content_generator) {
$content_generator = 'PhutilLipsumContextFreeGrammar';
}
return newv($content_generator, array())
->generateSeveral($this->roll(4, 12, 10));
}
private function newPasteContent() {
$languages = $this->getSupportedLanguages();
$language = array_rand($languages); $language = array_rand($languages);
$spec = $languages[$language]; $spec = $languages[$language];
@ -62,16 +76,10 @@ final class PhabricatorPasteTestDataGenerator
$title_generator = 'PhabricatorPasteFilenameContextFreeGrammar'; $title_generator = 'PhabricatorPasteFilenameContextFreeGrammar';
} }
$content_generator = idx($spec, 'content');
if (!$content_generator) {
$content_generator = 'PhutilLipsumContextFreeGrammar';
}
$title = newv($title_generator, array()) $title = newv($title_generator, array())
->generate(); ->generate();
$content = newv($content_generator, array()) $content = $this->generateContent($spec);
->generateSeveral($this->roll(4, 12, 10));
// Usually add the language as a suffix. // Usually add the language as a suffix.
if ($this->roll(1, 20) > 2) { if ($this->roll(1, 20) > 2) {