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
//! Integration Tests: Sequence Null vs Empty String
//!
//! Tests YAML parsing behavior for sequences containing null values versus empty strings.
//! Ensures correct differentiation and handling of `null` and `""` in sequence contexts.
//!
//! Copyright (c) 2026 YAML Library Developers
use crate::{BufferSource, Node, parse};
#[test]
fn test_sequence_null_vs_empty_string_cases() {
let cases = vec![
(
b"-\n-\n" as &[u8],
vec![Node::None, Node::None],
"dash + newline",
),
(
b"- \n- \n",
vec![Node::None, Node::None],
"dash + space + newline",
),
(
b"- ''\n- \"\"\n",
vec![
Node::Str(
String::new(),
crate::nodes::node::QuoteType::Single,
crate::nodes::node::BlockStyle::None,
),
Node::Str(
String::new(),
crate::nodes::node::QuoteType::Double,
crate::nodes::node::BlockStyle::None,
),
],
"explicit empty strings",
),
];
for (yaml, expected, label) in cases {
let node = {
let mut source = BufferSource::new(yaml);
parse(&mut source).expect(label)
};
let arr = match &node {
Node::Document(items) => {
if let Some(Node::Array(arr)) = items.first() {
arr
} else {
panic!(
"{}: Expected Array as first document element, got: {:#?}",
label, node
)
}
}
Node::Documents(docs) => {
if let Some(Node::Document(items)) = docs.first() {
if let Some(Node::Array(arr)) = items.first() {
arr
} else {
panic!(
"{}: Expected Array as first document element, got: {:#?}",
label, node
)
}
} else {
panic!(
"{}: Expected Document as first element in Documents, got: {:#?}",
label, node
)
}
}
_ => panic!(
"{}: Expected Document or Documents at root, got: {:#?}",
label, node
),
};
assert_eq!(
arr.len(),
expected.len(),
"{}: Array length mismatch",
label
);
for (i, (item, exp)) in arr.iter().zip(expected.iter()).enumerate() {
assert_eq!(
item, exp,
"{}: Item {} mismatch: got {:#?}, expected {:#?}",
label, i, item, exp
);
}
}
}