tests: give the capture fixture the mouse position helper

The fixture compiles `Game::capture` on its own, so the helper it now
calls has to be part of it: the test extracts it from the client, like it
extracts the methods, and the call inside the fixture loses the crate
path.

The fixture also asserts the grab path now: grabbing the pointer puts
the mouse at the window's centre, as `MouseHandler.grabMouse` does.

Co-Authored-By: minimax-m3.1-flash (Claude Code) <noreply@users.noreply.github.com>
This commit is contained in:
levzzz
2026-10-27 18:18:07 +05:00
parent 1f040d06eb
commit 67e0d54062
+19 -1
View File
@@ -27,6 +27,17 @@ def method(source, name):
return source[start:end]
def function(source, name):
start = source.index(f"pub fn {name}(")
opening = source.index("{", start)
depth = 1
end = opening + 1
while depth:
depth += (source[end] == "{") - (source[end] == "}")
end += 1
return source[start:end]
class WorldInputCaptureTests(unittest.TestCase):
def test_loading_completion_wiring(self):
game = (ROOT / "crates/horizon-client/src/game.rs").read_text(encoding="utf-8")
@@ -44,6 +55,7 @@ class WorldInputCaptureTests(unittest.TestCase):
@unittest.skipUnless(shutil.which("rustc"), "requires Rust")
def test_capture_lifecycle(self):
source = (ROOT / "crates/horizon-client/src/game.rs").read_text(encoding="utf-8")
mouse = (ROOT / "crates/horizon-client/src/mouse.rs").read_text(encoding="utf-8")
fixture = r'''
use std::cell::Cell;
#[derive(Clone, Copy, PartialEq)]
@@ -99,6 +111,7 @@ impl Default for Game {
renderer: None, cursor: (0.0, 0.0) }
}
}
HELPER
impl Game {
fn stop_mining(&mut self) { self.mining = false; }
fn reset_inventory_clicks(&mut self) {}
@@ -150,6 +163,7 @@ fn main() {
assert!(!game.captured); // Focus alone does not resume gameplay.
game.capture(true); // Click or resume action.
assert!(game.captured);
assert_eq!(game.cursor, (213.5, 120.0)); // The grab puts the mouse at the centre.
}
let mut game = Game::default();
// On a server the chat is ChatScreen (#708): loading never grabs over it.
@@ -183,7 +197,11 @@ fn main() {
assert!(game.window.as_ref().unwrap().visible.get());
}
'''
fixture = fixture.replace("METHODS", method(source, "capture") + "\n" +
capture = method(source, "capture").replace(
"horizon_client::mouse::mouse_position_after_grab_change",
"mouse_position_after_grab_change")
fixture = fixture.replace("HELPER", function(mouse, "mouse_position_after_grab_change"))
fixture = fixture.replace("METHODS", capture + "\n" +
method(source, "capture_loaded_world"))
with tempfile.TemporaryDirectory(prefix="horizon-input-") as folder:
folder = Path(folder)