fix(engine): M8: compile insert submodules

This commit is contained in:
Cédric Legrand committed 2026-11-14 18:25:22 +01:00
1 parent 40783ab184
commit 569707e3f0
8 files changed
+234 -1649

No files matched your search

File diff suppressed because it is too large. Load diff
+70 -11
View File
@@ -1,17 +1,38 @@
use super::{
Anchor, CellRef, Chart, ChartKind, EngineError, Json, LegendPos, RangeRef, Result, Series, Session, Sheet, anchor_mode_param, bad, block,
bool_param, cell_param_on, edit, f64_param, json, split_sheet, str_param, target_ranges, target_sheet, u32_param,
Anchor, CellRef, Chart, ChartKind, EngineError, Json, LegendPos, MAX_COLS, MAX_ROWS, RangeRef, Result, Series, Session, Sheet, anchor_mode_param,
bad, block, bool_param, cell_param_on, edit, f64_param, json, size_cap, split_sheet, str_param, target_ranges, target_sheet, u32_param,
};
#[cfg(test)]
pub(super) fn compiled() -> bool {
true
}
fn chart_areas(s: &Session, p: &Json) -> Result<Vec<RangeRef>> {
if p.get("range").is_some() {
return target_ranges(s, p);
let mut areas = if p.get("range").is_some() {
target_ranges(s, p)?
} else if s.doc()?.selection.ranges.len() > 1 {
s.doc()?.selection.ranges.clone()
} else {
vec![block(s, p)?]
};
// Whole columns/rows span a million cells: clip their far edges to the cells in use, so only
// a block that really is too large gets refused. Bounded areas keep their extent as given.
let sheet = target_sheet(s, p)?;
if let Some(used) = s.doc()?.wb.sheet(sheet).and_then(|sh| sh.used_range()) {
// Areas that start outside the used range keep their extent as given.
for r in &mut areas {
let whole_cols = r.start.row == 0 && r.end.row >= MAX_ROWS - 1;
let whole_rows = r.start.col == 0 && r.end.col >= MAX_COLS - 1;
if whole_cols && r.start.row <= used.end.row {
r.end.row = r.end.row.min(used.end.row);
}
if whole_rows && r.start.col <= used.end.col {
r.end.col = r.end.col.min(used.end.col);
}
}
}
let d = s.doc()?;
if d.selection.ranges.len() > 1 {
return Ok(d.selection.ranges.clone());
}
Ok(vec![block(s, p)?])
Ok(areas)
}
// ---------------------------------------------------------------- charts
@@ -263,6 +284,8 @@ pub fn build_chart(s: &Session, p: &Json) -> Result<(usize, Chart)> {
data_table: None,
gridlines: !matches!(kind, ChartKind::Pie | ChartKind::Doughnut | ChartKind::Treemap | ChartKind::Sunburst | ChartKind::Funnel),
style: 1,
hole_size: 75,
first_slice_angle: 0,
x_title: None,
y_title: None,
source: (areas.len() == 1).then(|| format!("{}!{}", gridcraft_formula::quote_sheet(&sh.name), bounds.a1())),
@@ -308,7 +331,11 @@ pub(super) fn chart_set(s: &mut Session, p: &Json) -> Result<Json> {
let Some(c) = sh.charts.get_mut(ci) else { return Ok(Json::Null) };
if let Some(t) = str_param(p, "type") {
c.kind = chart_kind(t, str_param(p, "subtype").unwrap_or(""));
if !c.supports_data_table() {
c.data_table = None;
}
}
update_data_table(c, p, bool_param(p, "dataTable"))?;
if let Some(method) = quartiles {
for series in &mut c.series {
series.quartiles = method;
@@ -335,6 +362,12 @@ pub(super) fn chart_set(s: &mut Session, p: &Json) -> Result<Json> {
if let Some(v) = u32_param(p, "style") {
c.style = v.clamp(1, 16);
}
if let Some(v) = u32_param(p, "holeSize") {
c.hole_size = v.clamp(10, 90) as u8;
}
if let Some(v) = u32_param(p, "firstSliceAngle") {
c.first_slice_angle = (v % 360) as u16;
}
if let Some(t) = p.get("xTitle") {
c.x_title = t.as_str().map(str::to_string);
}
@@ -345,10 +378,10 @@ pub(super) fn chart_set(s: &mut Session, p: &Json) -> Result<Json> {
c.anchor.cell = at;
}
if let Some(w) = f64_param(p, "width") {
c.anchor.width = w.clamp(20.0, 10000.0) as f32;
c.anchor.width = w.clamp(20.0, size_cap(c.anchor.width)) as f32;
}
if let Some(h) = f64_param(p, "height") {
c.anchor.height = h.clamp(20.0, 10000.0) as f32;
c.anchor.height = h.clamp(20.0, size_cap(c.anchor.height)) as f32;
}
if let Some(v) = f64_param(p, "dx") {
c.anchor.dx = v as f32;
@@ -360,6 +393,32 @@ pub(super) fn chart_set(s: &mut Session, p: &Json) -> Result<Json> {
})
}
/// Shared by Chart Properties and Add Chart Element; no separate UI state.
pub(crate) fn update_data_table(c: &mut Chart, p: &Json, on: Option<bool>) -> Result<()> {
if p.get("dataTable").is_some_and(|v| !v.is_boolean()) {
return Err(bad("chart", "`dataTable` must be a boolean"));
}
if on == Some(false) {
c.data_table = None;
return Ok(());
}
let fields = ["dataTableKeys", "dataTableHorizontalBorder", "dataTableVerticalBorder", "dataTableOutline"];
if on == Some(true) || fields.iter().any(|k| p.get(k).is_some()) {
if !c.supports_data_table() {
return Err(bad("chart", "data tables need a column, bar, line, area or compatible combo chart"));
}
let table = c.data_table.get_or_insert_with(Default::default);
for (key, value) in
fields.into_iter().zip([&mut table.show_keys, &mut table.horizontal_border, &mut table.vertical_border, &mut table.outline])
{
if let Some(v) = p.get(key) {
*value = v.as_bool().ok_or_else(|| bad("chart", format!("`{key}` must be a boolean")))?;
}
}
}
Ok(())
}
pub(super) fn chart_switch(s: &mut Session, p: &Json) -> Result<Json> {
let (si, ci) = find_chart(s, p)?;
edit(s, |cx| {
+27 -2
View File
@@ -1,8 +1,14 @@
use super::{
Anchor, BorderLine, BorderStyle, Borders, CfOperator, CfRule, CfValueKind, Color, CondFormat, EngineError, Fill, Json, Result, Session, Shape,
ShapeKind, Style, anchor_mode_param, bad, bool_param, cell_param, edit, f64_param, json, ok, str_param, target_ranges, target_sheet, u32_param,
Anchor, BorderLine, BorderStyle, Borders, CellRef, CfOperator, CfRule, CfValueKind, Color, CondFormat, EngineError, Fill, Json, RangeRef, Result,
Session, Shape, ShapeKind, Style, anchor_mode_param, bad, bool_param, cell_param, edit, f64_param, json, ok, str_param, target_ranges,
target_sheet, u32_param,
};
#[cfg(test)]
pub(super) fn compiled() -> bool {
true
}
// ---------------------------------------------------------------- conditional formatting
fn preset_style(name: &str) -> Style {
@@ -271,7 +277,13 @@ pub(super) fn clear_cf(s: &mut Session, p: &Json) -> Result<Json> {
sh.cond_formats.clear();
} else {
for cf in sh.cond_formats.iter_mut() {
let before = RangeRef::top_left(&cf.ranges);
cf.ranges.retain(|r| !ranges.iter().any(|x| x.intersects(r)));
// The relative formulas are written for the top-left cell: when it goes, they're
// rewritten for the new one, so the areas left keep reading the same cells.
if let (Some(from), Some(to)) = (before, RangeRef::top_left(&cf.ranges)) {
rebase_cf_formulas(&mut cf.rule, from, to);
}
}
sh.cond_formats.retain(|c| !c.ranges.is_empty());
}
@@ -279,6 +291,19 @@ pub(super) fn clear_cf(s: &mut Session, p: &Json) -> Result<Json> {
})
}
/// Moves the relative references of a rule's per-cell formulas written for `from` to `to`.
fn rebase_cf_formulas(rule: &mut CfRule, from: CellRef, to: CellRef) {
let mv = |f: &str| crate::cmd::data::move_rule_formula(f, from, to);
match rule {
CfRule::CellIs { a, b, .. } => {
*a = mv(a);
*b = b.as_deref().map(mv);
}
CfRule::Expression { formula, .. } => *formula = mv(formula),
_ => {}
}
}
pub(super) fn manage_cf(s: &mut Session, p: &Json) -> Result<Json> {
let sheet = target_sheet(s, p)?;
if p.get("delete").is_none() && p.get("moveUp").is_none() && p.get("moveDown").is_none() {
+17 -5
View File
@@ -3,6 +3,11 @@ use super::{
split_sheet, str_param, target_ranges, target_sheet,
};
#[cfg(test)]
pub(super) fn compiled() -> bool {
true
}
// ---------------------------------------------------------------- links & comments
pub(super) fn insert_link(s: &mut Session, p: &Json) -> Result<Json> {
@@ -27,8 +32,10 @@ pub(super) fn insert_link(s: &mut Session, p: &Json) -> Result<Json> {
st.font.underline = Underline::Single;
});
let sh = cx.sheet_mut(sheet)?;
if let Some(t) = text.clone().or_else(|| sh.value(at).is_empty().then(|| target.clone())) {
sh.set_cell(at, Cell { value: gridcraft_core::Value::text(t.as_str()), formula: None, style: link_style });
if let Some(t) = text.clone().or_else(|| {
(sh.spill_anchor(at).is_none() && sh.value(at).is_empty() && sh.cell(at).is_none_or(|cell| !cell.has_content())).then(|| target.clone())
}) {
sh.set_cell(at, Cell { value: gridcraft_core::Value::text(t.as_str()), formula: None, style: link_style, py: None });
} else {
sh.set_style(at, link_style);
}
@@ -38,9 +45,11 @@ pub(super) fn insert_link(s: &mut Session, p: &Json) -> Result<Json> {
})
}
/// Follows a link: a reference selects it, an `http`/`https`/`mailto` address is handed to the
/// host (`UiRequest::OpenUrl`); anything else is refused ([`crate::links::classify`]). Opens no
/// dialog; the interactive click asks for confirmation first, in the UI.
/// Follows a link: a reference selects it; anything else is refused ([`crate::links::classify`]).
/// An `http`/`https`/`mailto` address is refused too unless the host set
/// [`crate::links::LinkPolicy::Allow`]: every caller of a command may be a script or an agent, so
/// the user opens such links by clicking and confirming, and the UI then calls
/// [`Session::open_confirmed_link`] (#2181). Opens no dialog.
pub(super) fn open_link(s: &mut Session, p: &Json) -> Result<Json> {
let target = match str_param(p, "url").or_else(|| str_param(p, "target")) {
Some(t) => t.to_string(),
@@ -56,6 +65,9 @@ pub(super) fn open_link(s: &mut Session, p: &Json) -> Result<Json> {
match crate::links::classify(&target) {
crate::links::LinkKind::Internal(r) => crate::cmd::edit::go_to(s, &json!({"reference": r.trim_start_matches('#')})),
crate::links::LinkKind::External(u) => {
if s.link_policy != crate::links::LinkPolicy::Allow {
return Err(EngineError::Other(crate::links::NEEDS_CONFIRMATION.into()));
}
s.ui_requests.push(crate::UiRequest::OpenUrl(u.clone()));
Ok(json!({"opened": u}))
}
+47 -43
View File
@@ -1,8 +1,14 @@
use super::{
Anchor, CellPicture, CellRef, Color, EngineError, Image, Json, PROTECTED, Result, Session, Shape, ShapeKind, Sparkline, SparklineKind,
anchor_mode_name, anchor_mode_param, bad, bool_param, cell_param, edit, f64_param, json, locked_cell_error, ok, str_param, u32_param,
Anchor, CellPicture, CellRef, Color, EngineError, Image, Json, MAX_OBJECT_OFFSET, ObjKind, ObjRef, PROTECTED, Result, Session, Shape, ShapeKind,
Sparkline, SparklineKind, anchor_mode_name, anchor_mode_param, bad, bool_param, cell_param, edit, f64_param, json, locked_cell_error, ok,
size_cap, str_param, u32_param,
};
#[cfg(test)]
pub(super) fn compiled() -> bool {
true
}
pub(super) fn insert_sparkline(s: &mut Session, p: &Json) -> Result<Json> {
let src = str_param(p, "range").ok_or_else(|| bad("insert.sparkline", "missing `range`"))?.to_string();
let loc = cell_param(s, p, "location")?.ok_or_else(|| bad("insert.sparkline", "missing `location`"))?;
@@ -63,6 +69,10 @@ pub(super) fn insert_picture(s: &mut Session, p: &Json) -> Result<Json> {
.unwrap_or_else(|| if data.starts_with(&[0x89, b'P', b'N', b'G']) { "image/png".into() } else { "image/jpeg".into() });
let (w, h) = crate::io::image_size(&data).unwrap_or((320, 240));
let d = s.doc()?;
// Sheet protection locks drawing objects, as for a text box's text.
if d.wb.active().is_some_and(|sh| sh.is_protected()) {
return Err(EngineError::Other(PROTECTED.into()));
}
let id = d.wb.next_object_id();
let at = cell_param(s, p, "at")?.unwrap_or(d.selection.active);
let scale = (640.0 / w.max(1) as f32).min(1.0);
@@ -176,9 +186,15 @@ pub(super) fn shape_set_text(s: &mut Session, p: &Json) -> Result<Json> {
let sheet = d.wb.active_sheet();
let sh = d.wb.active().ok_or_else(|| bad("shape.setText", "no such text box"))?;
let shape = sh.shapes.iter().find(|shape| shape.id == id).ok_or_else(|| bad("shape.setText", "no such text box"))?;
if shape.kind != ShapeKind::TextBox {
if !matches!(shape.kind, ShapeKind::TextBox | ShapeKind::WordArt) {
return Err(bad("shape.setText", "the shape is not a text box"));
}
if shape.kind == ShapeKind::WordArt && text.is_empty() {
return Err(bad("shape.setText", "WordArt text must not be empty"));
}
if shape.kind == ShapeKind::WordArt && text.chars().nth(crate::cmd::wordart::MAX_CHARS).is_some() {
return Err(bad("shape.setText", format!("`text` is longer than {} characters", crate::cmd::wordart::MAX_CHARS)));
}
// Sheet protection locks drawing objects (there is no "edit objects" allowance yet).
if sh.is_protected() {
return Err(EngineError::Other(PROTECTED.into()));
@@ -193,51 +209,50 @@ pub(super) fn shape_set_text(s: &mut Session, p: &Json) -> Result<Json> {
})
}
/// The floating object a `{kind, id}` command names on the active sheet. Unknown kinds and
/// objects are errors, so a stale id never succeeds silently.
fn object_param(s: &Session, p: &Json, cmd: &str) -> Result<(usize, ObjRef)> {
let id = u32_param(p, "id").ok_or_else(|| bad(cmd, "missing `id`"))?;
let kind =
str_param(p, "kind").and_then(ObjKind::parse).ok_or_else(|| bad(cmd, "kind must be chart, image, shape, slicer, equation or control"))?;
let d = s.doc()?;
let sheet = d.wb.active_sheet();
let o = ObjRef::new(kind, id);
if !d.wb.sheet(sheet).is_some_and(|sh| sh.has_object(o)) {
return Err(bad(cmd, "no such object"));
}
// A locked form control on a protected sheet stays as it is.
crate::cmd::controls::check_objects_unlocked(s, sheet, kind, &[id])?;
Ok((sheet, o))
}
pub(super) fn delete_object(s: &mut Session, p: &Json) -> Result<Json> {
let id = u32_param(p, "id").ok_or_else(|| bad("object.delete", "missing `id`"))?;
let kind = str_param(p, "kind").unwrap_or("").to_string();
let sheet = s.doc()?.wb.active_sheet();
let (sheet, o) = object_param(s, p, "object.delete")?;
edit(s, |cx| {
let sh = cx.sheet_mut(sheet)?;
match kind.as_str() {
"chart" => sh.charts.retain(|c| c.id != id),
"image" => sh.images.retain(|c| c.id != id),
"slicer" => sh.slicers.retain(|c| c.id != id),
_ => sh.shapes.retain(|c| c.id != id),
}
Ok(Json::Null)
cx.sheet_mut(sheet)?.remove_object(o);
Ok(json!({"deleted": o}))
})
}
pub(super) fn move_object(s: &mut Session, p: &Json) -> Result<Json> {
let id = u32_param(p, "id").ok_or_else(|| bad("object.move", "missing `id`"))?;
let kind = str_param(p, "kind").unwrap_or("").to_string();
let sheet = s.doc()?.wb.active_sheet();
let (sheet, o) = object_param(s, p, "object.move")?;
let at = cell_param(s, p, "at")?;
edit(s, |cx| {
let sh = cx.sheet_mut(sheet)?;
let anchor = match kind.as_str() {
"chart" => sh.charts.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
"image" => sh.images.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
"slicer" => sh.slicers.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
"shape" => sh.shapes.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
_ => None,
};
let Some(a) = anchor else { return Err(bad("object.move", "no such object")) };
let Some(a) = cx.sheet_mut(sheet)?.object_anchor_mut(o) else { return Err(bad("object.move", "no such object")) };
if let Some(at) = at {
a.cell = at;
}
if let Some(v) = f64_param(p, "dx") {
a.dx = v as f32;
a.dx = v.clamp(-MAX_OBJECT_OFFSET, MAX_OBJECT_OFFSET) as f32;
}
if let Some(v) = f64_param(p, "dy") {
a.dy = v as f32;
a.dy = v.clamp(-MAX_OBJECT_OFFSET, MAX_OBJECT_OFFSET) as f32;
}
if let Some(v) = f64_param(p, "width") {
a.width = v.clamp(1.0, 10000.0) as f32;
a.width = v.clamp(1.0, size_cap(a.width)) as f32;
}
if let Some(v) = f64_param(p, "height") {
a.height = v.clamp(0.0, 10000.0) as f32;
a.height = v.clamp(0.0, size_cap(a.height)) as f32;
}
Ok(Json::Null)
})
@@ -247,21 +262,10 @@ pub(super) fn move_object(s: &mut Session, p: &Json) -> Result<Json> {
/// cells" / "Don't move or size with cells"), so it follows — or ignores — its rows and columns
/// when the sheet is sorted or edited structurally.
pub(super) fn set_anchor_mode(s: &mut Session, p: &Json) -> Result<Json> {
let id = u32_param(p, "id").ok_or_else(|| bad("object.setAnchorMode", "missing `id`"))?;
let kind = str_param(p, "kind").unwrap_or("").to_string();
if !matches!(kind.as_str(), "chart" | "image" | "shape") {
return Err(bad("object.setAnchorMode", "kind must be chart, image or shape"));
}
let (sheet, o) = object_param(s, p, "object.setAnchorMode")?;
let mode = anchor_mode_param(p).ok_or_else(|| bad("object.setAnchorMode", "mode must be moveAndSize, moveOnly or absolute"))?;
let sheet = s.doc()?.wb.active_sheet();
edit(s, |cx| {
let sh = cx.sheet_mut(sheet)?;
let anchor = match kind.as_str() {
"chart" => sh.charts.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
"image" => sh.images.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
_ => sh.shapes.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
};
let Some(a) = anchor else { return Err(bad("object.setAnchorMode", "no such object")) };
let Some(a) = cx.sheet_mut(sheet)?.object_anchor_mut(o) else { return Err(bad("object.setAnchorMode", "no such object")) };
a.mode = mode;
Ok(json!({"mode": anchor_mode_name(mode)}))
})
+10 -2
View File
@@ -3,6 +3,11 @@ use super::{
block, bool_param, edit, json, rewrite, shift_cell_features, str_param, target_range, target_sheet, with,
};
#[cfg(test)]
pub(super) fn compiled() -> bool {
true
}
// ---------------------------------------------------------------- tables
pub(super) fn insert_table(s: &mut Session, p: &Json) -> Result<Json> {
@@ -51,7 +56,7 @@ pub(super) fn insert_table(s: &mut Session, p: &Json) -> Result<Json> {
let sh = cx.sheet_mut(sheet)?;
// The header row pushes the data down one row: never off the end of the sheet.
let last = RangeRef::new(CellRef::new(MAX_ROWS - 1, r.start.col), CellRef::new(MAX_ROWS - 1, r.end.col));
if sh.cells.iter_range(last).any(|(_, x)| x.formula.is_some() || !x.value.is_empty()) {
if sh.cells.iter_range(last).any(|(_, x)| x.has_content()) {
return Err(EngineError::Other("To prevent possible loss of data, cells can't be pushed off the end of the worksheet.".into()));
}
sh.cells.shift_rows_in_cols(r.start.col, r.end.col, r.start.row, 1);
@@ -211,7 +216,10 @@ fn write_totals(sh: &mut Sheet, ti: usize) {
let c = CellRef::new(row, t.range.start.col + i as u32);
if let Some(code) = col.totals.subtotal_code() {
let f = format!("=SUBTOTAL({code},{}[{}])", t.name, col.name);
sh.set_cell(c, Cell { formula: Some(std::sync::Arc::new(Formula::new(&f))), value: gridcraft_core::Value::Empty, style: sh.style_id(c) });
sh.set_cell(
c,
Cell { formula: Some(std::sync::Arc::new(Formula::new(&f))), value: gridcraft_core::Value::Empty, style: sh.style_id(c), py: None },
);
} else if let Some(l) = &col.totals_label {
sh.set_value(c, gridcraft_core::Value::text(l.as_str()));
} else {
+29
View File
@@ -2401,6 +2401,35 @@ fn merging_over_a_spill_blocks_it_and_unmerging_unblocks_it() {
assert_eq!(v(&s, "A3"), Value::Number(3.0));
}
#[test]
fn inserting_a_link_without_text_preserves_a_spill_child() {
let mut s = s();
s.execute("cell.set", json!({"cell": "A1", "input": "=SEQUENCE(3)"})).unwrap();
assert_eq!(v(&s, "A2"), Value::Number(2.0));
s.execute("insert.link", json!({"cell": "A2", "target": "https://example.org"})).unwrap();
assert_eq!(v(&s, "A1"), Value::Number(1.0));
assert_eq!(v(&s, "A2"), Value::Number(2.0));
let d = s.doc().unwrap();
let at = CellRef::parse("A2").unwrap();
assert_eq!(d.wb.active().unwrap().hyperlinks.get(&at).map(|link| link.target.as_str()), Some("https://example.org"));
}
#[test]
fn inserting_a_link_without_text_preserves_an_empty_spill_child() {
let mut s = s();
s.execute("range.setValues", json!({"range": "A1:C3", "values": [["a", "x", 1], ["b", "x", 2], ["a", "y", 3]]})).unwrap();
s.execute("cell.set", json!({"cell": "K1", "input": "=PIVOTBY(A1:A3,B1:B3,C1:C3,LAMBDA(x,SUM(x)))"})).unwrap();
assert_eq!(v(&s, "K1"), Value::Empty);
let at = CellRef::parse("M3").unwrap();
assert_eq!(v(&s, "M3"), Value::Empty);
assert_eq!(s.doc().unwrap().wb.active().unwrap().spill_anchor(at), Some(CellRef::parse("K1").unwrap()));
s.execute("insert.link", json!({"cell": "M3", "target": "https://example.org"})).unwrap();
assert_eq!(v(&s, "K1"), Value::Empty);
assert_eq!(v(&s, "M3"), Value::Empty);
let d = s.doc().unwrap();
assert_eq!(d.wb.active().unwrap().hyperlinks.get(&at).map(|link| link.target.as_str()), Some("https://example.org"));
}
#[test]
fn multi_cell_array_formulas_and_tables_dont_overlap() {
// Found by the command-sequence fuzzer: an array over a table header lost its value to the
+13
View File
@@ -530,3 +530,16 @@ fn python_code_with_an_empty_value_counts_as_content() {
s.execute("edit.copy", json!({"range": "T1"})).unwrap();
assert!(s.execute("edit.paste", json!({"at": "R2"})).is_err_and(|e| e.to_string().contains("part of an array")));
}
#[test]
fn inserting_a_link_without_text_preserves_an_empty_python_cell() {
let mut s = s();
plant_empty(&mut s, "A1");
s.execute("insert.link", json!({"cell": "A1", "target": "https://example.org"})).unwrap();
assert_eq!(code(&s, 0, "A1"), Some("x = 1".into()));
let d = s.doc().unwrap();
let sh = d.wb.sheet(0).unwrap();
let at = CellRef::parse("A1").unwrap();
assert_eq!(sh.value(at), Value::Empty);
assert_eq!(sh.hyperlinks.get(&at).map(|link| link.target.as_str()), Some("https://example.org"));
}