diff --git a/tests/test_world_input_capture.py b/tests/test_world_input_capture.py index 5607c3684..e2d58ba41 100644 --- a/tests/test_world_input_capture.py +++ b/tests/test_world_input_capture.py @@ -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)