Function EXACT(arg1, arg2) support (#595)

This commit is contained in:
Rolands Usāns 2018-07-15 05:56:25 +03:00 committed by Adrien Crivelli
parent 043327bb7d
commit eb31899225
5 changed files with 83 additions and 1 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added ### Added
- Add excel function EXACT(value1, value2) support
- Support workbook view attributes for Xlsx format - [#523](https://github.com/PHPOffice/PhpSpreadsheet/issues/523) - Support workbook view attributes for Xlsx format - [#523](https://github.com/PHPOffice/PhpSpreadsheet/issues/523)
### Fixed ### Fixed

View File

@ -752,7 +752,7 @@ class Calculation
], ],
'EXACT' => [ 'EXACT' => [
'category' => Category::CATEGORY_TEXT_AND_DATA, 'category' => Category::CATEGORY_TEXT_AND_DATA,
'functionCall' => [Functions::class, 'DUMMY'], 'functionCall' => [TextData::class, 'EXACT'],
'argumentCount' => '2', 'argumentCount' => '2',
], ],
'EXP' => [ 'EXP' => [

View File

@ -577,4 +577,22 @@ class TextData
return (float) $value; 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;
}
} }

View File

@ -359,4 +359,28 @@ class TextDataTest extends TestCase
{ {
return require 'data/Calculation/TextData/VALUE.php'; 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';
}
} }

View File

@ -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,
' ',
'',
],
];