StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use strato_core::ui_node::{PropValue, UiNode, WidgetNode}; |
| 2 | use strato_widgets::prelude::*; |
| 3 | |
| 4 | #[test] |
| 5 | fn test_view_macro_ast_generation() { |
| 6 | let node = view! { |
| 7 | Container { |
| 8 | padding: 20.0, |
| 9 | child: Text { "Snapshot" } |
| 10 | } |
| 11 | }; |
| 12 | |
| 13 | let expected = UiNode::Widget(WidgetNode { |
| 14 | name: "Container".to_string(), |
| 15 | props: vec![("padding".to_string(), PropValue::Float(20.0))], |
| 16 | children: vec![UiNode::Widget(WidgetNode { |
| 17 | name: "Text".to_string(), |
| 18 | props: vec![( |
| 19 | "text".to_string(), |
| 20 | PropValue::String("Snapshot".to_string()), |
| 21 | )], |
| 22 | children: vec![], |
| 23 | })], |
| 24 | }); |
| 25 | |
| 26 | assert_eq!(node, expected); |
| 27 | } |
| 28 | |
| 29 | #[test] |
| 30 | fn test_view_macro_nested() { |
| 31 | let node = view! { |
| 32 | Column { |
| 33 | spacing: 10.0, |
| 34 | children: [ |
| 35 | Text { "A" }, |
| 36 | Text { "B" } |
| 37 | ] |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | // Note: implementation details of macro might change ordering or exact structure, |
| 42 | // so this snapshot verifies the CURRENT behavior. |
| 43 | |
| 44 | // In current macro: |
| 45 | // props: "spacing": 10.0 (Float) |
| 46 | // children: explicit children list |
| 47 | |
| 48 | match node { |
| 49 | UiNode::Widget(n) => { |
| 50 | assert_eq!(n.name, "Column"); |
| 51 | assert!(n |
| 52 | .props |
| 53 | .contains(&("spacing".to_string(), PropValue::Float(10.0)))); |
| 54 | assert_eq!(n.children.len(), 2); |
| 55 | |
| 56 | // Verify children are Text Widgets |
| 57 | if let UiNode::Widget(t1) = &n.children[0] { |
| 58 | assert_eq!(t1.name, "Text"); |
| 59 | assert!(t1 |
| 60 | .props |
| 61 | .contains(&("text".to_string(), PropValue::String("A".to_string())))); |
| 62 | } else { |
| 63 | panic!("child 0 not widget") |
| 64 | } |
| 65 | |
| 66 | if let UiNode::Widget(t2) = &n.children[1] { |
| 67 | assert_eq!(t2.name, "Text"); |
| 68 | assert!(t2 |
| 69 | .props |
| 70 | .contains(&("text".to_string(), PropValue::String("B".to_string())))); |
| 71 | } else { |
| 72 | panic!("child 1 not widget") |
| 73 | } |
| 74 | } |
| 75 | _ => panic!("Expected Widget node"), |
| 76 | } |
| 77 | } |
| 78 |