Skip to content

Commit 8349b25

Browse files
authored
Merge pull request #4676 from augusto2112/regex-tests
[lldb] Add tests for Swift regex support
2 parents 936edc6 + 229bc99 commit 8349b25

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS := -Xfrontend -enable-bare-slash-regex -Xfrontend -disable-availability-checking
3+
4+
5+
include Makefile.rules
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# TestSwiftRegex.py
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ------------------------------------------------------------------------------
12+
"""
13+
Test Swift's regex support
14+
"""
15+
import lldb
16+
from lldbsuite.test.lldbtest import *
17+
from lldbsuite.test.decorators import *
18+
import lldbsuite.test.lldbutil as lldbutil
19+
20+
21+
class TestSwiftRegex(TestBase):
22+
mydir = TestBase.compute_mydir(__file__)
23+
24+
def setUp(self):
25+
TestBase.setUp(self)
26+
self.main_source = "main.swift"
27+
self.main_source_spec = lldb.SBFileSpec(self.main_source)
28+
29+
@swiftTest
30+
def test_swift_regex(self):
31+
"""Test Swift's regex support"""
32+
self.build()
33+
lldbutil.run_to_source_breakpoint(
34+
self, 'Set breakpoint here', self.main_source_spec)
35+
self.expect('v regex',
36+
substrs=['_StringProcessing.Regex<(Substring, Substring, Substring, Substring)>) regex = {'])
37+
self.expect('po regex',
38+
substrs=['Regex<(Substring, Substring, Substring, Substring)>'])
39+
40+
self.expect('v dslRegex',
41+
substrs=['(_StringProcessing.Regex<Substring>) dslRegex = {'])
42+
self.expect('po dslRegex',
43+
substrs=['Regex<Substring>'])
44+
45+
@swiftTest
46+
# Expected to fail because of availability checking while Regex support isn't stabilized
47+
@expectedFailureDarwin
48+
def test_swift_regex_in_exp(self):
49+
"""Test Swift's regex support"""
50+
self.build()
51+
lldbutil.run_to_source_breakpoint(
52+
self, 'Set breakpoint here', self.main_source_spec)
53+
self.runCmd(
54+
"settings set target.experimental.swift-enable-bare-slash-regex true")
55+
self.expect('e -- /Order from <(.*)>, type: (.*), count in dozen: ([0-9]+)/',
56+
substrs=['_StringProcessing.Regex<(Substring, Substring, Substring, Substring)>'])
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// main.swift
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
// -----------------------------------------------------------------------------
12+
import RegexBuilder
13+
14+
let regex = /Order from <(.*)>, type: (.*), count in dozen: ([0-9]+)/
15+
16+
let dslRegex = Regex { .digit }
17+
18+
print(regex) // Set breakpoint here
19+

lldb/test/Shell/SwiftREPL/Regex.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Test that we can use Swift's regex functionalities on the REPL.
2+
// REQUIRES: swift
3+
// XFAIL: system-darwin
4+
// This is expected to fail on macOS for now because Regex has an availability of 9999 (for now).
5+
6+
// RUN: %lldb --repl < %s | FileCheck %s
7+
8+
:settings set target.experimental.swift-enable-bare-slash-regex true
9+
let regex = /Order from <(.*)>, type: (.*), count in dozen: ([0-9]+)/
10+
// CHECK: _StringProcessing.Regex<(Substring, Substring, Substring, Substring)> =
11+
12+
import RegexBuilder
13+
let dslRegex = Regex { .digit }
14+
// CHECK: _StringProcessing.Regex<Substring> =

0 commit comments

Comments
 (0)