Move stubs from ./stubs to ./shared/Stubs
Gathers all shared test code in single place.
This commit is contained in:
24
tests/unit/shared/Stubs/SharedFunctionCollectionStub.ts
Normal file
24
tests/unit/shared/Stubs/SharedFunctionCollectionStub.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { ISharedFunction, FunctionBodyType } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
||||
import { ISharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionCollection';
|
||||
import { SharedFunctionStub } from './SharedFunctionStub';
|
||||
|
||||
export class SharedFunctionCollectionStub implements ISharedFunctionCollection {
|
||||
private readonly functions = new Map<string, ISharedFunction>();
|
||||
|
||||
public withFunction(...funcs: readonly ISharedFunction[]) {
|
||||
for (const func of funcs) {
|
||||
this.functions.set(func.name, func);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public getFunctionByName(name: string): ISharedFunction {
|
||||
if (this.functions.has(name)) {
|
||||
return this.functions.get(name);
|
||||
}
|
||||
return new SharedFunctionStub(FunctionBodyType.Code)
|
||||
.withName(name)
|
||||
.withCode('code by SharedFunctionCollectionStub')
|
||||
.withRevertCode('revert-code by SharedFunctionCollectionStub');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user