Move stubs from ./stubs to ./shared/Stubs
Gathers all shared test code in single place.
This commit is contained in:
29
tests/unit/shared/Stubs/PipeFactoryStub.ts
Normal file
29
tests/unit/shared/Stubs/PipeFactoryStub.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { IPipe } from '@/application/Parser/Script/Compiler/Expressions/Pipes/IPipe';
|
||||
import { IPipeFactory } from '@/application/Parser/Script/Compiler/Expressions/Pipes/PipeFactory';
|
||||
|
||||
export class PipeFactoryStub implements IPipeFactory {
|
||||
private readonly pipes = new Array<IPipe>();
|
||||
|
||||
public get(pipeName: string): IPipe {
|
||||
const result = this.pipes.find((pipe) => pipe.name === pipeName);
|
||||
if (!result) {
|
||||
throw new Error(`pipe not registered: "${pipeName}"`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public withPipe(pipe: IPipe) {
|
||||
if (!pipe) {
|
||||
throw new Error('missing pipe');
|
||||
}
|
||||
this.pipes.push(pipe);
|
||||
return this;
|
||||
}
|
||||
|
||||
public withPipes(pipes: IPipe[]) {
|
||||
for (const pipe of pipes) {
|
||||
this.withPipe(pipe);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user