diff options
Diffstat (limited to 'chain/src/item/default/mod.rs')
-rw-r--r-- | chain/src/item/default/mod.rs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/chain/src/item/default/mod.rs b/chain/src/item/default/mod.rs index 5971985..e0e2296 100644 --- a/chain/src/item/default/mod.rs +++ b/chain/src/item/default/mod.rs @@ -1584,4 +1584,102 @@ mod item_test { Ok(()) } + + #[test] + fn test_set_pos() -> Result<(), Box<dyn std::error::Error>> { + let grammar_file = std::fs::read_to_string( + "/Users/durand/Desktop/Centre/A propos de programmes\ + /Rust/rep/grammar/abnf grammars/test.abnf", + )?; + + let grammar: grammar::Grammar = grammar_file.parse()?; + + let atom = DefaultAtom::from_grammar(grammar)?; + + // atom.print_nullables(); + + let mut forest: DefaultForest<ForestLabel<GrammarLabel>> = DefaultForest::new_leaf_raw( + ForestLabel::new(GrammarLabel::new(TNT::Non(0), 0), ForestLabelType::Plain), + ); + + forest.plant( + 0, + DefaultForest::new_leaf_raw(ForestLabel::new( + GrammarLabel::new(1, 0), + ForestLabelType::Plain, + )), + false, + )?; + + forest.plant( + 1, + DefaultForest::new_leaf_raw(ForestLabel::new( + GrammarLabel::new(TNT::Non(1), 0), + ForestLabelType::Plain, + )), + false, + )?; + + forest.plant( + 2, + DefaultForest::new_leaf_raw(ForestLabel::new( + GrammarLabel::new(104, 0), + ForestLabelType::Plain, + )), + false, + )?; + + forest.plant( + 3, + DefaultForest::new_leaf_raw(ForestLabel::new( + GrammarLabel::new(TNT::Non(2), 0), + ForestLabelType::Plain, + )), + false, + )?; + + forest.plant( + 4, + DefaultForest::new_leaf_raw(ForestLabel::new( + GrammarLabel::new(2, 0), + ForestLabelType::Plain, + )), + false, + )?; + + forest.plant( + 5, + DefaultForest::new_leaf_raw(ForestLabel::new( + GrammarLabel::new(TNT::Ter(0), 0), + ForestLabelType::Plain, + )), + false, + )?; + + // forest.print_viz("test.gv")?; + + forest.set_pos(&atom, 1, true)?; + + // forest.print_viz("test set.gv")?; + + for node in 0..=6 { + let label = forest.vertex_label(node)?.expect("node no label?"); + + assert_eq!(label.label().start(), 1); + } + + for node in 0..3 { + let label = forest.vertex_label(node)?.expect("node no label?"); + + assert!(label.label().end().is_none()); + } + + for node in 3..=6 { + let label = forest.vertex_label(node)?.expect("node no label?"); + + assert_eq!(label.label().end(), Some(2)); + } + + Ok(()) + } } |