Skip to content

Commit

Permalink
Use goto label syntax in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed Jan 26, 2021
1 parent 14cff45 commit d911bfc
Show file tree
Hide file tree
Showing 78 changed files with 2,232 additions and 1,132 deletions.
24 changes: 16 additions & 8 deletions tests/src/Enum/Enum.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ $abcTwo = ABC::get(2);
$abdOne = ABD::get(1);
$fOne = E::get(1);

// get()

get:
Assert::type($aOne, A::class);
Assert::equal($aOne, $aOne2);

// getValue()

getValue:
Assert::same($aOne->getValue(), 1);

// getConstantName()

getConstantName:
Assert::same($aOne->getConstantName(), 'ONE');

// equals()

equals:
Assert::exception(static function () use ($aOne, $fOne): void {
$aOne->equals($fOne);
}, InvalidTypeException::class);
Expand All @@ -87,15 +91,18 @@ Assert::true($abOne->equals($abcOne));
Assert::true($abOne->equals($abdOne));
Assert::true($abcOne->equals($abdOne));

// equalsValue()

equalsValue:
Assert::false($aOne->equalsValue(2));
Assert::true($aOne->equalsValue(1));

// isValid()

isValid:
Assert::false(A::isValid(5));
Assert::true(A::isValid(1));

// getAllowedValues()

