Skip to content

Commit

Permalink
Simplify logic to exclude empty strings
Browse files Browse the repository at this point in the history
Signed-off-by: Zabil Cheriya Maliackal <[email protected]>
  • Loading branch information
zabil committed Oct 10, 2024
1 parent 918d7e1 commit 910e614
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions e2e/specs/parameters.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

## Custom Parameters in steps

* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}"
* This step checks if strings with numbers for example "3 % 4" is correct
* Convert custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}"
* Check strings with numbers for example "3 % 4" is correct
8 changes: 3 additions & 5 deletions e2e/tests/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ export default class Parameter {
assert.strictEqual(original.trim(), expected);
}

@Step("This step uses a custom parameter of type Person and value <person>")
@Step("Convert custom parameter of type Person and value <person>")
public async validatePerson(person: Person) {
assert.strictEqual(person.name, "John");
assert.strictEqual(person.age, 30);
assert.ok(person.isAdult());
}
@Step(
"This step checks if strings with numbers for example <value> is correct",
)
async setFilter(value: string) {
@Step("Check strings with numbers for example <value> is correct")
async checkStringConversion(value: string) {
assert.strictEqual(value, "3 % 4");
}
}
9 changes: 4 additions & 5 deletions gauge-ts/src/processors/params/PrimitiveParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ export class PrimitiveParser implements ParameterParser {
}

private convertToNumber(value: string): number | undefined {
const trimmedValue = value.trim();
if (/^-?\d+(\.\d+)?$/.test(trimmedValue)) {
const num = Number.parseFloat(trimmedValue);
return Number.isFinite(num) ? num : undefined;
if (value.trim() === "") {
return undefined;
}
return undefined;
const num = Number(value);
return Number.isFinite(num) ? num : undefined;
}

private convertToBoolean(value: string): boolean | undefined {
Expand Down

0 comments on commit 910e614

Please sign in to comment.