diff options
Diffstat (limited to 'crates/shirabe/tests/script/event_test.rs')
| -rw-r--r-- | crates/shirabe/tests/script/event_test.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/crates/shirabe/tests/script/event_test.rs b/crates/shirabe/tests/script/event_test.rs index 47891c7..424f553 100644 --- a/crates/shirabe/tests/script/event_test.rs +++ b/crates/shirabe/tests/script/event_test.rs @@ -1 +1,64 @@ //! ref: composer/tests/Composer/Test/Script/EventTest.php + +use std::cell::RefCell; +use std::rc::Rc; + +use indexmap::IndexMap; +use shirabe::composer::{ComposerHandle, PartialOrFullComposer}; +use shirabe::config::Config; +use shirabe::event_dispatcher::Event as BaseEvent; +use shirabe::io::IOInterface; +use shirabe::io::null_io::NullIO; +use shirabe::package::{RootPackageHandle, RootPackageInterfaceHandle}; +use shirabe::script::Event; + +fn create_composer_instance() -> ComposerHandle { + let composer = + ComposerHandle::from_rc_unchecked(Rc::new(RefCell::new(PartialOrFullComposer::new_full()))); + let config = Rc::new(RefCell::new(Config::new(true, None))); + composer.borrow_mut().set_config(config); + let package: RootPackageInterfaceHandle = + RootPackageHandle::new("foo".to_string(), "1.0.0.0".to_string(), "1.0.0".to_string()) + .into(); + composer.borrow_mut().set_package(package); + composer +} + +#[test] +#[ignore = "Event::calculate_originating_event (called by set_originating_event) is todo!()"] +fn test_event_sets_originating_event() { + let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new())); + let composer = create_composer_instance(); + + let originating_event = + BaseEvent::new("originatingEvent".to_string(), vec![], IndexMap::new()); + + let mut script_event = Event::new( + "test".to_string(), + composer.downgrade(), + io, + true, + vec![], + IndexMap::new(), + ); + + assert!( + script_event.get_originating_event().is_none(), + "originatingEvent is initialized as null" + ); + + script_event.set_originating_event(originating_event); + + assert!(script_event.get_originating_event().is_some()); +} + +// In PHP, the intermediate originating event is itself a Script\Event, and +// getOriginatingEvent() recurses to return the upper-most event. Here +// set_originating_event takes a concrete event_dispatcher::Event, so a Script +// Event cannot be passed as the originating event (it is not polymorphic), and +// the test cannot be expressed faithfully. +#[test] +#[ignore = "set_originating_event takes a concrete event_dispatcher::Event; a Script Event cannot be passed as originating event, and calculate_originating_event is todo!()"] +fn test_event_calculates_nested_originating_event() { + todo!() +} |
