1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// This test file has been translated from swift/test/Parse/pattern_without_variables.swift
@_spi(ExperimentalLanguageFeatures) import SwiftParser
import XCTest
final class PatternWithoutVariablesTests: ParserTestCase {
func testPatternWithoutVariables1() {
assertParse(
"""
let _ = 1
inout _ = 1
_mutating _ = 1
_borrowing _ = 1
_consuming _ = 1
""",
experimentalFeatures: .referenceBindings
)
}
func testPatternWithoutVariables2() {
assertParse(
"""
func foo() {
let _ = 1 // OK
inout _ = 1
_mutating _ = 1
_borrowing _ = 1
_consuming _ = 1
}
""",
experimentalFeatures: .referenceBindings
)
}
func testPatternWithoutVariables3() {
assertParse(
"""
struct Foo {
let _ = 1
var (_, _) = (1, 2)
func foo() {
let _ = 1 // OK
}
inout (_, _) = (1, 2)
_mutating (_, _) = (1, 2)
_borrowing (_, _) = (1, 2)
_consuming (_, _) = (1, 2)
}
""",
experimentalFeatures: .referenceBindings
)
}
func testPatternWithoutVariables4() {
assertParse(
#"""
// <rdar://problem/19786845> Warn on "let" and "var" when no data is bound in a pattern
enum SimpleEnum { case Bar }
"""#
)
}
func testPatternWithoutVariables5() {
assertParse(
#"""
func testVarLetPattern(a : SimpleEnum) {
switch a {
case let .Bar: break
}
switch a {
case let x: _ = x; break // Ok.
}
switch a {
case let _: break
}
switch (a, 42) {
case let (_, x): _ = x; break // ok
}
if case let _ = "str" {}
switch a {
case inout .Bar: break
}
switch a {
case _mutating .Bar: break
}
switch a {
case _borrowing .Bar: break
}
switch a {
case _consuming .Bar: break
}
}
"""#
)
}
func testPatternWithoutVariables6() {
assertParse(
"""
// https://github.com/apple/swift/issues/53293
class C_53293 {
static var _: Int { 0 }
}
"""
)
}
func testMutatingNotADeclarationStartIfNotEnabled() {
assertParse("_mutating = 2")
}
}
|