From 16a25f218dd0fa2e9b5111eea57968463d4471a6 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Tue, 21 Jun 2022 10:01:18 -0700 Subject: [PATCH] Unconditionally print a regex block for concatenations fix test --- .../_StringProcessing/PrintAsPattern.swift | 17 ++++++++++++---- Tests/RegexTests/RenderDSLTests.swift | 20 +++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Sources/_StringProcessing/PrintAsPattern.swift b/Sources/_StringProcessing/PrintAsPattern.swift index 5e4347f3b..2fe7c6ccc 100644 --- a/Sources/_StringProcessing/PrintAsPattern.swift +++ b/Sources/_StringProcessing/PrintAsPattern.swift @@ -71,8 +71,15 @@ extension PrettyPrinter { print("let \(namedCapture) = Reference(Substring.self)") } - printBlock("Regex") { printer in - printer.printAsPattern(convertedFromAST: node) + switch node { + case .concatenation(_): + printAsPattern(convertedFromAST: node) + case .convertedRegexLiteral(.concatenation(_), _): + printAsPattern(convertedFromAST: node) + default: + printBlock("Regex") { printer in + printer.printAsPattern(convertedFromAST: node) + } } } @@ -99,8 +106,10 @@ extension PrettyPrinter { } case let .concatenation(c): - c.forEach { - printAsPattern(convertedFromAST: $0) + printBlock("Regex") { printer in + c.forEach { + printer.printAsPattern(convertedFromAST: $0) + } } case let .nonCapturingGroup(kind, child): diff --git a/Tests/RegexTests/RenderDSLTests.swift b/Tests/RegexTests/RenderDSLTests.swift index 75f6d2974..7bf8ba412 100644 --- a/Tests/RegexTests/RenderDSLTests.swift +++ b/Tests/RegexTests/RenderDSLTests.swift @@ -97,19 +97,17 @@ extension RenderDSLTests { } """) - try XCTExpectFailure("Concatenations in alternations aren't grouped") { - try testConversion(#"\da|b"#, """ - Regex { - ChoiceOf { - Regex { - .digit - "a" - } - "bc" + try testConversion(#"\da|bc"#, """ + Regex { + ChoiceOf { + Regex { + One(.digit) + "a" } + "bc" } - """) - } + } + """) } func testQuoting() throws {