getAllowedValues:
Assert::same(A::getAllowedValues(), [
'ONE' => 1,
'TWO' => 2,
Expand All @@ -119,7 +126,8 @@ Assert::same(ABD::getAllowedValues(), [
'TWO' => 2,
]);

// getInstances()

getInstances:
Assert::equal(A::getInstances(), [
'ONE' => $aOne,
'TWO' => $aTwo,
Expand Down
66 changes: 44 additions & 22 deletions tests/src/Enum/Set.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,28 @@ $jklOneTwo = JKL::get(1, 2);
$jkmOneTwo = JKM::get(1, 2);
$nOneTwo = N::get(1, 2);

// get()

get:
Assert::type($jOne, J::class);
Assert::equal($jOne, $jOne2);

// getValue()

getValue:
Assert::same($jOne->getValue(), 1);
Assert::same($jOneTwo->getValue(), 3);

// getValues()

getValues:
Assert::same($jOne->getValues(), [1]);
Assert::same($jOneTwo->getValues(), [1, 2]);

// getConstantNames()

getConstantNames:
Assert::same($jOne->getConstantNames(), [1 => 'ONE']);
Assert::same($jOneTwo->getConstantNames(), [1 => 'ONE', 2 => 'TWO']);

// equals()

equals:
Assert::exception(static function () use ($jOne, $nOne): void {
$jOne->equals($nOne);
}, InvalidTypeException::class);
Expand All @@ -117,17 +122,20 @@ Assert::true($jkOneTwo->equals($jklOneTwo));
Assert::true($jkOneTwo->equals($jkmOneTwo));
Assert::true($jklOneTwo->equals($jkmOneTwo));

// equalsValue()

equalsValue:
Assert::false($jOne->equalsValue(2));
Assert::true($jOne->equalsValue(1));
Assert::false($jOneTwo->equalsValue(6));
Assert::true($jOneTwo->equalsValue(3));

// isValid()

isValid:
Assert::false(J::isValid(5));
Assert::true(J::isValid(1));

// getAllowedValues()

getAllowedValues:
Assert::same(J::getAllowedValues(), [
'ONE' => 1,
'TWO' => 2,
Expand All @@ -151,7 +159,8 @@ Assert::same(JKM::getAllowedValues(), [
'TWO' => 2,
]);

// getInstances()

getInstances:
Assert::equal(J::getInstances(), [
'ONE' => $jOne,
'TWO' => $jTwo,
Expand All @@ -164,69 +173,82 @@ Assert::equal(JKL::getInstances(), [
'TWO' => $jklTwo,
]);

// invert()

invert:
Assert::equal($jTwoFour->invert(), $jOneEight);
Assert::equal($jEmpty->invert(), $jAll);
Assert::equal($jAll->invert(), $jEmpty);

// contains()

contains:
Assert::false($jOneTwo->contains($jTwoFour));
Assert::true($jOneTwo->contains($jOneTwo2));
Assert::true($jOneTwo->contains($jOne));
Assert::true($jOneTwo->contains($jEmpty));

// intersects()

intersects:
Assert::false($jOne->intersects($jTwo));
Assert::false($jOne->intersects($jEmpty));
Assert::true($jOneTwo->intersects($jTwoFour));

// intersect()

intersect:
Assert::equal($jOneTwo->intersect($jTwoFour), $jTwo);
Assert::equal($jOneTwo->intersect($jEmpty), $jEmpty);

// union()

union:
Assert::equal($jEmpty->union($jOne), $jOne);
Assert::equal($jOne->union($jTwo), $jOneTwo);
Assert::equal($jOneTwo->union($jTwoFour), $jOneTwoFour);

// subtract()

subtract:
Assert::equal($jOneTwo->subtract($jOne), $jTwo);
Assert::equal($jOneTwo->subtract($jEmpty), $jOneTwo);
Assert::equal($jEmpty->subtract($jOne), $jEmpty);
Assert::equal($jOneTwo->subtract($jEmpty), $jOneTwo);

// difference()

difference:
Assert::equal($jOneTwo->difference($jTwoFour), $jOneFour);
Assert::equal($jEmpty->difference($jEmpty), $jEmpty);
Assert::equal($jEmpty->difference($jAll), $jAll);
Assert::equal($jAll->difference($jAll), $jEmpty);
Assert::equal($jAll->difference($jEmpty), $jAll);

// containsAll()

containsAll:
Assert::false($jOneTwo->containsAll(2, 4));
Assert::true($jOneTwo->containsAll(1, 2));
Assert::true($jAll->containsAll(1, 2, 4, 8));

// containsAny()

containsAny:
Assert::false($jOneTwo->containsAny(4, 8));
Assert::true($jOneTwo->containsAny(2, 4));
Assert::false($jEmpty->containsAny(1, 2, 4, 8));

// filter()

filter:
Assert::equal($jOneTwo->filter(1, 4), $jOne);
Assert::equal($jAll->filter(1, 2), $jOneTwo);
Assert::equal($jAll->filter(), $jEmpty);
Assert::equal($jEmpty->filter(1, 2), $jEmpty);

// add()

add:
Assert::equal($jOneTwo->add(2, 4), $jOneTwoFour);
Assert::equal($jOneTwo->add(4, 8), $jAll);

// remove()

remove:
Assert::equal($jAll->remove(4, 8), $jOneTwo);
Assert::equal($jOneTwo->remove(2, 4), $jOne);

// xor()

_xor:
Assert::equal($jOneTwo->xor(2, 4), $jOneFour);
Assert::equal($jEmpty->xor(), $jEmpty);
Assert::equal($jEmpty->xor(1, 2, 4, 8), $jAll);
Expand Down
1 change: 1 addition & 0 deletions tests/src/Geolocation/PositionFormatter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require_once __DIR__ . '/../bootstrap.php';
$position = new Position(-15, -50);
$positionFormatter = new PositionFormatter();


Assert::same($positionFormatter->format($position, 'l'), '15');
Assert::same($positionFormatter->format($position, 'L'), '-15');
Assert::same($positionFormatter->format($position, 'n'), 'S');
Expand Down
69 changes: 46 additions & 23 deletions tests/src/Language/Locale/Locale.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ if (PHP_VERSION_ID > 70011) {
$localeString = 'cs_Latn_CZ_VAR1_VAR2_X_PRI1_PRI2@currency=CZK;numbers=arab;calendar=iso8601;collation=phonebook;colbackwards=yes;colcasefirst=lower';
$localeStringCanonicalized = 'cs_Latn_CZ_VAR1_VAR2_X_PRI1_PRI2@calendar=iso8601;colbackwards=yes;colcasefirst=lower;collation=phonebook;currency=CZK;numbers=arab';

// get()

get:
$locale = Locale::get($localeString);
$simple = Locale::get('cs');

// create()

create:
$created = Locale::create(
Language::get(Language::CZECH),
Country::get(Country::CZECHIA),
Expand All @@ -50,65 +52,80 @@ $created = Locale::create(
);
Assert::same($created, $locale);

// removeCollation()

removeCollation:
$safeLocale = $locale->removeCollation();
Assert::type($safeLocale, Locale::class);
Assert::same($safeLocale->getValue(), 'cs_Latn_CZ_VAR1_VAR2_X_PRI1_PRI2@calendar=iso8601;currency=CZK;numbers=arab');

// getDefault()

getDefault:
Assert::type(Locale::getDefault(), Locale::class);

// getCollator()

getCollator:
$collator = $locale->getCollator();
Assert::type($collator, Collator::class);
Assert::same($collator->getLocaleObject()->getValue(), 'cs');

// matches()

matches:
Assert::true($locale->matches($simple));

// findBestMatch()

findBestMatch:
Assert::same($locale->findBestMatch(['cs', 'cs_Latn_CZ', 'cs_CZ', 'en'])->getValue(), 'cs_Latn_CZ');

// getValue()

getValue:
Assert::same($locale->getValue(), $localeStringCanonicalized);
Assert::same($simple->getValue(), 'cs');

// getLanguage()

getLanguage:
Assert::same($locale->getLanguage(), Language::get(Language::CZECH));
Assert::same($simple->getLanguage(), Language::get(Language::CZECH));

// getScript()

getScript:
Assert::same($locale->getScript(), Script::get(Script::LATIN));
Assert::null($simple->getScript());

// getCountry()

getCountry:
Assert::same($locale->getCountry(), Country::get(Country::CZECHIA));
Assert::null($simple->getCountry());

// getVariants()

getVariants:
Assert::same($locale->getVariants(), ['VAR1', 'VAR2']);
Assert::same($simple->getVariants(), []);

// getVariant()

getVariant:
Assert::same($locale->getVariant(0), 'VAR1');
Assert::same($locale->getVariant(1), 'VAR2');
Assert::null($simple->getVariant(0));

// hasVariant()

hasVariant:
Assert::true($locale->hasVariant('VAR1'));
Assert::true($locale->hasVariant('VAR2'));
Assert::false($locale->hasVariant('VAR3'));

// getPrivates()

getPrivates:
Assert::same($locale->getPrivates(), ['PRI1', 'PRI2']);
Assert::same($simple->getPrivates(), []);

// getPrivate()

getPrivate:
Assert::same($locale->getPrivate(0), 'PRI1');
Assert::same($locale->getPrivate(1), 'PRI2');
Assert::null($simple->getPrivate(0));

// getKeywords()

getKeywords:
Assert::same($locale->getKeywords(), [
LocaleKeyword::CALENDAR => LocaleCalendar::ISO8601,
LocaleKeyword::COL_BACKWARDS => LocaleColBackwards::YES,
Expand All @@ -119,7 +136,8 @@ Assert::same($locale->getKeywords(), [
]);
Assert::same($simple->getKeywords(), []);

// getKeyword()

getKeyword:
Assert::same($locale->getKeyword(LocaleKeyword::CURRENCY), Currency::CZECH_KORUNA);
Assert::same($locale->getKeyword(LocaleKeyword::NUMBERS), LocaleNumbers::ARABIC_INDIC);
Assert::same($locale->getKeyword(LocaleKeyword::CALENDAR), LocaleCalendar::ISO8601);
Expand All @@ -128,23 +146,28 @@ Assert::same($locale->getKeyword(LocaleKeyword::COL_BACKWARDS), LocaleColBackwar
Assert::same($locale->getKeyword(LocaleKeyword::COL_CASE_FIRST), LocaleColCaseFirst::LOWER);
Assert::null($locale->getKeyword('foo'));

// getCurrency()

getCurrency:
Assert::same($locale->getCurrency(), Currency::get(Currency::CZECH_KORUNA));
Assert::null($simple->getCurrency());

// getNumbers()

getNumbers:
Assert::same($locale->getNumbers(), LocaleNumbers::get(LocaleNumbers::ARABIC_INDIC));
Assert::null($simple->getNumbers());

// getCalendar()

getCalendar:
Assert::same($locale->getCalendar(), LocaleCalendar::get(LocaleCalendar::ISO8601));
Assert::null($simple->getCalendar());

// getCollation()

getCollation:
Assert::same($locale->getCollation(), LocaleCollation::get(LocaleCollation::PHONEBOOK));
Assert::null($simple->getCollation());

// getCollationOptions()

getCollationOptions:
Assert::same($locale->getCollationOptions(), [
LocaleKeyword::COL_BACKWARDS => LocaleColBackwards::get(LocaleColBackwards::YES),
LocaleKeyword::COL_CASE_FIRST => LocaleColCaseFirst::get(LocaleColCaseFirst::LOWER),
Expand Down
Loading

0 comments on commit d911bfc

Please sign in to comment.