From 0c8931b984cf9336fd96b6cb3f3c1c1f89330143 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Sun, 19 Dec 2021 16:40:12 -0800 Subject: [PATCH] finished extensive return value test --- src/tests/state_update_tests.rs | 45 ++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/tests/state_update_tests.rs b/src/tests/state_update_tests.rs index 3070112..671d958 100644 --- a/src/tests/state_update_tests.rs +++ b/src/tests/state_update_tests.rs @@ -1,4 +1,4 @@ -use crate::modules::stream_states::{state_update::StateUpdate, enums::Scenes}; +use crate::modules::stream_states::{state_update::StateUpdate, enums::{Scenes, SubScenes}}; @@ -56,4 +56,47 @@ fn test_json_to_state_update() { "{\"type\": \"button\", \"button\": \"Media_Pause_Play\", \"data\": false}" ).unwrap()), StateUpdate::ComputerMediaDoPause(false)); + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"button\", \"button\": \"Camera_None\"}" + ).unwrap()), StateUpdate::SubScene(SubScenes::CameraDefault)); + + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"button\", \"button\": \"Camera_Top_Right\"}" + ).unwrap()), StateUpdate::SubScene(SubScenes::CameraWithUpperRight)); + + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"button\", \"button\": \"Camera_Bottom_Right\"}" + ).unwrap()), StateUpdate::SubScene(SubScenes::CameraWithLowerRight)); + + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"button\", \"button\": \"Camera_Bottom_Left\"}" + ).unwrap()), StateUpdate::SubScene(SubScenes::CameraWithLargeUpperRight)); + + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"button\", \"button\": \"Screen_None\"}" + ).unwrap()), StateUpdate::SubScene(SubScenes::ScreenDefault)); + + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"button\", \"button\": \"Screen_Top_Right\"}" + ).unwrap()), StateUpdate::SubScene(SubScenes::ScreenWithUpperRight)); + + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"button\", \"button\": \"Screen_Bottom_Right\"}" + ).unwrap()), StateUpdate::SubScene(SubScenes::ScreenWithLowerRight)); + + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"Timer_Length\", \"data\": 5.5}" + ).unwrap()), StateUpdate::TimerLength(5.5)); + + assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"update\"}" + ).unwrap()), StateUpdate::UpdateClient); +} + +#[test] +#[should_panic] +fn test_json_to_state_update_fails() { + StateUpdate::json_to_state_update(serde_json::from_str( + "{\"type\": \"AnUnknownType\"}" + ).unwrap()); } \ No newline at end of file