From 2a08855e5d1bdf74354fd692cbfebd1a48e495ac Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Wed, 25 Aug 2021 17:15:54 +0100 Subject: [PATCH] Fix tests for `ParameterSubstitutionParser` Fix nested mocha "it"s and "different parameters" test having wrong expectation and add a test for whitespace tolerance. --- .../ParameterSubstitutionParser.spec.ts | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/unit/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.spec.ts b/tests/unit/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.spec.ts index f36b1104..b3b46eaa 100644 --- a/tests/unit/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.spec.ts +++ b/tests/unit/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.spec.ts @@ -5,17 +5,25 @@ import { ExpressionPosition } from '@/application/Parser/Script/Compiler/Express import { ExpressionArguments } from '@/application/Parser/Script/Compiler/Expressions/Expression/IExpression'; describe('ParameterSubstitutionParser', () => { - it('finds at expected positions', () => { + describe('finds at expected positions', () => { // arrange - const testCases = [ { - name: 'single parameter', + const testCases = [ + { + name: 'matches single parameter', code: '{{ $parameter }}!', - expected: [ new ExpressionPosition(0, 16) ], - }, { - name: 'different parameters', + expected: [new ExpressionPosition(0, 16)], + }, + { + name: 'matches different parameters', 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) { it(testCase.name, () => { const sut = new ParameterSubstitutionParser(); @@ -27,7 +35,7 @@ describe('ParameterSubstitutionParser', () => { }); } }); - it('evaluates as expected', () => { + describe('evaluates as expected', () => { const testCases = [ { name: 'single parameter', code: '{{ $parameter }}', @@ -45,7 +53,7 @@ describe('ParameterSubstitutionParser', () => { value: 'Hello', }, { - name: 'firstParameter', + name: 'secondParameter', value: 'World', }], expected: [ 'Hello', 'World' ],