This commit allows for parameters that does not require any arguments to be provided in function calls. It changes collection syntax where parameters are list of objects instead of primitive strings. A parameter has now 'name' and 'optional' properties. 'name' is required and used in same way as older strings as parameter definitions. 'Optional' property is optional, 'false' is the default behavior if undefined. It also adds additional validation to restrict parameter names to alphanumeric strings to have a clear syntax in expressions.
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import 'mocha';
|
|
import { expect } from 'chai';
|
|
import { FunctionCallArgument } from '@/application/Parser/Script/Compiler/FunctionCall/Argument/FunctionCallArgument';
|
|
import { testParameterName } from '../../ParameterNameTestRunner';
|
|
|
|
describe('FunctionCallArgument', () => {
|
|
describe('ctor', () => {
|
|
describe('parameter name', () => {
|
|
testParameterName(
|
|
(parameterName) => new FunctionCallArgumentBuilder()
|
|
.withParameterName(parameterName)
|
|
.build()
|
|
.parameterName,
|
|
);
|
|
});
|
|
it('throws if argument value is undefined', () => {
|
|
// arrange
|
|
const parameterName = 'paramName';
|
|
const expectedError = `undefined argument value for "${parameterName}"`;
|
|
const argumentValue = undefined;
|
|
// act
|
|
const act = () => new FunctionCallArgumentBuilder()
|
|
.withParameterName(parameterName)
|
|
.withArgumentValue(argumentValue)
|
|
.build();
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
});
|
|
|
|
class FunctionCallArgumentBuilder {
|
|
private parameterName = 'default-parameter-name';
|
|
private argumentValue = 'default-argument-value';
|
|
public withParameterName(parameterName: string) {
|
|
this.parameterName = parameterName;
|
|
return this;
|
|
}
|
|
public withArgumentValue(argumentValue: string) {
|
|
this.argumentValue = argumentValue;
|
|
return this;
|
|
}
|
|
public build() {
|
|
return new FunctionCallArgument(this.parameterName, this.argumentValue);
|
|
}
|
|
}
|