()
| 105 | |
| 106 | #[test] |
| 107 | fn test_save_and_load_array() -> Result<()> { |
| 108 | let test_dir = setup_test_dir(); |
| 109 | |
| 110 | let prefs = PreferenceConfig::new(test_dir.clone())?; |
| 111 | |
| 112 | // Create test array data |
| 113 | let test_array = vec![ |
| 114 | TestConfig { |
| 115 | string_value: "item1".to_string(), |
| 116 | number_value: 1, |
| 117 | boolean_value: true, |
| 118 | }, |
| 119 | TestConfig { |
| 120 | string_value: "item2".to_string(), |
| 121 | number_value: 2, |
| 122 | boolean_value: false, |
| 123 | }, |
| 124 | ]; |
| 125 | |
| 126 | // Convert the array to a Value and save it directly |
| 127 | let array_json = serde_json::to_value(&test_array)?; |
| 128 | |
| 129 | // Save with dot notation for the key path |
| 130 | prefs.save_selective("test.array_key".to_string(), Some(array_json))?; |
| 131 | |
| 132 | // First approach: Try to load individual items using array index notation |
| 133 | let item0: TestConfig = prefs.load_selective("test.array_key.0".to_string())?; |
| 134 | let item1: TestConfig = prefs.load_selective("test.array_key.1".to_string())?; |
| 135 | |
| 136 | // Verify individual items |
| 137 | assert_eq!(item0.string_value, "item1", "First item should be correct"); |
| 138 | assert_eq!(item1.number_value, 2, "Second item should be correct"); |
| 139 | |
| 140 | // Second approach: If direct array loading is supported |
| 141 | // Try a simpler test first to see if array loading works |
| 142 | let simple_array = vec![1, 2, 3]; |
| 143 | prefs.save_selective("test.simple_array".to_string(), Some(json!(simple_array)))?; |
| 144 | |
| 145 | // Try to load the simple array |
| 146 | let loaded_simple: Vec<i32> = prefs.load_selective("test.simple_array".to_string())?; |
| 147 | assert_eq!( |
| 148 | loaded_simple, |
| 149 | vec![1, 2, 3], |
| 150 | "Simple array should load correctly" |
| 151 | ); |
| 152 | |
| 153 | cleanup_test_dir(test_dir); |
| 154 | Ok(()) |
| 155 | } |
| 156 | |
| 157 | #[test] |
| 158 | fn test_secure_preferences() -> Result<()> { |
nothing calls this directly
no test coverage detected