From a786418e19b1410734958ee807366c2a1c02a156 Mon Sep 17 00:00:00 2001 From: David Richardson Date: Thu, 13 Aug 2026 16:42:57 -0600 Subject: [PATCH] Add test for @accessors(copy) @accessors(copy) had no test in ./Tests. The compiler's copy-accessor setter behaviour was unverified. Add CopyAccessorTest.j to Tests/Objective-J. It asserts three properties of the generated setter: - the stored value is not identical to the assigned object - the stored value is unaffected by later mutation of the original - the stored value is equal in content to the original at assignment This is added both as a matter of good coverage for the existing toolchain and so that new tooling has a reference for a piece of foundational behaviour. --- Tests/Objective-J/CopyAccessorTest.j | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Tests/Objective-J/CopyAccessorTest.j diff --git a/Tests/Objective-J/CopyAccessorTest.j b/Tests/Objective-J/CopyAccessorTest.j new file mode 100644 index 000000000..7c8374967 --- /dev/null +++ b/Tests/Objective-J/CopyAccessorTest.j @@ -0,0 +1,48 @@ +@import + +@implementation CopyAccessorTestClass : CPObject +{ + CPMutableArray ivar @accessors(copy); +} + +@end + +@implementation CopyAccessorTest : OJTestCase +{ + CopyAccessorTestClass testClass; +} + +- (void)setUp +{ + testClass = [[CopyAccessorTestClass alloc] init]; +} + +- (void)testCopyAccessorStoresDistinctObject +{ + var original = [@"a", @"b"]; + + [testClass setIvar:original]; + + [self assertFalse:[testClass ivar] === original]; +} + +- (void)testCopyAccessorIsUnaffectedByLaterMutation +{ + var original = [@"a", @"b"]; + + [testClass setIvar:original]; + [original addObject:@"c"]; + + [self assert:2 equals:[[testClass ivar] count]]; +} + +- (void)testCopyAccessorPreservesContentAtAssignment +{ + var original = [@"a", @"b"]; + + [testClass setIvar:original]; + + [self assert:original equals:[testClass ivar]]; +} + +@end