#![allow(unused_variables, dead_code)] use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize)] pub struct TextInput { pub text: String, } #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct TextStats { pub chars: usize, pub words: usize, pub lines: usize, } pub fn analyze_text_json(input_json: &str) -> Result { todo!("Deserializuj TextInput z JSON, policz chars/words/lines i zserializuj TextStats do JSON") } #[cfg(test)] mod tests { use super::*; #[test] fn processes_json_boundary_for_js_interop() { let raw = r#"{"text":"Rust\nin browser"}"#; let out_json = analyze_text_json(raw).unwrap(); let stats: TextStats = serde_json::from_str(&out_json).unwrap(); assert_eq!( stats, TextStats { chars: 15, words: 3, lines: 2 } ); } #[test] fn returns_error_on_invalid_json() { assert!(analyze_text_json("{invalid").is_err()); } }