Skip to content

Commit b327dbe

Browse files
committed
test: add tests for canonicalized options and caseFirst
1 parent f9d7afd commit b327dbe

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

NOTICE

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use of which is hereby acknowledged.
66
Test262: ECMAScript Test Suite
77

88
Copyright (c) 2011, 2012 Norbert Lindenberg. All rights reserved.
9-
Copyright (c) 2012, 2013, 2016 Mozilla Corporation. All rights reserved.
9+
Copyright (c) 2012, 2013, 2016, 2020 Mozilla Corporation. All rights reserved.
1010
Copyright (c) 2017, 2020, 2021 André Bargull. All rights reserved.
1111
Copyright (c) 2018 André Bargull; Igalia, S.L. All rights reserved.
1212
Copyright (c) 2018 Igalia, S.L. All rights reserved.

tests/intl402/Locale/Options/prototype/prop-desc.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@
4444
$names = array_map(fn (ReflectionNamedType $type): string => $type->getName(), $types);
4545
sort($names);
4646

47+
$expected = ['Stringable', 'null', 'string'];
48+
if ($name === 'caseFirst') {
49+
$expected = ['Stringable', 'false', 'null', 'string'];
50+
}
51+
4752
expect($names)
48-
->toBe(['Stringable', 'null', 'string']);
53+
->toBe($expected);
4954
};
5055

5156
it('is public')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale;
6+
use Ecma\Intl\Locale\Options;
7+
8+
$keyValueTests = [
9+
[
10+
'key' => 'ca',
11+
'option' => 'calendar',
12+
'tests' => [
13+
['islamicc', 'islamic-civil'],
14+
['ethiopic-amete-alem', 'ethioaa'],
15+
],
16+
],
17+
];
18+
19+
it('converts values provided as options to canonical form', function (
20+
string $key,
21+
string $option,
22+
array $tests,
23+
) {
24+
foreach ($tests as $test) {
25+
[$noncanonical, $canonical] = $test;
26+
27+
$canonicalInLocale = new Locale("en-u-$key-$canonical");
28+
29+
expect($canonicalInLocale->{$option})
30+
->toBe($canonical);
31+
32+
$canonicalInOption = new Locale('en', new Options(...[$option => $canonical]));
33+
34+
expect($canonicalInOption->{$option})
35+
->toBe($canonical);
36+
37+
$noncanonicalInLocale = new Locale("en-u-$key-$noncanonical");
38+
39+
expect($noncanonicalInLocale->{$option})
40+
->toBe($canonical);
41+
42+
$noncanonicalInOption = new Locale('en', new Options(...[$option => $noncanonical]));
43+
44+
expect($noncanonicalInOption->{$option})
45+
->toBe($canonical);
46+
}
47+
})->with($keyValueTests);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale;
6+
use Ecma\Intl\Locale\Options;
7+
8+
$invalidCaseFirstOptions = [
9+
'',
10+
'u',
11+
'Upper',
12+
'Lower',
13+
'upper ',
14+
'uppercase',
15+
' lower',
16+
'true',
17+
];
18+
19+
it('throws ValueError for invalid caseFirst options', function (string $test): void {
20+
expect(fn () => new Locale('en', new Options(caseFirst: $test)))
21+
->toThrow(ValueError::class);
22+
})->with($invalidCaseFirstOptions);
23+
24+
it('throws TypeError for boolean true', function (): void {
25+
expect(fn () => new Locale('en', new Options(caseFirst: true)))
26+
->toThrow(TypeError::class);
27+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale;
6+
use Ecma\Intl\Locale\Options;
7+
8+
$validCaseFirstOptions = [
9+
'upper',
10+
'lower',
11+
'false',
12+
false,
13+
];
14+
15+
it('sets caseFirst options on the locale', function (string | false $test): void {
16+
$expected = is_bool($test) ? 'false' : $test;
17+
$expect = "en-u-kf-$expected";
18+
19+
$locale = new Locale('en', new Options(caseFirst: $test));
20+
expect((string) $locale)->toBe($expect);
21+
22+
$locale = new Locale('en-u-kf-lower', new Options(caseFirst: $test));
23+
expect((string) $locale)->toBe($expect);
24+
25+
$locale = new Locale('en-u-kf-upper', new Options(caseFirst: $test));
26+
expect($locale->caseFirst)->toBe($expected);
27+
})->with($validCaseFirstOptions);

0 commit comments

Comments
 (0)