mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +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:
parent
77d7bb7af0
commit
6b6e1f0ba8
2 changed files with 34 additions and 24 deletions
|
@ -48,10 +48,12 @@ final class PhabricatorDifferentialRevisionTestDataGenerator
|
|||
|
||||
public function generateDiff($author) {
|
||||
$paste_generator = new PhabricatorPasteTestDataGenerator();
|
||||
$languages = $paste_generator->supportedLanguages;
|
||||
$lang = array_rand($languages);
|
||||
$code = $paste_generator->generateContent($lang);
|
||||
$altcode = $paste_generator->generateContent($lang);
|
||||
$languages = $paste_generator->getSupportedLanguages();
|
||||
$language = array_rand($languages);
|
||||
$spec = $languages[$language];
|
||||
|
||||
$code = $paste_generator->generateContent($spec);
|
||||
$altcode = $paste_generator->generateContent($spec);
|
||||
$newcode = $this->randomlyModify($code, $altcode);
|
||||
$diff = id(new PhabricatorDifferenceEngine())
|
||||
->generateRawDiffFromFileContent($code, $newcode);
|
||||
|
|
|
@ -22,9 +22,11 @@ final class PhabricatorPasteTestDataGenerator
|
|||
PhabricatorPasteTitleTransaction::TRANSACTIONTYPE,
|
||||
$name);
|
||||
|
||||
$xactions[] = $this->newTransaction(
|
||||
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE,
|
||||
$language);
|
||||
if (strlen($language) > 0) {
|
||||
$xactions[] = $this->newTransaction(
|
||||
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE,
|
||||
$language);
|
||||
}
|
||||
|
||||
$xactions[] = $this->newTransaction(
|
||||
PhabricatorPasteContentTransaction::TRANSACTIONTYPE,
|
||||
|
@ -43,17 +45,29 @@ final class PhabricatorPasteTestDataGenerator
|
|||
return new PhabricatorPasteTransaction();
|
||||
}
|
||||
|
||||
private function newPasteContent() {
|
||||
$languages = array(
|
||||
'txt' => array(),
|
||||
'php' => array(
|
||||
'content' => 'PhutilPHPCodeSnippetContextFreeGrammar',
|
||||
),
|
||||
'java' => array(
|
||||
'content' => 'PhutilJavaCodeSnippetContextFreeGrammar',
|
||||
),
|
||||
);
|
||||
public function getSupportedLanguages() {
|
||||
return array(
|
||||
'php' => array(
|
||||
'content' => 'PhutilPHPCodeSnippetContextFreeGrammar',
|
||||
),
|
||||
'java' => array(
|
||||
'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);
|
||||
$spec = $languages[$language];
|
||||
|
||||
|
@ -62,16 +76,10 @@ final class PhabricatorPasteTestDataGenerator
|
|||
$title_generator = 'PhabricatorPasteFilenameContextFreeGrammar';
|
||||
}
|
||||
|
||||
$content_generator = idx($spec, 'content');
|
||||
if (!$content_generator) {
|
||||
$content_generator = 'PhutilLipsumContextFreeGrammar';
|
||||
}
|
||||
|
||||
$title = newv($title_generator, array())
|
||||
->generate();
|
||||
|
||||
$content = newv($content_generator, array())
|
||||
->generateSeveral($this->roll(4, 12, 10));
|
||||
$content = $this->generateContent($spec);
|
||||
|
||||
// Usually add the language as a suffix.
|
||||
if ($this->roll(1, 20) > 2) {
|
||||
|
|
Loading…
Reference in a new issue