Add divide by zero test

This commit is contained in:
TJ Miller 2023-03-09 15:18:57 -08:00
parent 0b951fb6a4
commit 16997769e0
2 changed files with 27 additions and 0 deletions

View File

@ -36,3 +36,21 @@ a: 4.8
b: 2.5 b: 2.5
``` ```
## Number division by zero
Dividing by zero results in +Inf or -Inf
Given a sample.yml file of:
```yaml
a: 1
b: -1
```
then
```bash
yq '.a = .a / 0 | .b = .b / 0' sample.yml
```
will output
```yaml
a: !!float +Inf
b: !!float -Inf
```

View File

@ -39,6 +39,15 @@ var divideOperatorScenarios = []expressionScenario{
"D0, P[], (doc)::{a: 4.8, b: 2.5}\n", "D0, P[], (doc)::{a: 4.8, b: 2.5}\n",
}, },
}, },
{
description: "Number division by zero",
subdescription: "Dividing by zero results in +Inf or -Inf",
document: `{a: 1, b: -1}`,
expression: `.a = .a / 0 | .b = .b / 0`,
expected: []string{
"D0, P[], (doc)::{a: !!float +Inf, b: !!float -Inf}\n",
},
},
{ {
skipDoc: true, skipDoc: true,
description: "Custom types: that are really strings", description: "Custom types: that are really strings",