Added more tests for parameter parsing

This commit is contained in:
Jan Böhmer 2024-04-15 22:31:19 +02:00
parent ff03f8217a
commit 6f295ce7fb
2 changed files with 30 additions and 0 deletions

View file

@ -45,6 +45,9 @@ class ParameterDTO
/** /**
* This function tries to decide on the value, if it is a numerical value (which is then stored in one of the value_*) fields) or a text value (which is stored in value_text). * This function tries to decide on the value, if it is a numerical value (which is then stored in one of the value_*) fields) or a text value (which is stored in value_text).
* It is possible to give ranges like 1...2 (or 1~2) here, which will be parsed as value_min: 1.0, value_max: 2.0. * It is possible to give ranges like 1...2 (or 1~2) here, which will be parsed as value_min: 1.0, value_max: 2.0.
*
* For certain expressions (like ranges) the unit is automatically extracted from the value, if no unit is given
* @TODO Rework that, so that the difference between parseValueField and parseValueIncludingUnit is clearer or merge them
* @param string $name * @param string $name
* @param string|float $value * @param string|float $value
* @param string|null $unit * @param string|null $unit

View file

@ -192,6 +192,33 @@ class ParameterDTOTest extends TestCase
'm', 'm',
'test' 'test'
]; ];
//Test ranges with tilde
yield [
new ParameterDTO('test', value_min: -1.0, value_max: 2.0, unit: 'kg', symbol: 'm', group: 'test'),
'test',
'-1.0kg~+2.0kg', //Leading signs are parsed correctly
'm',
'test'
];
//Test @comment
yield [
new ParameterDTO('test', value_text: "@comment", value_typ: 1.0, unit: 'kg', symbol: 'm', group: 'test'),
'test',
'1.0 kg@comment',
'm',
'test'
];
//Test plus minus range (without unit)
yield [
new ParameterDTO('test', value_min: -1.0, value_max: +1.0, unit: 'kg', symbol: 'm', group: 'test'),
'test',
'±1.0 kg',
'm',
'test'
];
} }
/** /**