mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-23 02:29:34 +00:00
Added more tests for parameter parsing
This commit is contained in:
parent
ff03f8217a
commit
6f295ce7fb
2 changed files with 30 additions and 0 deletions
|
|
@ -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).
|
||||
* 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|float $value
|
||||
* @param string|null $unit
|
||||
|
|
|
|||
|
|
@ -192,6 +192,33 @@ class ParameterDTOTest extends TestCase
|
|||
'm',
|
||||
'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'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue