Skip to content

Commit

Permalink
test: add unit tests for toLocaleString()
Browse files Browse the repository at this point in the history
  • Loading branch information
xanaDev committed Oct 16, 2022
1 parent 3e3b87b commit fbf2e51
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/ArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,48 @@
expect($result->length())->toEqual(4);
expect($result->arr())->toEqual([2, 4, 6, 8]);
});

it('tests setLocaleString() returns an empty string for empty array', function () {
$arr = Arr::make([]);

$result = $arr->toLocaleString();
expect($result)
->toBeString()
->toEqual('');
});

it("tests setLocaleString() returns a string representing the elements of the array", function () {
$arr = Arr::make(['🥝', '🍎', 'I_DONT_KNOW', 1, 2, 3]);

$result = $arr->toLocaleString();
expect($result)
->toBeString()
->toEqual('🥝,🍎,I_DONT_KNOW,1,2,3');
});

it("tests setLocaleString() transforms dates and numbers using default locale and timezone", function () {
$arr = Arr::make([-123897.23, +123456.03, 'a', '2022-10-01']);

$result = $arr->toLocaleString(); // 'en_US.utf8', 'UTC'
expect($result)
->toBeString()
->toEqual('-123,897.23,123,456.03,a,Sat 01 Oct 2022 12:00:00 AM UTC');
});

it("tests setLocaleString() transforms dates and numbers using provided locale and timezone", function () {
$arr = Arr::make([-123897.23, +123456.03, 'a', '2022-10-01']);

$result = $arr->toLocaleString('fr_FR.utf8', 'Europe/Paris');
expect($result)
->toBeString()
->toEqual('-123 897,23,123 456,03,a,sam. 01 oct. 2022 00:00:00');
});

it("tests setLocaleString() skips nulls and invalid dates", function () {
$arr = Arr::make(['product', 123456.4, null, '2020-14-14']);

$result = $arr->toLocaleString();
expect($result)
->toBeString()
->toEqual('product,123,456.40,,2020-14-14');
});

0 comments on commit fbf2e51

Please sign in to comment.