-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enhance step parameter types #5 * Pass correct instance to hooks #138 --------- Signed-off-by: BugDiver <[email protected]>
- Loading branch information
Showing
22 changed files
with
335 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"files.associations": { | ||
"*.spec": "gauge", | ||
"*.cpt": "gauge" | ||
}, | ||
"files.autoSave": "afterDelay", | ||
"files.autoSaveDelay": 500, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"files": { | ||
"ignore": [ | ||
"dist/**", | ||
"coverage/**", | ||
"node_modules", | ||
"src/gen", | ||
".vscode", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export class Person { | ||
name: string; | ||
age: number; | ||
constructor(name: string, age: number) { | ||
this.name = name; | ||
this.age = age; | ||
} | ||
|
||
public isAdult(): boolean { | ||
return this.age >= 18; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Person } from "@lib/Person"; | ||
import type { Parameter, ParameterParser } from "gauge-ts"; | ||
export default class PersonParameterParser implements ParameterParser { | ||
public canParse(parameter: Parameter): boolean { | ||
return ( | ||
parameter.getValue().startsWith("{") && parameter.getValue().endsWith("}") | ||
); | ||
} | ||
|
||
public parse(parameter: Parameter): Person { | ||
const person = JSON.parse(parameter.getValue()); | ||
return new Person(person.name, person.age); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Parameter } from "../../gen/spec_pb"; | ||
|
||
export interface ParameterParser { | ||
canParse(parameter: Parameter): boolean; | ||
parse(parameter: Parameter): unknown; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Parameter } from "../../gen/spec_pb"; | ||
import type { ParameterParser } from "./ParameterParser"; | ||
import { PrimitiveParser } from "./PrimitiveParser"; | ||
import { TableParameterParser } from "./TableParameterParser"; | ||
|
||
export class ParameterParsingChain { | ||
private chain: Array<ParameterParser> = []; | ||
|
||
public constructor() { | ||
this.chain.push(new TableParameterParser()); | ||
this.chain.push(new PrimitiveParser()); | ||
} | ||
|
||
public parse(parameter: Parameter): unknown { | ||
for (const parser of this.chain) { | ||
if (parser.canParse(parameter)) { | ||
return parser.parse(parameter); | ||
} | ||
} | ||
return parameter.getValue(); | ||
} | ||
|
||
public addCustomParser(parser: ParameterParser): void { | ||
this.chain.unshift(parser); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { Parameter } from "../../gen/spec_pb"; | ||
import type { ParameterParser } from "./ParameterParser"; | ||
|
||
type ConvertFunction = (value: string) => unknown | undefined; | ||
|
||
export class PrimitiveParser implements ParameterParser { | ||
public readonly converters: ConvertFunction[] = []; | ||
|
||
constructor() { | ||
this.converters.push(this.convertToNumber); | ||
this.converters.push(this.convertToBoolean); | ||
} | ||
|
||
public canParse(parameter: Parameter): boolean { | ||
return true; | ||
} | ||
|
||
public parse(parameter: Parameter): unknown { | ||
const paramValue = parameter.getValue(); | ||
for (const converter of this.converters) { | ||
const v = converter(paramValue); | ||
if (v !== undefined) { | ||
return v; | ||
} | ||
} | ||
return paramValue; | ||
} | ||
|
||
private convertToNumber(value: string): number | undefined { | ||
const num = Number(value); | ||
return Number.isNaN(num) ? undefined : num; | ||
} | ||
|
||
private convertToBoolean(value: string): boolean | undefined { | ||
return value === "true" || value === "false" ? value === "true" : undefined; | ||
} | ||
} |
Oops, something went wrong.