aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/script/event_test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/tests/script/event_test.rs')
-rw-r--r--crates/shirabe/tests/script/event_test.rs52
1 files changed, 42 insertions, 10 deletions
diff --git a/crates/shirabe/tests/script/event_test.rs b/crates/shirabe/tests/script/event_test.rs
index e7e574b..d143bd2 100644
--- a/crates/shirabe/tests/script/event_test.rs
+++ b/crates/shirabe/tests/script/event_test.rs
@@ -11,7 +11,7 @@ use shirabe::event_dispatcher::EventInterface;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::package::{RootPackageHandle, RootPackageInterfaceHandle};
-use shirabe::script::Event;
+use shirabe::script::{Event, OriginatingEvent};
fn create_composer_instance() -> ComposerHandle {
let composer =
@@ -29,7 +29,6 @@ fn create_composer_instance() -> ComposerHandle {
}
#[test]
-#[ignore]
fn test_event_sets_originating_event() {
let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new()));
let composer = create_composer_instance();
@@ -50,7 +49,7 @@ fn test_event_sets_originating_event() {
"originatingEvent is initialized as null"
);
- script_event.set_originating_event(originating_event);
+ script_event.set_originating_event(OriginatingEvent::Base(originating_event));
// assertSame: the originating event passed in is returned unchanged.
assert_eq!(
@@ -62,13 +61,46 @@ fn test_event_sets_originating_event() {
);
}
-// 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 = "Event::set_originating_event takes a concrete event_dispatcher::Event, so a nested script::Event cannot be passed as originating event; the recursive calculate_originating_event behavior is not expressible"]
fn test_event_calculates_nested_originating_event() {
- todo!()
+ let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new()));
+ let composer = create_composer_instance();
+
+ let originating_event =
+ BaseEvent::new("upperOriginatingEvent".to_string(), vec![], IndexMap::new());
+
+ let mut intermediate_event = Event::new(
+ "intermediate".to_string(),
+ composer.downgrade(),
+ io.clone(),
+ true,
+ vec![],
+ IndexMap::new(),
+ );
+ intermediate_event.set_originating_event(OriginatingEvent::Base(originating_event));
+
+ let mut script_event = Event::new(
+ "test".to_string(),
+ composer.downgrade(),
+ io,
+ true,
+ vec![],
+ IndexMap::new(),
+ );
+ script_event.set_originating_event(OriginatingEvent::Script(Box::new(intermediate_event)));
+
+ // assertNotSame/assertSame: compare by name since Rust lacks PHP object identity.
+ let name = script_event
+ .get_originating_event()
+ .map(EventInterface::get_name);
+ assert_ne!(
+ name,
+ Some("intermediate"),
+ "getOriginatingEvent() SHOULD NOT return intermediate events"
+ );
+ assert_eq!(
+ name,
+ Some("upperOriginatingEvent"),
+ "getOriginatingEvent() SHOULD return upper-most event"
+ );
}