-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix caseFirst issues and improve tests
- Loading branch information
Showing
9 changed files
with
209 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
--TEST-- | ||
Locale::$baseName is readonly | ||
Locale properties are readonly | ||
--EXTENSIONS-- | ||
ecma_intl | ||
--FILE-- | ||
<?php | ||
use Ecma\Intl\Locale; | ||
|
||
$locale = new Locale('cmn-hans-cn-u-ca-t-ca-x-t-u'); | ||
$properties = [ | ||
'baseName' => 'en-Latn-US', | ||
'calendar' => 'gregory', | ||
'caseFirst' => 'upper', | ||
'collation' => 'emoji', | ||
'hourCycle' => 'h23', | ||
'language' => 'en', | ||
'numberingSystem' => 'latn', | ||
'numeric' => true, | ||
'region' => 'US', | ||
'script' => 'Latn', | ||
]; | ||
|
||
$locale->baseName = 'foo'; | ||
$locale = new Locale('en'); | ||
|
||
foreach ($properties as $property => $value) { | ||
try { | ||
$locale->{$property} = $value; | ||
} catch (Error $error) { | ||
echo $error->getMessage() . "\n"; | ||
} | ||
} | ||
|
||
--EXPECTF-- | ||
Fatal error: Uncaught Error: Cannot modify readonly property Ecma\Intl\Locale::$baseName in %s/Intl/Locale-005.php:%d | ||
Stack trace: | ||
#0 {main} | ||
thrown in %s/Intl/Locale-005.php on line %d | ||
Cannot modify readonly property Ecma\Intl\Locale::$baseName | ||
Cannot modify readonly property Ecma\Intl\Locale::$calendar | ||
Cannot modify readonly property Ecma\Intl\Locale::$caseFirst | ||
Cannot modify readonly property Ecma\Intl\Locale::$collation | ||
Cannot modify readonly property Ecma\Intl\Locale::$hourCycle | ||
Cannot modify readonly property Ecma\Intl\Locale::$language | ||
Cannot modify readonly property Ecma\Intl\Locale::$numberingSystem | ||
Cannot modify readonly property Ecma\Intl\Locale::$numeric | ||
Cannot modify readonly property Ecma\Intl\Locale::$region | ||
Cannot modify readonly property Ecma\Intl\Locale::$script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
Locale can access each property | ||
--EXTENSIONS-- | ||
ecma_intl | ||
--FILE-- | ||
<?php | ||
use Ecma\Intl\Locale; | ||
|
||
$locale = new Locale('en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latn-kn'); | ||
|
||
var_dump($locale->baseName); | ||
var_dump($locale->calendar); | ||
var_dump($locale->caseFirst); | ||
var_dump($locale->collation); | ||
var_dump($locale->hourCycle); | ||
var_dump($locale->language); | ||
var_dump($locale->numberingSystem); | ||
var_dump($locale->numeric); | ||
var_dump($locale->region); | ||
var_dump($locale->script); | ||
|
||
--EXPECT-- | ||
string(10) "en-Latn-US" | ||
string(7) "gregory" | ||
string(5) "upper" | ||
string(5) "emoji" | ||
string(3) "h23" | ||
string(2) "en" | ||
string(4) "latn" | ||
bool(true) | ||
string(2) "US" | ||
string(4) "Latn" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--TEST-- | ||
Locale must have a valid value | ||
--EXTENSIONS-- | ||
ecma_intl | ||
--FILE-- | ||
<?php | ||
use Ecma\Intl\Locale; | ||
|
||
$tests = [ | ||
'', | ||
'e', | ||
'en-', | ||
'en-Lat', | ||
'en-Latn-', | ||
'en-Latn-USA', | ||
'en-Latn-US-', | ||
'en-Latn-US-u-ca-gregoryab', | ||
'en-Latn-US-u-ca-gregory-', | ||
'en-Latn-US-u-ca-gregory-kf-upperabcd', | ||
'en-Latn-US-u-ca-gregory-kf-upper-', | ||
'en-Latn-US-u-ca-gregory-kf-upper-co-emojiabcd', | ||
'en-Latn-US-u-ca-gregory-kf-upper-co-emoji-', | ||
'en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23abcdef', | ||
'en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-', | ||
'en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latnabcde', | ||
'en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latn-', | ||
'en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latn-kn-falseabcd', | ||
'en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latn-kn-false-', | ||
]; | ||
|
||
foreach ($tests as $test) { | ||
try { | ||
$loc = new Locale($test); | ||
echo json_encode($loc) . "\n"; | ||
} catch (ValueError $exception) { | ||
echo $exception->getMessage() . "\n"; | ||
} | ||
} | ||
|
||
--EXPECT-- | ||
Invalid language tag "" | ||
Invalid language tag "e" | ||
Invalid language tag "en-" | ||
Invalid language tag "en-Lat" | ||
Invalid language tag "en-Latn-" | ||
Invalid language tag "en-Latn-USA" | ||
Invalid language tag "en-Latn-US-" | ||
Invalid language tag "en-Latn-US-u-ca-gregoryab" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upperabcd" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-co-emojiabcd" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-co-emoji-" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23abcdef" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latnabcde" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latn-" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latn-kn-falseabcd" | ||
Invalid language tag "en-Latn-US-u-ca-gregory-kf-upper-co-emoji-hc-h23-nu-latn-kn-false-" |