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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#[cfg(test)]
mod tests {
use serde_yml::{de::Event, modules::path::Path};
/// Test the `Path::Root` variant.
///
/// This test ensures that the `Root` path is correctly formatted as ".".
#[test]
fn test_path_root() {
let path = Path::Root;
assert_eq!(format!("{}", path), ".");
}
/// Test the `Path::Seq` variant.
///
/// This test checks that a sequence path with a given index is correctly formatted.
#[test]
fn test_path_seq() {
let root = Path::Root;
let path = Path::Seq {
parent: &root,
index: 42,
};
assert_eq!(format!("{}", path), "\\[42\\]");
}
/// Test the `Path::Seq` variant with a very large index.
///
/// This test checks that a sequence path with a large index is correctly formatted.
#[test]
fn test_path_seq_large_index() {
let root = Path::Root;
let path = Path::Seq {
parent: &root,
index: usize::MAX,
};
assert_eq!(
format!("{}", path),
format!("\\[{}\\]", usize::MAX)
);
}
/// Test the `Path::Seq` variant with a nested parent.
///
/// This test checks that a sequence path with a parent sequence is correctly formatted.
#[test]
fn test_seq_with_parent() {
let root = Path::Root;
let parent_seq = Path::Seq {
parent: &root,
index: 1,
};
let child_seq = Path::Seq {
parent: &parent_seq,
index: 42,
};
assert_eq!(format!("{}", child_seq), "\\[1\\].\\[42\\]");
}
/// Test the `Path::Seq` variant with different indices.
///
/// This test validates that various index values in the `Seq` variant are correctly formatted.
#[test]
fn test_seq_with_different_indices() {
let root = Path::Root;
let path_zero = Path::Seq {
parent: &root,
index: 0,
};
assert_eq!(format!("{}", path_zero), "\\[0\\]");
let path_large = Path::Seq {
parent: &root,
index: 100,
};
assert_eq!(format!("{}", path_large), "\\[100\\]");
}
/// Test the `Path::Map` variant.
///
/// This test checks that a map path with a given key is correctly formatted.
#[test]
fn test_path_map() {
let root = Path::Root;
let path = Path::Map {
parent: &root,
key: "key_name",
};
assert_eq!(format!("{}", path), "key_name");
}
/// Test the `Path::Map` variant with an empty key.
///
/// This test ensures that a map path with an empty key is correctly handled and formatted.
#[test]
fn test_path_map_empty_key() {
let root = Path::Root;
let path = Path::Map {
parent: &root,
key: "",
};
assert_eq!(format!("{}", path), "");
}
/// Test the `Path::Map` variant with different keys.
///
/// This test validates that various key values in the `Map` variant are correctly formatted.
#[test]
fn test_map_with_different_keys() {
let root = Path::Root;
let path_empty_key = Path::Map {
parent: &root,
key: "",
};
assert_eq!(format!("{}", path_empty_key), "");
let path_special_key = Path::Map {
parent: &root,
key: "special_key",
};
assert_eq!(format!("{}", path_special_key), "special_key");
let path_number_key = Path::Map {
parent: &root,
key: "123",
};
assert_eq!(format!("{}", path_number_key), "123");
}
/// Test the `Path::Map` variant with a parent sequence.
///
/// This test checks that the `parent` field in a `Map` variant is correctly formatted.
#[test]
fn test_map_with_parent() {
let root = Path::Root;
let parent_seq = Path::Seq {
parent: &root,
index: 1,
};
let map = Path::Map {
parent: &parent_seq,
key: "key",
};
assert_eq!(format!("{}", map), "\\[1\\].key");
}
/// Test the `Path::Alias` variant.
///
/// This test checks that an alias path is correctly formatted.
#[test]
fn test_path_alias() {
let root = Path::Root;
let path = Path::Alias { parent: &root };
assert_eq!(format!("{}", path), "");
}
/// Test the `Path::Alias` variant with a parent map.
///
/// This test checks that the `parent` field in an `Alias` variant is correctly formatted.
#[test]
fn test_alias_with_parent() {
let root = Path::Root;
let parent_map = Path::Map {
parent: &root,
key: "parent_key",
};
let alias = Path::Alias {
parent: &parent_map,
};
assert_eq!(format!("{}", alias), "parent_key.");
}
/// Test the `Path::Unknown` variant.
///
/// This test checks that an unknown path is correctly formatted.
#[test]
fn test_path_unknown() {
let root = Path::Root;
let path = Path::Unknown { parent: &root };
assert_eq!(format!("{}", path), "?");
}
/// Test the `Path::Unknown` variant with a parent map.
///
/// This test checks that the `parent` field in an `Unknown` variant is correctly formatted.
#[test]
fn test_unknown_with_parent() {
let root = Path::Root;
let parent_map = Path::Map {
parent: &root,
key: "parent_key",
};
let unknown = Path::Unknown {
parent: &parent_map,
};
assert_eq!(format!("{}", unknown), "parent_key.?");
}
/// Test equality of two `Path` instances with the same structure.
///
/// This test checks that two instances of `Path` with identical structures are considered equal.
#[test]
fn test_path_equality() {
let root = Path::Root;
let seq1 = Path::Seq {
parent: &root,
index: 42,
};
let seq2 = Path::Seq {
parent: &root,
index: 42,
};
assert_eq!(seq1, seq2);
}
/// Test cloning and copying a `Path` instance.
///
/// This test checks that copying a `Path` instance results in an identical path.
#[test]
fn test_path_clone_and_copy() {
let root = Path::Root;
let seq = Path::Seq {
parent: &root,
index: 42,
};
// No need to explicitly clone, just copy directly
let seq_copy = seq;
assert_eq!(seq, seq_copy);
}
/// Test nested paths.
///
/// This test ensures that nested paths with various combinations of variants are correctly formatted.
#[test]
fn test_path_nested() {
let root = Path::Root;
let seq = Path::Seq {
parent: &root,
index: 0,
};
let map = Path::Map {
parent: &seq,
key: "key",
};
let alias = Path::Alias { parent: &map };
let unknown = Path::Unknown { parent: &alias };
assert_eq!(format!("{}", unknown), "\\[0\\].key..?");
}
/// Test deeply nested paths.
///
/// This test checks the formatting of a deeply nested path with multiple levels of sequences and maps.
#[test]
fn test_deeply_nested_path() {
let root = Path::Root;
let seq1 = Path::Seq {
parent: &root,
index: 1,
};
let map1 = Path::Map {
parent: &seq1,
key: "first",
};
let seq2 = Path::Seq {
parent: &map1,
index: 2,
};
let map2 = Path::Map {
parent: &seq2,
key: "second",
};
let alias = Path::Alias { parent: &map2 };
let unknown = Path::Unknown { parent: &alias };
assert_eq!(
format!("{}", unknown),
"\\[1\\].first.\\[2\\].second..?"
);
}
/// Test a complex nested structure with a `Seq` inside a `Map` inside another `Seq`.
///
/// This test checks the formatting of a complex nested structure involving sequences and maps.
#[test]
fn test_path_complex_nested() {
let root = Path::Root;
let seq1 = Path::Seq {
parent: &root,
index: 1,
};
let map = Path::Map {
parent: &seq1,
key: "key",
};
let seq2 = Path::Seq {
parent: &map,
index: 99,
};
assert_eq!(format!("{}", seq2), "\\[1\\].key.\\[99\\]");
}
/// Test panic for unexpected end of sequence.
#[test]
#[should_panic(expected = "unexpected end of sequence")]
fn test_panic_unexpected_end_of_sequence() {
panic!("unexpected end of sequence");
}
/// Test panic for unexpected end of mapping.
#[test]
#[should_panic(expected = "unexpected end of mapping")]
fn test_panic_unexpected_end_of_mapping() {
panic!("unexpected end of mapping");
}
/// Test deserialization of the `Alias` variant in the `Event` enum.
///
/// This test checks that the `Alias` variant is correctly handled in the `Event` enum.
#[test]
fn test_event_alias_variant() {
let alias_index: usize = 42; // Example index
let event = Event::Alias(alias_index);
// Match the alias case to ensure it handles the usize correctly
if let Event::Alias(index) = event {
assert_eq!(index, alias_index);
} else {
panic!("Failed to match the Alias variant.");
}
}
}