| 1 | use model::comp::{BitDepth, Comp, NodeId, ParamValue, SaverSpec}; |
| 2 | use model::edit::CompHistory; |
| 3 | use model::expr::ExprEngine; |
| 4 | use model::lua_value::{LuaTable, parse_lua}; |
| 5 | use model::spline::{BezierSpline, HandleMode, KeyFlags, Keyframe, PolyPath, PolyPoint, segment_control_points}; |
| 6 | use std::collections::HashMap; |
| 7 | |
| 8 | fn ast_fusion_string(comp: &Comp) -> String { |
| 9 | let mut s = comp.sync_to_raw_ast().to_fusion_string(); |
| 10 | if !s.ends_with('\n') { |
| 11 | s.push('\n'); |
| 12 | } |
| 13 | s |
| 14 | } |
| 15 | |
| 16 | fn assert_save_equivalence_and_reparse(comp: &Comp) { |
| 17 | let streamed = comp.to_fusion_string(); |
| 18 | let ast = ast_fusion_string(comp); |
| 19 | assert_eq!(streamed, ast, "streaming vs AST save divergence"); |
| 20 | Comp::from_fusion_str(&streamed).expect("saved comp must re-parse cleanly"); |
| 21 | } |
| 22 | |
| 23 | #[test] |
| 24 | fn lua_parser_bounds_deep_nesting_without_stack_overflow() { |
| 25 | for depth in [200, 500, 5000] { |
| 26 | let open_tables = "{".repeat(depth); |
| 27 | assert!(parse_lua(&open_tables).is_err(), "unclosed tables depth {depth}"); |
| 28 | |
| 29 | let closed_tables = format!("{}1{}", "{".repeat(depth), "}".repeat(depth)); |
| 30 | assert!(parse_lua(&closed_tables).is_err(), "closed tables depth {depth}"); |
| 31 | |
| 32 | let nested_calls = format!("{}1{}", "Foo(".repeat(depth), ")".repeat(depth)); |
| 33 | assert!(parse_lua(&nested_calls).is_err(), "nested calls depth {depth}"); |
| 34 | |
| 35 | let nested_keys = format!("{}1{}", "{[".repeat(depth), "]=1}".repeat(depth)); |
| 36 | assert!(parse_lua(&nested_keys).is_err(), "nested keys depth {depth}"); |
| 37 | |
| 38 | let nested_groups = format!( |
| 39 | "Composition {{ Tools = ordered() {{ {} }} }}", |
| 40 | "G = GroupOperator { Tools = ordered() { ".repeat(depth / 2) |
| 41 | + &"} } ".repeat(depth / 2) |
| 42 | ); |
| 43 | assert!(Comp::from_fusion_str(&nested_groups).is_err(), "nested groups depth {depth}"); |
| 44 | } |
| 45 | |
| 46 | // Legitimate Fusion-like nesting well under the cap still parses cleanly. |
| 47 | let ok = format!("{}42{}", "{".repeat(32), "}".repeat(32)); |
| 48 | assert!(parse_lua(&ok).is_ok()); |
| 49 | } |
| 50 | |
| 51 | #[test] |
| 52 | fn malformed_comp_prefixes_escapes_nul_brackets_and_huge_numbers_never_panic() { |
| 53 | let sample = r#"Composition { |
| 54 | CurrentTime = 10, |
| 55 | GlobalRange = { 0, 100 }, |
| 56 | RenderRange = { 0, 100 }, |
| 57 | Prefs = { Comp = { FrameFormat = { Width = 1920, Height = 1080, Rate = 24 } } }, |
| 58 | Tools = ordered() { |
| 59 | BG1 = Background { Inputs = { Width = Input { Value = 1920 } } }, |
| 60 | Blur1 = Blur { Inputs = { Input = Input { SourceOp = "BG1", Source = "Output" } } }, |
| 61 | }, |
| 62 | }"#; |
| 63 | |
| 64 | // Every UTF-8 prefix truncation must return Ok or Err without panicking or hanging. |
| 65 | for (idx, _) in sample.char_indices() { |
| 66 | let _ = Comp::from_fusion_str(&sample[..idx]); |
| 67 | } |
| 68 | |
| 69 | // Deterministic byte/char mutations over a representative comp never panic or hang. |
| 70 | let mut seed = 0x9E37_79B9_7F4A_7C15u64; |
| 71 | let mut next_u32 = || -> u32 { |
| 72 | seed ^= seed << 13; |
| 73 | seed ^= seed >> 7; |
| 74 | seed ^= seed << 17; |
| 75 | (seed >> 16) as u32 |
| 76 | }; |
| 77 | let sample_bytes = sample.as_bytes(); |
| 78 | for _ in 0..256 { |
| 79 | let mut buf = sample_bytes.to_vec(); |
| 80 | let edits = 1 + (next_u32() as usize % 6); |
| 81 | for _ in 0..edits { |
| 82 | let pos = next_u32() as usize % buf.len(); |
| 83 | match next_u32() % 3 { |
| 84 | 0 => buf[pos] = next_u32() as u8, |
| 85 | 1 if buf.len() > 1 => { |
| 86 | buf.remove(pos); |
| 87 | } |
| 88 | _ => buf.insert(pos, next_u32() as u8), |
| 89 | } |
| 90 | } |
| 91 | let mutated = String::from_utf8_lossy(&buf); |
| 92 | if let Ok(comp) = Comp::from_fusion_str(&mutated) { |
| 93 | let _ = comp.to_fusion_string(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Bad escapes, unterminated strings/long brackets/comments, bare NUL bytes. |
| 98 | for bad in [ |
| 99 | "", |
| 100 | " -- just a comment", |
| 101 | "\0", |
| 102 | "Composition { \0 }", |
| 103 | r#"Composition { Name = "unterminated"#, |
| 104 | r#"Composition { Name = "bad\x" }"#, |
| 105 | r#"Composition { Name = "bad\xZZ" }"#, |
| 106 | r#"Composition { Name = [===[unterminated ]==] }"#, |
| 107 | r#"--[===[unterminated comment ]==] Composition {}"#, |
| 108 | "12345", |
| 109 | "nil", |
| 110 | "\"not a table\"", |
| 111 | ] { |
| 112 | assert!(Comp::from_fusion_str(bad).is_err(), "expected Err for {bad:?}"); |
| 113 | } |
| 114 | |
| 115 | // NUL inside quoted strings/long brackets/comments and huge numbers survive roundtrip. |
| 116 | let weird = concat!( |
| 117 | "-- comment with \0 nul\n", |
| 118 | "Composition {\n", |
| 119 | "\tTools = ordered() {\n", |
| 120 | "\t\tN1 = Note { Inputs = { Comments = Input { Value = \"a\0b\\255\" } } },\n", |
| 121 | "\t\tN2 = Note { Inputs = { Comments = Input { Value = [=[x\0y]=] } } },\n", |
| 122 | "\t\tB1 = Blur { Inputs = { XBlurSize = Input { Value = 1e9999 } } },\n", |
| 123 | "\t\tB2 = Blur { Inputs = { XBlurSize = Input { Value = -1e9999 } } },\n", |
| 124 | "\t\tB3 = Blur {},\n", |
| 125 | "\t},\n", |
| 126 | "}\n" |
| 127 | ); |
| 128 | let comp = Comp::from_fusion_str(weird).expect("weird valid comp parses"); |
| 129 | assert_save_equivalence_and_reparse(&comp); |
| 130 | } |
| 131 | |
| 132 | #[test] |
| 133 | fn non_finite_and_degenerate_metadata_normalizes_and_saves_equivalently() { |
| 134 | let weird_meta = r#"Composition { |
| 135 | CurrentTime = nan, |
| 136 | AudioOffset = 1e9999, |
| 137 | GlobalRange = { nan, 1e9999 }, |
| 138 | RenderRange = { -1e9999, nan }, |
| 139 | Prefs = { Comp = { FrameFormat = { Width = 1e9999, Height = nan, Rate = 1e9999, DepthFull = nan } } }, |
| 140 | Tools = ordered() { |
| 141 | A = Blur {}, |
| 142 | B = Blur {}, |
| 143 | C = Blur {}, |
| 144 | D = Blur {}, |
| 145 | E = Blur {}, |
| 146 | }, |
| 147 | }"#; |
| 148 | let comp = Comp::from_fusion_str(weird_meta).expect("parses comp with non-finite metadata"); |
| 149 | assert_eq!(comp.width, 1920); |
| 150 | assert_eq!(comp.height, 1080); |
| 151 | assert_eq!(comp.fps, 30.0); |
| 152 | assert_eq!(comp.depth_full, BitDepth::Int8); |
| 153 | assert_eq!(comp.current_time, 0.0); |
| 154 | assert_eq!(comp.audio_offset, 0.0); |
| 155 | assert_eq!(comp.global_range, [0, 1000]); |
| 156 | assert_eq!(comp.render_range, [0, 1000]); |
| 157 | assert_save_equivalence_and_reparse(&comp); |
| 158 | |
| 159 | // Non-table Prefs / Tools, empty Tools, and inferred huge Background sizes. |
| 160 | for src in [ |
| 161 | "Composition { Prefs = 123, Tools = 123 }", |
| 162 | "Composition { Prefs = { Comp = 123 }, Tools = {} }", |
| 163 | "Composition { Tools = ordered() {} }", |
| 164 | "Composition { Prefs = { Comp = { FrameFormat = { Width = 1e20, Height = 1e20, Rate = nan } } }, Tools = ordered() { A = Blur {}, B = Blur {}, C = Blur {}, D = Blur {}, E = Blur {} } }", |
| 165 | "Composition { Tools = ordered() { BG = Background { Inputs = { Width = Input { Value = 1e9999 }, Height = Input { Value = 1e9999 } } } } }", |
| 166 | ] { |
| 167 | let c = Comp::from_fusion_str(src).expect(src); |
| 168 | assert!(c.width <= 65536 && c.height <= 65536); |
| 169 | assert!(c.fps.is_finite() && c.fps > 0.0); |
| 170 | assert_save_equivalence_and_reparse(&c); |
| 171 | } |
| 172 | |
| 173 | // Duplicate flow + modifier name in Tools must not diverge between streaming and AST save. |
| 174 | let dup_name = r#"Composition { |
| 175 | Tools = ordered() { |
| 176 | Foo = Blur {}, |
| 177 | Foo = BezierSpline { KeyFrames = { [0] = { 1, Flags = { Linear = true } } } }, |
| 178 | B = Blur {}, |
| 179 | C = Blur {}, |
| 180 | D = Blur {}, |
| 181 | }, |
| 182 | }"#; |
| 183 | let mut comp = Comp::from_fusion_str(dup_name).expect("dup name parses"); |
| 184 | comp.splines.get_mut("Foo").unwrap().keyframes[0].value = 2.5; |
| 185 | assert_save_equivalence_and_reparse(&comp); |
| 186 | } |
| 187 | |
| 188 | #[test] |
| 189 | fn cyclic_source_op_and_grid_mesh_overflow_and_utf8_saver_path_do_not_panic() { |
| 190 | let cyclic = r#"Composition { |
| 191 | Tools = ordered() { |
| 192 | A = ColorCorrector { SourceOp = "B", Inputs = { MasterRGBGain = Input { Value = 2 } } }, |
| 193 | B = ColorCorrector { SourceOp = "A" }, |
| 194 | SelfInst = ColorCorrector { SourceOp = "SelfInst" }, |
| 195 | GW = GridWarp { |
| 196 | Inputs = { |
| 197 | SrcMesh = Input { |
| 198 | Value = Mesh { |
| 199 | Col = 1e9999, |
| 200 | Points = { |
| 201 | { X = 0, Y = 0 }, { X = 1, Y = 0 }, |
| 202 | { X = 0, Y = 1 }, { X = 1, Y = 1 }, |
| 203 | }, |
| 204 | }, |
| 205 | }, |
| 206 | }, |
| 207 | }, |
| 208 | }, |
| 209 | }"#; |
| 210 | let comp = Comp::from_fusion_str(cyclic).expect("cyclic SourceOp parses"); |
| 211 | let gw = comp.node(comp.find_node("GW").unwrap()); |
| 212 | assert!(comp.eval_grid_mesh(gw, "SrcMesh", 0.0).is_none()); |
| 213 | assert!(comp.eval_grid_mesh(gw, "SrcMesh", f64::NAN).is_none()); |
| 214 | |
| 215 | // Multi-byte UTF-8 Saver stem + extreme range must never slice mid-char or overflow i64. |
| 216 | for filename in ["render_é.png", "出力.exr", "frame_é001.exr", "plain.png"] { |
| 217 | let spec = SaverSpec { |
| 218 | node_id: NodeId(0), |
| 219 | name: "S".to_owned(), |
| 220 | upstream: None, |
| 221 | filename: filename.to_owned(), |
| 222 | range: [i64::MIN, i64::MAX], |
| 223 | sequence_start: Some(10), |
| 224 | }; |
| 225 | let p = spec.frame_path(100); |
| 226 | assert!(!p.as_os_str().is_empty()); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | #[test] |
| 231 | fn expression_engine_math_dsl_and_shake_handle_cycles_depth_and_non_finite_time() { |
| 232 | let expr = ExprEngine::new(); |
| 233 | |
| 234 | // Non-finite times & expressions never panic in Lua or format_number. |
| 235 | let empty_nums = HashMap::new(); |
| 236 | let empty_pts = HashMap::new(); |
| 237 | let empty_nodes = HashMap::new(); |
| 238 | for t in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 0.0] { |
| 239 | let _ = expr.eval_number("time + 1", t, &empty_nums, &empty_pts, &empty_nodes); |
| 240 | let _ = expr.eval_string("tostring(time)", t, &empty_nums, &empty_pts, &empty_nodes); |
| 241 | let _ = expr.eval_point("Point(time, 0/0)", t, &empty_nums, &empty_pts, &empty_nodes); |
| 242 | } |
| 243 | assert_eq!( |
| 244 | expr.eval_string("0/0", 0.0, &empty_nums, &empty_pts, &empty_nodes).as_deref(), |
| 245 | Some("nan") |
| 246 | ); |
| 247 | assert_eq!( |
| 248 | expr.eval_string("1/0", 0.0, &empty_nums, &empty_pts, &empty_nodes).as_deref(), |
| 249 | Some("inf") |
| 250 | ); |
| 251 | assert_eq!( |
| 252 | expr.eval_string("-1/0", 0.0, &empty_nums, &empty_pts, &empty_nodes).as_deref(), |
| 253 | Some("-inf") |
| 254 | ); |
| 255 | |
| 256 | // Deeply nested expressions in ExpressionModifier math DSL & Lua must not overflow stack. |
| 257 | let deep_parens = format!("{}1{}", "(".repeat(4000), ")".repeat(4000)); |
| 258 | let deep_unary = format!("{}1", "-".repeat(4000)); |
| 259 | let deep_pow = format!("{}2", "2^".repeat(4000)); |
| 260 | let src = format!( |
| 261 | r#"Composition {{ |
| 262 | Tools = ordered() {{ |
| 263 | A = Transform {{ |
| 264 | Inputs = {{ |
| 265 | Size = Input {{ Expression = "B.Size", }}, |
| 266 | Angle = Input {{ SourceOp = "Shk", Source = "X", }}, |
| 267 | Width = Input {{ SourceOp = "EM1", Source = "NumberResult", }}, |
| 268 | Height = Input {{ SourceOp = "EM2", Source = "NumberResult", }}, |
| 269 | Edges = Input {{ SourceOp = "EM3", Source = "NumberResult", }}, |
| 270 | }}, |
| 271 | }}, |
| 272 | B = Transform {{ |
| 273 | Inputs = {{ |
| 274 | Size = Input {{ Expression = "A.Size", }}, |
| 275 | }}, |
| 276 | }}, |
| 277 | Shk = Shake {{ |
| 278 | Inputs = {{ |
| 279 | Smoothness = Input {{ Value = 0.01 }}, |
| 280 | XMinimum = Input {{ Value = 0 }}, |
| 281 | XMaximum = Input {{ Value = 10 }}, |
| 282 | }}, |
| 283 | }}, |
| 284 | EM1 = Expression {{ Inputs = {{ NumberExpression = Input {{ Value = "{deep_parens}" }} }} }}, |
| 285 | EM2 = Expression {{ Inputs = {{ NumberExpression = Input {{ Value = "{deep_unary}" }} }} }}, |
| 286 | EM3 = Expression {{ Inputs = {{ NumberExpression = Input {{ Value = "{deep_pow}" }} }} }}, |
| 287 | }}, |
| 288 | }}"# |
| 289 | ); |
| 290 | let comp = Comp::from_fusion_str(&src).expect("comp parses"); |
| 291 | let a = comp.node(comp.find_node("A").unwrap()); |
| 292 | |
| 293 | for t in [0.0, f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 1e20, -1e20] { |
| 294 | // Cyclic NodeA.P <-> NodeB.P terminates cleanly. |
| 295 | assert_eq!(comp.eval_number(a, "Size", t, 42.0, &expr), 42.0); |
| 296 | // Shake at huge / non-finite times never panics with i64 overflow. |
| 297 | let shk = comp.eval_number(a, "Angle", t, -1.0, &expr); |
| 298 | assert!(shk.is_finite()); |
| 299 | // Deep ExpressionModifier formulas don't overflow stack. |
| 300 | assert_eq!(comp.eval_number(a, "Width", t, 7.0, &expr), 7.0); |
| 301 | assert_eq!(comp.eval_number(a, "Height", t, 7.0, &expr), 7.0); |
| 302 | assert_eq!(comp.eval_number(a, "Edges", t, 7.0, &expr), 7.0); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | #[test] |
| 307 | fn splines_and_polypaths_survive_degenerate_keys_nan_and_inf() { |
| 308 | // Empty & 1-key splines |
| 309 | let empty_sp = BezierSpline { |
| 310 | name: "e".to_owned(), |
| 311 | color: [0, 0, 0], |
| 312 | keyframes: vec![], |
| 313 | }; |
| 314 | assert_eq!(empty_sp.eval(f64::NAN), 0.0); |
| 315 | assert_eq!(empty_sp.eval(f64::INFINITY), 0.0); |
| 316 | |
| 317 | // Manually constructed NaN-timed keyframes with handles must not panic in segment_control_points. |
| 318 | let mut k0 = Keyframe::new(f64::NAN, 1.0); |
| 319 | k0.rh = Some([1.0, 2.0]); |
| 320 | let mut k1 = Keyframe::new(f64::NAN, 3.0); |
| 321 | k1.lh = Some([2.0, 4.0]); |
| 322 | let _ = segment_control_points(&k0, &k1); |
| 323 | |
| 324 | // Loop spline evaluated at NaN / Inf / -Inf must stay finite (no inf - inf = NaN). |
| 325 | let lp = KeyFlags { |
| 326 | linear: true, |
| 327 | loop_after: true, |
| 328 | ..Default::default() |
| 329 | }; |
| 330 | let mut sp = BezierSpline { |
| 331 | name: "loop".to_owned(), |
| 332 | color: [255, 255, 255], |
| 333 | keyframes: vec![ |
| 334 | Keyframe { time: 20.0, value: 2.0, lh: None, rh: None, flags: lp, handle_mode: HandleMode::Vector }, |
| 335 | Keyframe { time: 10.0, value: 1.0, lh: None, rh: None, flags: lp, handle_mode: HandleMode::Vector }, |
| 336 | Keyframe { time: 10.0, value: 1.5, lh: None, rh: None, flags: lp, handle_mode: HandleMode::Vector }, |
| 337 | ], |
| 338 | }; |
| 339 | sp.sort(); |
| 340 | for t in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 10.0, 15.0, 25.0] { |
| 341 | assert!(sp.eval(t).is_finite(), "non-finite eval at t={t}"); |
| 342 | } |
| 343 | |
| 344 | // Malformed KeyFrames table with nan/inf keys & handles filters non-finite entries cleanly. |
| 345 | let sp_tbl = parse_lua( |
| 346 | r#"BezierSpline { |
| 347 | KeyFrames = { |
| 348 | [nan] = { 1, LH = { nan, 0 }, RH = { inf, 0 } }, |
| 349 | [inf] = { 2 }, |
| 350 | [0] = { nan }, |
| 351 | [5] = { 0.5, LH = { nan, 1 } }, |
| 352 | [10] = { 1.5 }, |
| 353 | }, |
| 354 | }"#, |
| 355 | ) |
| 356 | .unwrap(); |
| 357 | let parsed_sp = BezierSpline::from_lua("s".to_owned(), sp_tbl.as_table().unwrap()); |
| 358 | assert_eq!(parsed_sp.keyframes.len(), 2); |
| 359 | assert!(parsed_sp.keyframes[0].lh.is_none()); |
| 360 | assert!(parsed_sp.eval(f64::NAN).is_finite()); |
| 361 | |
| 362 | // PolyPath at NaN / Inf / -Inf stays finite. |
| 363 | let pp = PolyPath { |
| 364 | name: "p".to_owned(), |
| 365 | displacement_op: None, |
| 366 | displacement_value: 0.0, |
| 367 | closed: false, |
| 368 | points: vec![ |
| 369 | PolyPoint { x: 0.0, y: 0.0, lx: 0.0, ly: 0.0, rx: 0.0, ry: 0.0, linear: true }, |
| 370 | PolyPoint { x: 0.5, y: 0.0, lx: 0.0, ly: 0.0, rx: 0.0, ry: 0.0, linear: true }, |
| 371 | ], |
| 372 | }; |
| 373 | for d in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY] { |
| 374 | let p = pp.eval_center(d); |
| 375 | assert!(p[0].is_finite() && p[1].is_finite(), "non-finite PolyPath at d={d}"); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | #[test] |
| 380 | fn comp_history_and_edits_handle_stale_ids_and_rapid_roundtrips() { |
| 381 | let mut comp = Comp::from_fusion_str("Composition { Tools = ordered() {} }").unwrap(); |
| 382 | let mut history = CompHistory::with_max_depth(8); |
| 383 | history.mark_saved(&comp); |
| 384 | |
| 385 | let stale = NodeId(999); |
| 386 | assert!(comp.set_keyframe(stale, "Gain", 0.0, 1.0).is_err()); |
| 387 | assert!(!comp.delete_keyframe("MissingSpline", 0.0)); |
| 388 | assert!(comp.rename_node(stale, "ValidName").is_err()); |
| 389 | assert!(comp.connect_output(stale, "Output", stale, "Input").is_err()); |
| 390 | assert!(!comp.disconnect(stale, "Input")); |
| 391 | assert!(comp.splice_node_into_pipe(stale, stale, stale, "Input").is_err()); |
| 392 | assert!(!comp.set_input_value(stale, "Gain", ParamValue::Number(1.0))); |
| 393 | assert!(!comp.set_input_expression(stale, "Gain", Some("1".to_owned()))); |
| 394 | assert!(!comp.toggle_passthrough(stale)); |
| 395 | comp.set_node_pos(stale, [1.0, 2.0]); |
| 396 | assert!(comp.delete_nodes(&[stale]).is_empty()); |
| 397 | assert!(comp.node_splines(stale).is_empty()); |
| 398 | assert!(history.paste_fusion_clipboard(&mut comp, "{{{{{", (0.0, 0.0)).is_err()); |
| 399 | assert!(!history.undo(&mut comp)); |
| 400 | assert!(!history.redo(&mut comp)); |
| 401 | |
| 402 | // Rapid add -> wire -> keyframe -> rename -> splice -> delete -> undo -> redo sequence. |
| 403 | history.push_snapshot(&comp, "Add BG"); |
| 404 | let bg = comp.add_node("Background", None, [0.0, 0.0]); |
| 405 | assert!(comp.rename_node(bg, "123bad").is_err()); |
| 406 | assert!(comp.rename_node(bg, "end").is_err()); |
| 407 | assert!(comp.rename_node(bg, "").is_err()); |
| 408 | |
| 409 | history.push_snapshot(&comp, "Add Merge"); |
| 410 | let merge = comp.add_node("Merge", None, [200.0, 0.0]); |
| 411 | comp.connect_output(bg, "Output", merge, "Background").unwrap(); |
| 412 | |
| 413 | history.push_snapshot(&comp, "Keyframe & Splice"); |
| 414 | let sp = comp.set_keyframe(merge, "Blend", 10.0, 0.5).unwrap(); |
| 415 | assert!(comp.set_keyframe(merge, "Blend", f64::NAN, 1.0).is_err()); |
| 416 | let blur = comp.add_node("Blur", None, [100.0, 0.0]); |
| 417 | comp.splice_node_into_pipe(blur, bg, merge, "Background").unwrap(); |
| 418 | assert_save_equivalence_and_reparse(&comp); |
| 419 | |
| 420 | history.push_snapshot(&comp, "Rename & Delete key"); |
| 421 | comp.rename_node(blur, "SoftBlur").unwrap(); |
| 422 | assert!(comp.delete_keyframe(&sp, 10.0)); |
| 423 | assert!(!comp.delete_keyframe(&sp, f64::NAN)); |
| 424 | assert_save_equivalence_and_reparse(&comp); |
| 425 | |
| 426 | history.push_snapshot(&comp, "Delete Blur"); |
| 427 | comp.delete_nodes(&[blur]); |
| 428 | assert_save_equivalence_and_reparse(&comp); |
| 429 | |
| 430 | // Undo everything back to empty and redo everything forward. |
| 431 | while history.undo(&mut comp) { |
| 432 | assert_save_equivalence_and_reparse(&comp); |
| 433 | } |
| 434 | assert!(comp.nodes.is_empty()); |
| 435 | while history.redo(&mut comp) { |
| 436 | assert_save_equivalence_and_reparse(&comp); |
| 437 | } |
| 438 | |
| 439 | // Cancel and commit group edge cases. |
| 440 | assert!(!history.commit_group(&comp)); |
| 441 | assert!(!history.cancel_group(&mut comp)); |
| 442 | history.begin_group(&comp, "Canceled"); |
| 443 | let _tmp = comp.add_node("Note", None, [0.0, 0.0]); |
| 444 | assert!(history.cancel_group(&mut comp)); |
| 445 | assert_save_equivalence_and_reparse(&comp); |
| 446 | let _ = LuaTable::default(); |
| 447 | } |