Skip to content

Commit 3009cf2

Browse files
committed
Don't expand ntpdate into two subexpressions, we all know what ! means
1 parent 1a84ca2 commit 3009cf2

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Sources/TestingMacros/Support/ConditionArgumentParsing.swift

+6
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ private final class _ContextInserter<C, M>: SyntaxRewriter where C: MacroExpansi
427427
}
428428
}
429429

430+
if node.operator.tokenKind == .prefixOperator("!") {
431+
// Do not break apart the boolean negation operator from its expression
432+
// (it adds visual noise but is really just flipping a bit.)
433+
return _rewrite(node)
434+
}
435+
430436
return _rewrite(
431437
node
432438
.with(\.expression, _visitChild(node.expression)),

Tests/SubexpressionShowcase/SubexpressionShowcase.swift

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func subexpressionShowcase() async throws {
4343
#expect((123, 456) == (789, 0x12))
4444
#expect((try g() > 500) && true)
4545

46+
#expect(!Bool(true))
47+
4648
do {
4749
let n = Int.random(in: 0 ..< 100)
4850
var m = n

Tests/TestingMacrosTests/ConditionMacroTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct ConditionMacroTests {
3737
##"#expect("a" == "b")"##:
3838
##"Testing.__checkCondition({ (__ec: inout Testing.__ExpectationContext) -> Swift.Bool in __ec.__cmp({ $0 == $1 }, 0x0, "a", 0x2, "b", 0x200) }, sourceCode: [0x0: #""a" == "b""#], comments: [], isRequired: false, sourceLocation: Testing.SourceLocation.__here()).__expected()"##,
3939
##"#expect(!Bool.random())"##:
40-
##"Testing.__checkCondition({ (__ec: inout Testing.__ExpectationContext) -> Swift.Bool in __ec(!__ec(Bool.random(), 0x4), 0x0) }, sourceCode: [0x0: "!Bool.random()", 0x4: "Bool.random()"], comments: [], isRequired: false, sourceLocation: Testing.SourceLocation.__here()).__expected()"##,
40+
##"Testing.__checkCondition({ (__ec: inout Testing.__ExpectationContext) -> Swift.Bool in __ec(!Bool.random(), 0x0) }, sourceCode: [0x0: "!Bool.random()"], comments: [], isRequired: false, sourceLocation: Testing.SourceLocation.__here()).__expected()"##,
4141
##"#expect((true && false))"##:
4242
##"Testing.__checkCondition({ (__ec: inout Testing.__ExpectationContext) -> Swift.Bool in __ec((__ec(__ec(true, 0x3c) && __ec(false, 0x21c), 0x1c)), 0x0) }, sourceCode: [0x0: "(true && false)", 0x1c: "true && false", 0x3c: "true", 0x21c: "false"], comments: [], isRequired: false, sourceLocation: Testing.SourceLocation.__here()).__expected()"##,
4343
##"#expect(try x())"##:
@@ -118,7 +118,7 @@ struct ConditionMacroTests {
118118
##"#require("a" == "b")"##:
119119
##"Testing.__checkCondition({ (__ec: inout Testing.__ExpectationContext) -> Swift.Bool in try Testing.__requiringTry(__ec.__cmp({ $0 == $1 }, 0x0, "a", 0x2, "b", 0x200)) }, sourceCode: [0x0: #""a" == "b""#], comments: [], isRequired: true, sourceLocation: Testing.SourceLocation.__here()).__required()"##,
120120
##"#require(!Bool.random())"##:
121-
##"Testing.__checkCondition({ (__ec: inout Testing.__ExpectationContext) -> Swift.Bool in try Testing.__requiringTry(__ec(!__ec(Bool.random(), 0x4), 0x0)) }, sourceCode: [0x0: "!Bool.random()", 0x4: "Bool.random()"], comments: [], isRequired: true, sourceLocation: Testing.SourceLocation.__here()).__required()"##,
121+
##"Testing.__checkCondition({ (__ec: inout Testing.__ExpectationContext) -> Swift.Bool in try Testing.__requiringTry(__ec(!Bool.random(), 0x0)) }, sourceCode: [0x0: "!Bool.random()"], comments: [], isRequired: true, sourceLocation: Testing.SourceLocation.__here()).__required()"##,
122122
##"#require((true && false))"##:
123123
##"Testing.__checkCondition({ (__ec: inout Testing.__ExpectationContext) -> Swift.Bool in try Testing.__requiringTry(__ec((__ec(__ec(true, 0x3c) && __ec(false, 0x21c), 0x1c)), 0x0)) }, sourceCode: [0x0: "(true && false)", 0x1c: "true && false", 0x3c: "true", 0x21c: "false"], comments: [], isRequired: true, sourceLocation: Testing.SourceLocation.__here()).__required()"##,
124124
##"#require(try x())"##:

0 commit comments

Comments
 (0)