mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
Merge main into fix/craft-libs-869c970
This commit is contained in:
commit
ad0330f359
2 files changed
+64
-2
No files matched your search
@@ -2478,3 +2478,25 @@ fn variables_that_settle_over_several_scans_stay_linear() {
|
||||
let r = report(&src);
|
||||
assert!(r.steps <= 9 * src.len() + 16, "{} steps for {} bytes", r.steps, src.len());
|
||||
}
|
||||
|
||||
/// A script whose declarations give names values the analysis doesn't read, and whose variables
|
||||
/// hold nothing the check knows, is scanned once: a second scan would find the same. The bytes are
|
||||
/// the input `any_bytes_are_checked_in_linear_work` shrank to when it found the second scan.
|
||||
#[test]
|
||||
fn a_script_that_is_only_unsure_is_scanned_once() {
|
||||
let bytes: &[u8] = &[
|
||||
1, 1, 32, 1, 48, 32, 33, 48, 33, 1, 33, 1, 35, 1, 35, 123, 35, 123, 32, 48, 40, 32, 35, 48, 1, 40, 32, 1, 40, 32, 32, 123, 35, 123, 32, 35,
|
||||
32, 1, 35, 48, 58, 40, 40, 48, 91, 9, 32, 92, 124, 32, 27, 33, 33, 48, 58, 124, 33, 124, 32, 48, 41, 32, 32, 41, 32, 41, 93, 32, 32, 32, 32,
|
||||
33, 32, 32, 32, 32, 27, 32, 32, 32, 32, 27, 32, 32, 32, 27, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 92, 117, 9, 1,
|
||||
];
|
||||
let limits = Limits::default();
|
||||
let mut acc = crate::report::Acc::new(&limits);
|
||||
let (text, _) = decode(bytes);
|
||||
let (text, braced) = analyze::unescaped(text, &mut acc);
|
||||
let declared = analyze::declarations(&text, &mut acc);
|
||||
let scan = analyze::scan(&text, &declared, &braced, None, std::rc::Rc::from([]), &analyze::Known::default(), &mut acc);
|
||||
assert!(scan.known.unsure && scan.known.bound.is_empty() && scan.known.files.is_empty());
|
||||
let r = check("a.jsx", bytes, None, &limits);
|
||||
assert_eq!(r.steps, acc.steps);
|
||||
assert!(r.steps <= 5 * bytes.len() + 16, "{} steps for {} bytes", r.steps, bytes.len());
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
//! previews on the canvas and runs `addon.pathtools.cornerSet` on OK, one undo step. It opens on
|
||||
//! the Corner Tool's radius and kind, every corner angle (0° to 180°).
|
||||
|
||||
use craft::ui::contract::Bind;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamDialog, ParamKind};
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
use serde_json::{Value, json};
|
||||
@@ -64,7 +65,7 @@ pub(crate) fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
Param::number("minAngle", tl!("Angle:"), *ANGLES.start(), 1.0, 1).unit(UnitKind::Degrees).bounds(Some(*ANGLES.start()), Some(max)),
|
||||
Param::number("maxAngle", tl!("to"), *ANGLES.end(), 1.0, 1).unit(UnitKind::Degrees).bounds(Some(min), Some(*ANGLES.end())),
|
||||
];
|
||||
ParamDialog::new(COMMAND, tl!("Set Corners"), rows).previews(true)
|
||||
ParamDialog::new(COMMAND, tl!("Set Corners"), rows).values(Bind::bound(fields)).previews(true)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,7 +75,8 @@ mod tests {
|
||||
use vectorcraft_doc::{LiveCorners, NodeId};
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
use crate::addons::dialogs::tests::{cancel, confirm, dialog_id, frame, set};
|
||||
use crate::addons::dialogs::tests::{cancel, confirm, dialog_id, frame, read, set};
|
||||
use crate::tests::panel_harness::Panel as Harness;
|
||||
use crate::{VectorcraftApp, menus};
|
||||
|
||||
/// The anchor indices of `id`'s uncut outline with a corner drawn.
|
||||
@@ -141,4 +143,42 @@ mod tests {
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), n + 1);
|
||||
assert_eq!(cut(&app, id), vec![0, 1, 3]);
|
||||
}
|
||||
|
||||
/// The radius drawn at anchor `k` of `id`.
|
||||
fn radius(app: &VectorcraftApp, id: u64, k: usize) -> f64 {
|
||||
let doc = &app.session.doc().unwrap().doc;
|
||||
LiveCorners::of(doc.node(NodeId(id)).unwrap()).unwrap().drawn_radius(k)
|
||||
}
|
||||
|
||||
/// Replaces a numeric field's text and commits it by moving focus, without confirming the dialog.
|
||||
fn type_number(panel: &mut Harness, label: &str, text: &str) {
|
||||
panel.click(label);
|
||||
panel.key(egui::Key::A, egui::Modifiers::COMMAND);
|
||||
panel.type_text(text);
|
||||
panel.key(egui::Key::Tab, egui::Modifiers::NONE);
|
||||
panel.frame();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_set_corners_edits_reach_the_preview_and_the_confirmed_corners() {
|
||||
// A house: square corners at 0, 1 and 3, the roof's 135° corners at 2 and 4.
|
||||
let (app, id) = selected_path(json!([{"x": 0, "y": 0}, {"x": 100, "y": 0}, {"x": 100, "y": 100}, {"x": 50, "y": 150}, {"x": 0, "y": 100}]));
|
||||
let mut panel = Harness::new(app, crate::tests::picks::dialogs);
|
||||
menus::invoke(&mut panel.app(), super::COMMAND, json!({}));
|
||||
panel.frame();
|
||||
type_number(&mut panel, "Radius", "7");
|
||||
type_number(&mut panel, "Angle", "120");
|
||||
let dialog = dialog_id(&panel.app());
|
||||
assert_eq!(read(&panel.app(), dialog, |f| (f.number("radius"), f.number("minAngle"))), (Some(7.0), Some(120.0)));
|
||||
assert_eq!(cut(&panel.app(), id), vec![2, 4], "the typed angle range previewed");
|
||||
assert_eq!(radius(&panel.app(), id, 2), 7.0, "the typed radius previewed");
|
||||
let n = panel.app().session.doc().unwrap().history.undo.len();
|
||||
panel.click("OK");
|
||||
panel.frame();
|
||||
let app = panel.app();
|
||||
assert!(!app.any_dialog_open());
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), n + 1);
|
||||
assert_eq!(cut(&app, id), vec![2, 4]);
|
||||
assert_eq!(radius(&app, id, 4), 7.0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user