From 6736af335e5470857f47bde9846e250e01ce2241 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 24 Jun 2022 14:14:11 +1000 Subject: [PATCH] fix(#222): escape single quotation marks in data tables --- CHANGELOG.md | 3 + .../integration_test/features/create.feature | 10 +- .../gherkin_suite_test.g.dart | 284 +++++++++--------- .../gherkin_suite_test_generator.dart | 5 +- pubspec.yaml | 2 +- 5 files changed, 154 insertions(+), 150 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a98b387..43d2db7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [3.0.0-rc.12] - 24/06/2022 + - Fix #222 - escape single quotation marks in data tables + ## [3.0.0-rc.11] - 24/06/2022 - Fix #231 - Removed the use of explicitly calling `pumpAndSettle` in the pre-defined steps in favour of the implicit `pumpAndSettle` calls used in the `WidgetTesterAppDriverAdapter`. - Added ability to add a `appLifecyclePumpHandler` to override the default handler that determines how the app is pumped during lifecycle events. Useful if your app has a long splash screen etc. Parameter is on `executeTestSuite`. diff --git a/example_with_integration_test/integration_test/features/create.feature b/example_with_integration_test/integration_test/features/create.feature index ff7a899..c5cd423 100644 --- a/example_with_integration_test/integration_test/features/create.feature +++ b/example_with_integration_test/integration_test/features/create.feature @@ -11,15 +11,15 @@ Feature: Creating todos Scenario: User can create multiple new todo items Given I fill the "todo" field with "Buy carrots" When I tap the "add" button - And I fill the "todo" field with "Buy apples" + And I fill the "todo" field with "Buy hannah's apples" When I tap the "add" button And I fill the "todo" field with "Buy blueberries" When I tap the "add" button Then I expect the todo list - | Todo | - | Buy blueberries | - | Buy apples | - | Buy carrots | + | Todo | + | Buy blueberries | + | Buy hannah's apples | + | Buy carrots | Given I wait 5 seconds for the animation to complete Given I have item with data """ diff --git a/example_with_integration_test/integration_test/gherkin_suite_test.g.dart b/example_with_integration_test/integration_test/gherkin_suite_test.g.dart index 35a4738..81f254d 100644 --- a/example_with_integration_test/integration_test/gherkin_suite_test.g.dart +++ b/example_with_integration_test/integration_test/gherkin_suite_test.g.dart @@ -27,6 +27,146 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner { } void testFeature0() { + runFeature( + name: 'Swiping:', + tags: ['@tag'], + run: () { + runScenario( + name: 'User can swipe cards left and right', + path: '.\\integration_test\\features\\swiping.feature', + tags: ['@tag', '@debug'], + steps: [ + ( + TestDependencies dependencies, + bool skip, + ) async { + return await runStep( + name: + 'Given I swipe right by 250 pixels on the "scrollable cards"`', + multiLineStrings: [], + table: null, + dependencies: dependencies, + skip: skip, + ); + }, + ( + TestDependencies dependencies, + bool skip, + ) async { + return await runStep( + name: 'Then I expect the text "Page 2" to be present', + multiLineStrings: [], + table: null, + dependencies: dependencies, + skip: skip, + ); + }, + ( + TestDependencies dependencies, + bool skip, + ) async { + return await runStep( + name: + 'Given I swipe left by 250 pixels on the "scrollable cards"`', + multiLineStrings: [], + table: null, + dependencies: dependencies, + skip: skip, + ); + }, + ( + TestDependencies dependencies, + bool skip, + ) async { + return await runStep( + name: 'Then I expect the text "Page 1" to be present', + multiLineStrings: [], + table: null, + dependencies: dependencies, + skip: skip, + ); + }, + ], + onBefore: () async => onBeforeRunFeature( + name: 'Swiping', + path: r'.\\integration_test\\features\\swiping.feature', + tags: ['@tag'], + ), + onAfter: () async => onAfterRunFeature( + name: 'Swiping', + path: r'.\\integration_test\\features\\swiping.feature', + tags: ['@tag'], + ), + ); + }, + ); + } + + void testFeature1() { + runFeature( + name: 'Checking data:', + tags: ['@tag'], + run: () { + runScenario( + name: 'User can have data', + path: '.\\integration_test\\features\\check.feature', + tags: ['@tag', '@tag1'], + steps: [ + ( + TestDependencies dependencies, + bool skip, + ) async { + return await runStep( + name: 'Given I have item with data', + multiLineStrings: [ + """{ + "glossary": { + "title": "example glossary", + "GlossDiv": { + "title": "S", + "GlossList": { + "GlossEntry": { + "ID": "SGML", + "SortAs": "SGML", + "GlossTerm": "Standard Generalized Markup Language", + "Acronym": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossDef": { + "para": "A meta-markup language, used to create markup languages such as DocBook.", + "GlossSeeAlso": [ + "GML", + "XML" + ] + }, + "GlossSee": "markup" + } + } + } + } +}""" + ], + table: null, + dependencies: dependencies, + skip: skip, + ); + }, + ], + onBefore: () async => onBeforeRunFeature( + name: 'Checking data', + path: r'.\\integration_test\\features\\check.feature', + tags: ['@tag'], + ), + onAfter: () async => onAfterRunFeature( + name: 'Checking data', + path: r'.\\integration_test\\features\\check.feature', + tags: ['@tag'], + ), + ); + }, + ); + } + + void testFeature2() { runFeature( name: 'Creating todos:', tags: ['@tag'], @@ -114,7 +254,7 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner { bool skip, ) async { return await runStep( - name: 'And I fill the "todo" field with "Buy apples"', + name: 'And I fill the "todo" field with "Buy hannah\'s apples"', multiLineStrings: [], table: null, dependencies: dependencies, @@ -165,7 +305,7 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner { name: 'Then I expect the todo list', multiLineStrings: [], table: GherkinTable.fromJson( - '[{"Todo":"Buy blueberries"},{"Todo":"Buy apples"},{"Todo":"Buy carrots"}]'), + '[{"Todo":"Buy blueberries"},{"Todo":"Buy hannah\'s apples"},{"Todo":"Buy carrots"}]'), dependencies: dependencies, skip: skip, ); @@ -230,146 +370,6 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner { }, ); } - - void testFeature1() { - runFeature( - name: 'Swiping:', - tags: ['@tag'], - run: () { - runScenario( - name: 'User can swipe cards left and right', - path: '.\\integration_test\\features\\swiping.feature', - tags: ['@tag', '@debug'], - steps: [ - ( - TestDependencies dependencies, - bool skip, - ) async { - return await runStep( - name: - 'Given I swipe right by 250 pixels on the "scrollable cards"`', - multiLineStrings: [], - table: null, - dependencies: dependencies, - skip: skip, - ); - }, - ( - TestDependencies dependencies, - bool skip, - ) async { - return await runStep( - name: 'Then I expect the text "Page 2" to be present', - multiLineStrings: [], - table: null, - dependencies: dependencies, - skip: skip, - ); - }, - ( - TestDependencies dependencies, - bool skip, - ) async { - return await runStep( - name: - 'Given I swipe left by 250 pixels on the "scrollable cards"`', - multiLineStrings: [], - table: null, - dependencies: dependencies, - skip: skip, - ); - }, - ( - TestDependencies dependencies, - bool skip, - ) async { - return await runStep( - name: 'Then I expect the text "Page 1" to be present', - multiLineStrings: [], - table: null, - dependencies: dependencies, - skip: skip, - ); - }, - ], - onBefore: () async => onBeforeRunFeature( - name: 'Swiping', - path: r'.\\integration_test\\features\\swiping.feature', - tags: ['@tag'], - ), - onAfter: () async => onAfterRunFeature( - name: 'Swiping', - path: r'.\\integration_test\\features\\swiping.feature', - tags: ['@tag'], - ), - ); - }, - ); - } - - void testFeature2() { - runFeature( - name: 'Checking data:', - tags: ['@tag'], - run: () { - runScenario( - name: 'User can have data', - path: '.\\integration_test\\features\\check.feature', - tags: ['@tag', '@tag1'], - steps: [ - ( - TestDependencies dependencies, - bool skip, - ) async { - return await runStep( - name: 'Given I have item with data', - multiLineStrings: [ - """{ - "glossary": { - "title": "example glossary", - "GlossDiv": { - "title": "S", - "GlossList": { - "GlossEntry": { - "ID": "SGML", - "SortAs": "SGML", - "GlossTerm": "Standard Generalized Markup Language", - "Acronym": "SGML", - "Abbrev": "ISO 8879:1986", - "GlossDef": { - "para": "A meta-markup language, used to create markup languages such as DocBook.", - "GlossSeeAlso": [ - "GML", - "XML" - ] - }, - "GlossSee": "markup" - } - } - } - } -}""" - ], - table: null, - dependencies: dependencies, - skip: skip, - ); - }, - ], - onBefore: () async => onBeforeRunFeature( - name: 'Checking data', - path: r'.\\integration_test\\features\\check.feature', - tags: ['@tag'], - ), - onAfter: () async => onAfterRunFeature( - name: 'Checking data', - path: r'.\\integration_test\\features\\check.feature', - tags: ['@tag'], - ), - ); - }, - ); - } } void executeTestSuite({ diff --git a/lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart b/lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart index 90384da..eaaa149 100644 --- a/lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart +++ b/lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart @@ -301,13 +301,14 @@ class FeatureFileTestGeneratorVisitor extends FeatureFileVisitor { code = _replaceVariable( code, 'step_multi_line_strings', - // '[${multiLineStrings.map((s) => "'${_escapeText(s)}'").join(',')}]', '[${multiLineStrings.map((s) => '"""$s"""').join(',')}]', ); code = _replaceVariable( code, 'step_table', - table == null ? 'null' : 'GherkinTable.fromJson(\'${table.toJson()}\')', + table == null + ? 'null' + : 'GherkinTable.fromJson(\'${_escapeText(table.toJson())}\')', ); _stepBuffer.writeln(code); diff --git a/pubspec.yaml b/pubspec.yaml index 68b59ae..9be8cf9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_gherkin description: A Gherkin / Cucumber parser and test runner for Dart and Flutter -version: 3.0.0-rc.11 +version: 3.0.0-rc.12 homepage: https://github.com/jonsamwell/flutter_gherkin environment: