Skip to content

Commit 5f59627

Browse files
committed
Add tests.
1 parent f9273e4 commit 5f59627

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

Tests/FoundationMacrosTests/PredicateMacroFunctionCallTests.swift

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,80 @@ 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+
// Ensure key path methods and initializers are correctly handled in filter.
350+
AssertPredicateExpansion(
351+
"""
352+
#Predicate<Object> { inputA in
353+
inputA.filter(\\.method())
354+
}
355+
""",
356+
"""
357+
\(foundationModuleName).Predicate<Object>({ inputA in
358+
PredicateExpressions.build_filter(
359+
PredicateExpressions.build_Arg(inputA),
360+
{
361+
PredicateExpressions.build_KeyPath(
362+
root: PredicateExpressions.build_Arg($0),
363+
keyPath: \\.method
364+
)
365+
}
366+
)
367+
})
368+
"""
369+
)
370+
371+
AssertPredicateExpansion(
372+
"""
373+
#Predicate<Object> { inputA in
374+
inputA.filter(\\.method().description)
375+
}
376+
""",
377+
"""
378+
\(foundationModuleName).Predicate<Object>({ inputA in
379+
PredicateExpressions.build_filter(
380+
PredicateExpressions.build_Arg(inputA),
381+
{
382+
PredicateExpressions.build_KeyPath(
383+
root: PredicateExpressions.build_Arg($0),
384+
keyPath: \\.method
385+
)
386+
}
387+
)
388+
})
389+
"""
390+
)
391+
392+
AssertPredicateExpansion(
393+
"""
394+
#Predicate<Object> { inputA in
395+
inputA.filter(\\Object.init(val:))
396+
}
397+
""",
398+
"""
399+
\(foundationModuleName).Predicate<Object>({ inputA in
400+
PredicateExpressions.build_filter(
401+
PredicateExpressions.build_Arg(inputA),
402+
{
403+
PredicateExpressions.build_KeyPath(
404+
root: PredicateExpressions.build_Arg($0),
405+
keyPath: \\.init(val:)
406+
)
407+
}
408+
)
409+
})
410+
"""
411+
)
412+
413+
// Unsupported key path methods should produce diagnostics.
414+
AssertPredicateExpansion(
415+
"""
416+
#Predicate<Object> { inputA in
417+
inputA.filter(\\Object.method<Int>())
418+
}
419+
""",
420+
diagnostics: ["2:19: This key path is not supported here in this predicate."]
421+
)
348422
}
349423

350424
func testStartsWith() {

0 commit comments

Comments
 (0)