Fix tests for ParameterSubstitutionParser

Fix nested mocha "it"s and "different parameters" test having wrong expectation
and add a test for whitespace tolerance.
This commit is contained in:
undergroundwires
2021-08-25 17:15:54 +01:00
parent 1c6b3057ea
commit 2a08855e5d

View File

@@ -5,17 +5,25 @@ import { ExpressionPosition } from '@/application/Parser/Script/Compiler/Express
import { ExpressionArguments } from '@/application/Parser/Script/Compiler/Expressions/Expression/IExpression'; import { ExpressionArguments } from '@/application/Parser/Script/Compiler/Expressions/Expression/IExpression';
describe('ParameterSubstitutionParser', () => { describe('ParameterSubstitutionParser', () => {
it('finds at expected positions', () => { describe('finds at expected positions', () => {
// arrange // arrange
const testCases = [ { const testCases = [
name: 'single parameter', {
name: 'matches single parameter',
code: '{{ $parameter }}!', code: '{{ $parameter }}!',
expected: [ new ExpressionPosition(0, 16) ], expected: [new ExpressionPosition(0, 16)],
}, { },
name: 'different parameters', {
name: 'matches different parameters',
code: 'He{{ $firstParameter }} {{ $secondParameter }}!!', code: 'He{{ $firstParameter }} {{ $secondParameter }}!!',
expected: [ new ExpressionPosition(2, 23), new ExpressionPosition(24, 46) ], expected: [new ExpressionPosition(2, 23), new ExpressionPosition(24, 46)],
}]; },
{
name: 'tolerates spaces around brackets',
code: 'He{{$firstParameter}}!!',
expected: [new ExpressionPosition(2, 21) ],
},
];
for (const testCase of testCases) { for (const testCase of testCases) {
it(testCase.name, () => { it(testCase.name, () => {
const sut = new ParameterSubstitutionParser(); const sut = new ParameterSubstitutionParser();
@@ -27,7 +35,7 @@ describe('ParameterSubstitutionParser', () => {
}); });
} }
}); });
it('evaluates as expected', () => { describe('evaluates as expected', () => {
const testCases = [ { const testCases = [ {
name: 'single parameter', name: 'single parameter',
code: '{{ $parameter }}', code: '{{ $parameter }}',
@@ -45,7 +53,7 @@ describe('ParameterSubstitutionParser', () => {
value: 'Hello', value: 'Hello',
}, },
{ {
name: 'firstParameter', name: 'secondParameter',
value: 'World', value: 'World',
}], }],
expected: [ 'Hello', 'World' ], expected: [ 'Hello', 'World' ],