TextData Coverage and Minor Bug Fixes (#1744)
This had been intended to get 100% coverage for TextData functions, and it does that. However, some minor bugs requiring source changes arose during testing. - the Excel CHAR function restricts its argument to 1-255. PhpSpreadsheet CHARACTER had been allowing 0+. Also, there is no need to test if iconv exists, since it is part of Composer requirements. - The DOLLAR function had been returning NUM for invalid arguments. Excel returns VALUE. Also, negative amounts were not being handled correctly. - The FIXEDFORMAT function had been returning NUM for invalid arguments. Excel FIXED returns VALUE.
This commit is contained in:
parent
78774d6ac8
commit
957cb62dab
|
@ -27,15 +27,15 @@ class TextData
|
|||
{
|
||||
$character = Functions::flattenSingleValue($character);
|
||||
|
||||
if ((!is_numeric($character)) || ($character < 0)) {
|
||||
if (!is_numeric($character)) {
|
||||
return Functions::VALUE();
|
||||
}
|
||||
$character = (int) $character;
|
||||
if ($character < 1 || $character > 255) {
|
||||
return Functions::VALUE();
|
||||
}
|
||||
|
||||
if (function_exists('iconv')) {
|
||||
return iconv('UCS-4LE', 'UTF-8', pack('V', $character));
|
||||
}
|
||||
|
||||
return mb_convert_encoding('&#' . (int) $character . ';', 'UTF-8', 'HTML-ENTITIES');
|
||||
return iconv('UCS-4LE', 'UTF-8', pack('V', $character));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,7 +160,7 @@ class TextData
|
|||
|
||||
// Validate parameters
|
||||
if (!is_numeric($value) || !is_numeric($decimals)) {
|
||||
return Functions::NAN();
|
||||
return Functions::VALUE();
|
||||
}
|
||||
$decimals = floor($decimals);
|
||||
|
||||
|
@ -174,6 +174,7 @@ class TextData
|
|||
}
|
||||
$value = MathTrig::MROUND($value, $round);
|
||||
}
|
||||
$mask = "$mask;($mask)";
|
||||
|
||||
return NumberFormat::toFormattedString($value, $mask);
|
||||
}
|
||||
|
@ -265,7 +266,7 @@ class TextData
|
|||
|
||||
// Validate parameters
|
||||
if (!is_numeric($value) || !is_numeric($decimals)) {
|
||||
return Functions::NAN();
|
||||
return Functions::VALUE();
|
||||
}
|
||||
$decimals = (int) floor($decimals);
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ return [
|
|||
'#VALUE!',
|
||||
-5,
|
||||
],
|
||||
[
|
||||
'#VALUE!',
|
||||
0,
|
||||
],
|
||||
[
|
||||
'A',
|
||||
65,
|
||||
|
@ -22,27 +26,39 @@ return [
|
|||
126,
|
||||
],
|
||||
[
|
||||
'⽇',
|
||||
'Á',
|
||||
193,
|
||||
],
|
||||
[
|
||||
'ÿ',
|
||||
255,
|
||||
],
|
||||
[
|
||||
'#VALUE!',
|
||||
256,
|
||||
],
|
||||
[
|
||||
'#VALUE!', // '⽇',
|
||||
12103,
|
||||
],
|
||||
[
|
||||
'œ',
|
||||
'#VALUE!', // 'œ',
|
||||
0x153,
|
||||
],
|
||||
[
|
||||
'ƒ',
|
||||
'#VALUE!', // 'ƒ',
|
||||
0x192,
|
||||
],
|
||||
[
|
||||
'℅',
|
||||
'#VALUE!', // '℅',
|
||||
0x2105,
|
||||
],
|
||||
[
|
||||
'∑',
|
||||
'#VALUE!', // '∑',
|
||||
0x2211,
|
||||
],
|
||||
[
|
||||
'†',
|
||||
'#VALUE!', // '†',
|
||||
0x2020,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -6,11 +6,20 @@ return [
|
|||
123.456,
|
||||
2,
|
||||
],
|
||||
[
|
||||
'$123.46',
|
||||
123.456,
|
||||
],
|
||||
[
|
||||
'$123.32',
|
||||
123.321,
|
||||
2,
|
||||
],
|
||||
[
|
||||
'($123.32)',
|
||||
-123.321,
|
||||
2,
|
||||
],
|
||||
[
|
||||
'$1,235,000',
|
||||
1234567,
|
||||
|
@ -22,12 +31,17 @@ return [
|
|||
-5,
|
||||
],
|
||||
[
|
||||
'#NUM!',
|
||||
'($1,200,000)',
|
||||
-1234567,
|
||||
-5,
|
||||
],
|
||||
[
|
||||
'#VALUE!',
|
||||
'ABC',
|
||||
2,
|
||||
],
|
||||
[
|
||||
'#NUM!',
|
||||
'#VALUE!',
|
||||
123.456,
|
||||
'ABC',
|
||||
],
|
||||
|
|
|
@ -20,13 +20,41 @@ return [
|
|||
true,
|
||||
],
|
||||
[
|
||||
'#NUM!',
|
||||
'-123456.79',
|
||||
-123456.789,
|
||||
2,
|
||||
true,
|
||||
],
|
||||
[
|
||||
'123500',
|
||||
123456.789,
|
||||
-2,
|
||||
true,
|
||||
],
|
||||
[
|
||||
'123,500',
|
||||
123456.789,
|
||||
-2,
|
||||
],
|
||||
[
|
||||
'-123500',
|
||||
-123456.789,
|
||||
-2,
|
||||
true,
|
||||
],
|
||||
[
|
||||
'-123,500',
|
||||
-123456.789,
|
||||
-2,
|
||||
],
|
||||
[
|
||||
'#VALUE!',
|
||||
'ABC',
|
||||
2,
|
||||
null,
|
||||
],
|
||||
[
|
||||
'#NUM!',
|
||||
'#VALUE!',
|
||||
123.456,
|
||||
'ABC',
|
||||
null,
|
||||
|
|
|
@ -54,6 +54,11 @@ return [
|
|||
'Mark Baker',
|
||||
2,
|
||||
],
|
||||
[
|
||||
1,
|
||||
'',
|
||||
'Mark Baker',
|
||||
],
|
||||
[
|
||||
'#VALUE!',
|
||||
'BITE',
|
||||
|
|
Loading…
Reference in New Issue