-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: recursion Support recursion in the serialization schema graph
- Loading branch information
Showing
12 changed files
with
421 additions
and
183 deletions.
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
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 |
---|---|---|
@@ -1,13 +1,26 @@ | ||
extern crate savefile_abi; | ||
extern crate savefile_derive; | ||
|
||
use savefile_abi::AbiConnection; | ||
use savefile_derive::savefile_abi_exportable; | ||
|
||
|
||
#[savefile_abi_exportable(version = 0)] | ||
pub trait ExampleTrait { | ||
fn get(&mut self) -> &'static str; | ||
fn test_slices(&mut self, slice: &[u32]) -> u32 { | ||
slice.iter().copied().sum() | ||
} | ||
} | ||
|
||
impl ExampleTrait for () { | ||
|
||
} | ||
|
||
#[test] | ||
fn dummy_test() {} | ||
fn dummy_test() { | ||
let boxed: Box<dyn ExampleTrait> = Box::new(()); | ||
let conn = AbiConnection::from_boxed_trait(boxed).unwrap(); | ||
|
||
assert!( conn.get_arg_passable_by_ref("test_slices", 0) ); | ||
//conn.test_slices(&[1,2,3,4]); | ||
} |
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,87 @@ | ||
use assert_roundtrip; | ||
use savefile::Removed; | ||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Tree { | ||
Leaf, | ||
Node(Box<Tree>,Box<Tree>) | ||
} | ||
|
||
#[test] | ||
pub fn test_cyclic() { | ||
let example = Tree::Node(Box::new(Tree::Leaf), Box::new(Tree::Leaf)); | ||
assert_roundtrip(example); | ||
|
||
let example = Tree::Node(Box::new(Tree::Node(Box::new(Tree::Leaf),Box::new(Tree::Leaf))), Box::new(Tree::Leaf)); | ||
assert_roundtrip(example); | ||
} | ||
|
||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
struct TreeNode { | ||
tree: Box<Tree2> | ||
} | ||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Tree2 { | ||
Leaf(String), | ||
Node(TreeNode) | ||
} | ||
#[test] | ||
pub fn test_cyclic2() { | ||
let example = Tree2::Node(TreeNode{tree: Box::new(Tree2::Leaf("hej".into()))}); | ||
assert_roundtrip(example); | ||
} | ||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Version1LevelD { | ||
Leaf, | ||
Node(Box<Version1LevelA>) | ||
} | ||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Version1LevelC { | ||
Leaf, | ||
Node(Box<Version1LevelD>) | ||
} | ||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Version1LevelB { | ||
Leaf(Box<Version1LevelC>), | ||
Node(Box<Version1LevelC>) | ||
} | ||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Version1LevelA { | ||
Leaf, | ||
Node(Box<Version1LevelB>) | ||
} | ||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Version2LevelC { | ||
Leaf, | ||
Node(Box<Version2LevelA>) | ||
} | ||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Version2LevelB { | ||
Leaf(Box<Version2LevelC>), | ||
Node(Box<Version2LevelC>) | ||
} | ||
|
||
#[derive(Savefile, Debug, PartialEq)] | ||
enum Version2LevelA { | ||
Leaf, | ||
Node(Box<Version2LevelB>) | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Saved schema differs from in-memory schema for version 0. Error: At location [.Version1LevelA/Node/0Version1LevelB/Leaf/0Version1LevelC/Node/0Version1LevelD/Node/0]: In memory schema: <recursion 3>, file schema: enum")] | ||
fn cycles_vertest1() { | ||
use assert_roundtrip_to_new_version; | ||
assert_roundtrip_to_new_version( | ||
Version1LevelA::Leaf, | ||
0, | ||
Version2LevelA::Leaf, | ||
1, | ||
); | ||
} |
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
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
Oops, something went wrong.