1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![allow(clippy::unwrap_used, dead_code, missing_docs)]
use specta::{Type, Types};
use specta_swift::Swift;
// Test with common types that might not have Type implementations
#[derive(Type)]
struct TestStruct {
// Basic types that should work
id: u32,
name: String,
email: Option<String>,
// These might not have Type implementations
// uuid: uuid::Uuid, // Commented out - likely not supported
// created_at: chrono::DateTime<chrono::Utc>, // Commented out - likely not supported
}
#[derive(Type)]
enum TestEnum {
Unit,
Tuple(String, u32),
Named { id: u32, name: String },
}
#[test]
fn test_common_types() {
let types = Types::default()
.register::<TestStruct>()
.register::<TestEnum>();
let swift = Swift::default();
let output = swift.export(&types, specta_serde::Format).unwrap();
println!("Generated Swift code:\n{}", output);
// Test that basic types work
assert!(output.contains("struct TestStruct"));
assert!(output.contains("enum TestEnum"));
assert!(output.contains("let id: UInt32"));
assert!(output.contains("let name: String"));
assert!(output.contains("let email: String?"));
}
// Test what happens when we try to use unsupported types
#[test]
fn test_unsupported_types() {
// This test will fail to compile if UUID doesn't have Type implementation
// Uncomment to test:
/*
#[derive(Type)]
struct WithUuid {
id: uuid::Uuid,
}
let types = Types::default().register::<WithUuid>();
let swift = Swift::default();
let output = swift.export(&types).unwrap();
println!("UUID support: {}", output);
*/
}