Function EXACT(arg1, arg2) support (#595)
This commit is contained in:
parent
043327bb7d
commit
eb31899225
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
|
||||
### Added
|
||||
|
||||
- Add excel function EXACT(value1, value2) support
|
||||
- Support workbook view attributes for Xlsx format - [#523](https://github.com/PHPOffice/PhpSpreadsheet/issues/523)
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -752,7 +752,7 @@ class Calculation
|
|||
],
|
||||
'EXACT' => [
|
||||
'category' => Category::CATEGORY_TEXT_AND_DATA,
|
||||
'functionCall' => [Functions::class, 'DUMMY'],
|
||||
'functionCall' => [TextData::class, 'EXACT'],
|
||||
'argumentCount' => '2',
|
||||
],
|
||||
'EXP' => [
|
||||
|
|
|
@ -577,4 +577,22 @@ class TextData
|
|||
|
||||
return (float) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two text strings and returns TRUE if they are exactly the same, FALSE otherwise.
|
||||
* EXACT is case-sensitive but ignores formatting differences.
|
||||
* Use EXACT to test text being entered into a document.
|
||||
*
|
||||
* @param $value1
|
||||
* @param $value2
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function EXACT($value1, $value2)
|
||||
{
|
||||
$value1 = Functions::flattenSingleValue($value1);
|
||||
$value2 = Functions::flattenSingleValue($value2);
|
||||
|
||||
return (string) $value2 === (string) $value1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -359,4 +359,28 @@ class TextDataTest extends TestCase
|
|||
{
|
||||
return require 'data/Calculation/TextData/VALUE.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerEXACT
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
* @param array $args
|
||||
*/
|
||||
public function testEXACT($expectedResult, ...$args)
|
||||
{
|
||||
StringHelper::setDecimalSeparator('.');
|
||||
StringHelper::setThousandsSeparator(' ');
|
||||
StringHelper::setCurrencyCode('$');
|
||||
|
||||
$result = TextData::EXACT(...$args);
|
||||
self::assertSame($expectedResult, $result, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerEXACT()
|
||||
{
|
||||
return require 'data/Calculation/TextData/EXACT.php';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
true,
|
||||
'',
|
||||
'',
|
||||
],
|
||||
[
|
||||
true,
|
||||
'1000',
|
||||
1000,
|
||||
],
|
||||
[
|
||||
true,
|
||||
1000,
|
||||
'1000',
|
||||
],
|
||||
[
|
||||
true,
|
||||
'Abč',
|
||||
'Abč',
|
||||
],
|
||||
[
|
||||
false,
|
||||
'abč',
|
||||
'Abč',
|
||||
],
|
||||
[
|
||||
false,
|
||||
'10.010',
|
||||
10.01,
|
||||
],
|
||||
[
|
||||
false,
|
||||
' ',
|
||||
'',
|
||||
],
|
||||
];
|
Loading…
Reference in New Issue