Skip to content

Commit ee2b8b2

Browse files
committed
Add tests.
1 parent 8c95430 commit ee2b8b2

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Tests/FoundationMacrosTests/PredicateMacroFunctionCallTests.swift

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,72 @@ final class PredicateMacroFunctionCallTests: XCTestCase {
345345
""",
346346
diagnostics: ["2:19: This key path is not supported here in this predicate. Use an explicit closure instead."]
347347
)
348+
349+
#if !FOUNDATION_FRAMEWORK
350+
// Ensure key path methods and initializers are correctly handled in filter.
351+
AssertPredicateExpansion(
352+
"""
353+
#Predicate<Object> { inputA in
354+
inputA.filter(\\.method())
355+
}
356+
""",
357+
"""
358+
\(foundationModuleName).Predicate<Object>({ inputA in
359+
PredicateExpressions.build_filter(
360+
PredicateExpressions.build_Arg(inputA),
361+
{
362+
PredicateExpressions.build_KeyPath(
363+
root: PredicateExpressions.build_Arg($0),
364+
keyPath: \\.method
365+
)
366+
}
367+
)
368+
})
369+
"""
370+
)
371+
372+
AssertPredicateExpansion(
373+
"""
374+
#Predicate<Object> { inputA in
375+
inputA.filter(\\.method().description)
376+
}
377+
""",
378+
"""
379+
\(foundationModuleName).Predicate<Object>({ inputA in
380+
PredicateExpressions.build_filter(
381+
PredicateExpressions.build_Arg(inputA),
382+
{
383+
PredicateExpressions.build_KeyPath(
384+
root: PredicateExpressions.build_Arg($0),
385+
keyPath: \\.method
386+
)
387+
}
388+
)
389+
})
390+
"""
391+
)
392+
393+
AssertPredicateExpansion(
394+
"""
395+
#Predicate<Object> { inputA in
396+
inputA.filter(\\Object.init(val:))
397+
}
398+
""",
399+
"""
400+
\(foundationModuleName).Predicate<Object>({ inputA in
401+
PredicateExpressions.build_filter(
402+
PredicateExpressions.build_Arg(inputA),
403+
{
404+
PredicateExpressions.build_KeyPath(
405+
root: PredicateExpressions.build_Arg($0),
406+
keyPath: \\.init(val:)
407+
)
408+
}
409+
)
410+
})
411+
"""
412+
)
413+
#endif
348414
}
349415

350416
func testStartsWith() {

0 commit comments

Comments
 (0)