From 6f4cc44167a6946d6aac1173b7660b779ca44f0e Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Wed, 19 Jun 2024 15:21:16 +0200 Subject: [PATCH 1/2] feat: expose gamedata to json --- src/vpx/jsonmodel.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/vpx/jsonmodel.rs b/src/vpx/jsonmodel.rs index 73a0b1a..dc1442c 100644 --- a/src/vpx/jsonmodel.rs +++ b/src/vpx/jsonmodel.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; use crate::vpx::collection::Collection; use crate::vpx::custominfotags::CustomInfoTags; +use crate::vpx::gamedata::{GameData, GameDataJson}; use crate::vpx::tableinfo::TableInfo; #[derive(Serialize, Deserialize)] @@ -113,3 +114,61 @@ pub fn json_to_collections(json: serde_json::Value) -> Result, s } Ok(collections) } + +pub fn game_data_to_json(game_data: &GameData) -> serde_json::Value { + let game_data_json = GameDataJson::from_game_data(game_data); + to_value(game_data_json).unwrap() +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::vpx::collection::Collection; + use crate::vpx::custominfotags::CustomInfoTags; + use crate::vpx::gamedata::GameData; + use crate::vpx::tableinfo::TableInfo; + use serde_json::Value; + + #[test] + fn test_info_to_json() { + let table_info = TableInfo::default(); + let custom_info_tags = CustomInfoTags::default(); + let json = info_to_json(&table_info, &custom_info_tags); + let (table_info2, custom_info_tags2) = json_to_info(json, None).unwrap(); + assert_eq!(table_info, table_info2); + assert_eq!(custom_info_tags, custom_info_tags2); + } + + #[test] + fn test_collections_to_json() { + let collections = vec![ + Collection { + name: "collection1".to_string(), + items: vec!["item1".to_string(), "item2".to_string()], + fire_events: true, + stop_single_events: false, + group_elements: true, + }, + Collection { + name: "collection2".to_string(), + items: vec!["item3".to_string(), "item4".to_string()], + fire_events: false, + stop_single_events: true, + group_elements: false, + }, + ]; + let json = collections_json(&collections); + let collections2 = json_to_collections(json).unwrap(); + assert_eq!(collections, collections2); + } + + #[test] + fn test_game_data_to_json() { + let game_data = GameData::default(); + let json = game_data_to_json(&game_data); + // assert that we have a value of type object that at least contains "name": String("Table1") + let map = json.as_object().unwrap(); + let name = map.get("name").unwrap(); + assert_eq!(name, &Value::String("Table1".to_string())); + } +} From aa89984d1ed595f9affd10947ececa847e3c198d Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Wed, 19 Jun 2024 15:57:55 +0200 Subject: [PATCH 2/2] ci: try to fix the rust version issue --- .github/workflows/rust.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 514c09a..19b596b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,6 +31,11 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + # make sure we are on rust 1.79 + # see https://github.com/tuffy/bitstream-io/commit/241eaed73b0cd814640ceaf01b8220e5c98927d6#commitcomment-143198388 + # TODO remove this once github is on a newer version of rust + - name: Set up Rust + run: rustup update - name: Build run: cargo build --verbose - name: Run tests