-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use egui_tiles::{Tiles, Tree}; | ||
|
||
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)] | ||
Check failure on line 3 in tests/serialize.rs GitHub Actions / Rust
Check failure on line 3 in tests/serialize.rs GitHub Actions / Rust
Check failure on line 3 in tests/serialize.rs GitHub Actions / Rust
|
||
struct Pane { | ||
nr: usize, | ||
} | ||
|
||
fn create_tree() -> Tree<Pane> { | ||
let mut next_view_nr = 0; | ||
let mut gen_pane = || { | ||
let pane = Pane { nr: next_view_nr }; | ||
next_view_nr += 1; | ||
pane | ||
}; | ||
|
||
let mut tiles = Tiles::default(); | ||
|
||
let mut tabs = vec![]; | ||
tabs.push({ | ||
let children = (0..7).map(|_| tiles.insert_pane(gen_pane())).collect(); | ||
tiles.insert_horizontal_tile(children) | ||
}); | ||
tabs.push({ | ||
let cells = (0..11).map(|_| tiles.insert_pane(gen_pane())).collect(); | ||
tiles.insert_grid_tile(cells) | ||
}); | ||
tabs.push(tiles.insert_pane(gen_pane())); | ||
|
||
let root = tiles.insert_tab_tile(tabs); | ||
|
||
Tree::new("my_tree", root, tiles) | ||
} | ||
|
||
#[test] | ||
fn test_serialize_json() { | ||
let original = create_tree(); | ||
let json = serde_json::to_string(&original).expect("json serialize"); | ||
Check failure on line 37 in tests/serialize.rs GitHub Actions / Rust
|
||
let restored = serde_json::from_str(&json).expect("json deserialize"); | ||
Check failure on line 38 in tests/serialize.rs GitHub Actions / Rust
|
||
assert_eq!(original, restored, "JSON did not round-trip"); | ||
} | ||
|
||
#[test] | ||
fn test_serialize_ron() { | ||
let original = create_tree(); | ||
let ron = ron::to_string(&original).expect("ron serialize"); | ||
Check failure on line 45 in tests/serialize.rs GitHub Actions / Rust
|
||
let restored = ron::from_str(&ron).expect("ron deserialize"); | ||
Check failure on line 46 in tests/serialize.rs GitHub Actions / Rust
|
||
assert_eq!(original, restored, "RON did not round-trip"); | ||
} |