Skip to content

Commit 80fe1b3

Browse files
valsongclaude
andcommitted
test: Add unit tests for MMFindBarView
- testFindBarShowWithFlags: verify that showWithText:flags: correctly maps the FRD bitmask to Ignore Case / Match Word checkbox states, covering flags 0x00, 0x08, 0x10, 0x18 and nil text handling - testFindBarPositionPreservedOnReshow: verify that the bar snaps to the top-right corner on first show, and that a subsequent call while already visible does not reset the user's dragged position Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b8ecf4e commit 80fe1b3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

src/MacVim/MacVimTests/MacVimTests.m

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "Miscellaneous.h"
1616
#import "MMAppController.h"
1717
#import "MMApplication.h"
18+
#import "MMFindBarView.h"
1819
#import "MMFullScreenWindow.h"
1920
#import "MMWindow.h"
2021
#import "MMTabline.h"
@@ -1576,4 +1577,78 @@ - (void)testIPCSelectedText {
15761577
[self waitForEventHandlingAndVimProcess];
15771578
}
15781579

1580+
// ── MMFindBarView tests ───────────────────────────────────────────────────────
1581+
1582+
/// Test that showWithText:flags: correctly restores the Ignore Case and Match
1583+
/// Word checkbox states from the flags bitmask.
1584+
- (void)testFindBarShowWithFlags {
1585+
MMFindBarView *bar = [[MMFindBarView alloc] init];
1586+
1587+
// flags = 0: ignoreCase ON (no ExactMatch bit), matchWord OFF
1588+
[bar showWithText:@"hello" flags:0];
1589+
XCTAssertTrue([bar ignoreCase], @"ignoreCase should be ON when ExactMatch bit is clear");
1590+
XCTAssertFalse([bar matchWord], @"matchWord should be OFF when MatchWord bit is clear");
1591+
XCTAssertEqualObjects([bar findString], @"hello");
1592+
1593+
// flags = MMFRDExactMatch (0x10): ignoreCase OFF
1594+
[bar showWithText:@"world" flags:0x10];
1595+
XCTAssertFalse([bar ignoreCase], @"ignoreCase should be OFF when ExactMatch bit (0x10) is set");
1596+
XCTAssertFalse([bar matchWord], @"matchWord should still be OFF");
1597+
XCTAssertEqualObjects([bar findString], @"world");
1598+
1599+
// flags = MMFRDMatchWord (0x08): matchWord ON
1600+
[bar showWithText:@"foo" flags:0x08];
1601+
XCTAssertTrue([bar ignoreCase], @"ignoreCase should be ON (ExactMatch bit clear)");
1602+
XCTAssertTrue([bar matchWord], @"matchWord should be ON when MatchWord bit (0x08) is set");
1603+
1604+
// flags = MMFRDExactMatch | MMFRDMatchWord (0x18): both set
1605+
[bar showWithText:@"bar" flags:0x18];
1606+
XCTAssertFalse([bar ignoreCase], @"ignoreCase should be OFF");
1607+
XCTAssertTrue([bar matchWord], @"matchWord should be ON");
1608+
1609+
// Passing nil text should not crash and should not clear existing text
1610+
NSString *prevText = [bar findString];
1611+
[bar showWithText:nil flags:0];
1612+
XCTAssertEqualObjects([bar findString], prevText, @"nil text should not clear the find field");
1613+
}
1614+
1615+
/// Test that calling showFindBarWithText:flags: on MMVimView snaps the bar to
1616+
/// the top-right corner only when the bar is hidden, and preserves the current
1617+
/// position when the bar is already visible.
1618+
- (void)testFindBarPositionPreservedOnReshow {
1619+
[self createTestVimWindow];
1620+
1621+
MMAppController *app = MMAppController.sharedInstance;
1622+
MMVimView *vimView = app.keyVimController.windowController.vimView;
1623+
MMFindBarView *bar = [vimView findBarView];
1624+
1625+
// Bar starts hidden; first show should snap to top-right.
1626+
XCTAssertTrue(bar.hidden, @"find bar should start hidden");
1627+
[self setDefault:MMFindBarInlineKey toValue:@YES];
1628+
[vimView showFindBarWithText:@"test" flags:0];
1629+
1630+
NSRect snapFrame = bar.frame;
1631+
NSRect textRect = vimView.textView.frame;
1632+
1633+
// Verify snapped position is near the top-right corner (within 1pt tolerance).
1634+
XCTAssertEqualWithAccuracy(NSMaxX(snapFrame), NSMaxX(textRect) - 8, 1,
1635+
@"find bar right edge should be 8pt inside text area right edge on first show");
1636+
XCTAssertEqualWithAccuracy(NSMaxY(snapFrame), NSMaxY(textRect) - 8, 1,
1637+
@"find bar top edge should be 8pt below text area top edge on first show");
1638+
1639+
// Move the bar to a different position.
1640+
NSPoint movedOrigin = NSMakePoint(snapFrame.origin.x - 50, snapFrame.origin.y - 30);
1641+
[bar setFrameOrigin:movedOrigin];
1642+
1643+
// Call showFindBarWithText: again while bar is already visible.
1644+
[vimView showFindBarWithText:@"test2" flags:0];
1645+
1646+
XCTAssertEqualWithAccuracy(bar.frame.origin.x, movedOrigin.x, 1,
1647+
@"X position should be preserved when bar is already visible");
1648+
XCTAssertEqualWithAccuracy(bar.frame.origin.y, movedOrigin.y, 1,
1649+
@"Y position should be preserved when bar is already visible");
1650+
XCTAssertEqualObjects([bar findString], @"test2",
1651+
@"find text should be updated even when position is preserved");
1652+
}
1653+
15791654
@end

0 commit comments

Comments
 (0)