Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3460,12 +3460,20 @@ fn a_scripts_error_says_where_it_stopped() {
assert_eq!(stop(&mut s, "layer.rename {\"name\": \"Bogotá\", }", "line 1: "), Some((1, Some(33))));
// JSON cut short: its last character, never past the line.
assert_eq!(stop(&mut s, "layer.rename {\"name\": ", "line 1: "), Some((1, Some(21))));
// The file goes when the test ends, whether or not an assert failed first (`stop` asserts too).
struct RemoveOnDrop(std::path::PathBuf);
impl Drop for RemoveOnDrop {
fn drop(&mut self) {
let _ = std::fs::remove_file(&self.0);
}
}
// An edit to a layer read in place.
let path = grid_fgb("script-stopped-at", 4);
let mut streamed = with_streamed(&path);
// `streamed` is declared after `path`, so it drops first and releases the file before it is removed
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
// (a file still open can't be removed on Windows): keep this order.
let path = RemoveOnDrop(grid_fgb("script-stopped-at", 4));
let mut streamed = with_streamed(&path.0);
let script = "edit.enable {\"on\": true}\nedit.addFeature {\"layer\": \"Streamed\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [1, 2]}}";
assert_eq!(stop(&mut streamed, script, "line 2: "), Some((2, None)));
let _ = std::fs::remove_file(path);
// Errors that name no line of the script.
let long = "map.zoomFull\n".repeat(crate::cmd::workflows::MAX_SCRIPT_LINES + 1);
let e = s.run("script.run", &json!({"script": long})).unwrap_err();
Expand Down
15 changes: 10 additions & 5 deletions crates/ui-egui/src/analysispane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3124,18 +3124,23 @@ mod tests {
script_ran(&mut app, crate::Landed::NotRun("cancelled".into()));
assert_eq!(at(&app), None);
// JSON that doesn't read, after two lines; a click on the error goes to its column.
let e = stopped(&mut app, "# move\nmap.zoomFull\nlayer.rename {\"layer\": }");
assert_eq!(at(&app), Some((3, Some(24))), "{e}");
let (first, second, third) = ("# move\n", "map.zoomFull\n", r#"layer.rename {"layer": }"#);
// The JSON stops reading at the closing brace, the line's last character.
let column = third.chars().count();
let e = stopped(&mut app, &format!("{first}{second}{third}"));
assert_eq!(at(&app), Some((3, Some(column))), "{e}");
// The cursor goes to the error: the characters of the two lines before it, and its column.
let error_at = first.chars().count() + second.chars().count() + (column - 1);
let mut h = egui_kittest::Harness::builder()
.with_size(vec2(900.0, 800.0))
.build_ui_state(|ui, app: &mut RustGisApp| script_pane(app, ui, &Tokens::light()), app);
h.run();
let box_id = egui::Id::unique("script_text");
let cursor = |h: &egui_kittest::Harness<'_, RustGisApp>| crate::widgets::cursor_range(&h.ctx, box_id).map(|r| r.primary.index.0);
assert_ne!(cursor(&h), Some(7 + 13 + 23));
assert_ne!(cursor(&h), Some(error_at));
h.get_by_label(&e).click();
h.run();
assert_eq!(cursor(&h), Some(7 + 13 + 23), "line 3, column 24");
assert_eq!(cursor(&h), Some(error_at), "line 3, column {column}");
assert!(h.ctx.memory(|m| m.has_focus(box_id)));
// From the keyboard: the error takes the focus (Tab), and Enter goes there too.
crate::widgets::set_cursor_range(&h.ctx, box_id, egui::text::CCursorRange::one(egui::text::CCursor::new(0)));
Expand All @@ -3144,7 +3149,7 @@ mod tests {
assert_eq!(cursor(&h), Some(0), "moved away first");
h.key_press(egui::Key::Enter);
h.run();
assert_eq!(cursor(&h), Some(7 + 13 + 23), "by the keyboard");
assert_eq!(cursor(&h), Some(error_at), "by the keyboard");
// Edited since: the error no longer goes anywhere.
h.state_mut().workflow.script.insert(0, '\n');
h.run();
Expand Down
Loading