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
//! Unit tests for isolated session elements
//!
//! Tests session parsing in isolation following the on-lexplore.lex guidelines:
//! - Use Lexplore to load centralized test files
//! - Use assert_ast for deep structure verification
//! - Test isolated elements (one element per test)
//! - Verify content and structure, not just counts
use lex_core::lex::testing::assert_ast;
use lex_core::lex::testing::lexplore::Lexplore;
#[test]
fn test_session_01_flat_simple() {
// session-01-flat-simple.lex: Session with title "Introduction" and one paragraph
let doc = Lexplore::session(1).parse().unwrap();
assert_ast(&doc).item_count(1).item(0, |item| {
item.assert_session()
.label("Introduction")
.child_count(1)
.child(0, |child| {
child
.assert_paragraph()
.text_contains("simple session with a title");
});
});
}
#[test]
fn test_session_02_flat_numbered_title() {
// session-02-flat-numbered-title.lex: Session with numbered title "1. Introduction:"
let doc = Lexplore::session(2).parse().unwrap();
assert_ast(&doc).item_count(1).item(0, |item| {
item.assert_session()
.label("1. Introduction:")
.child_count(1)
.child(0, |child| {
child
.assert_paragraph()
.text_contains("numbered title marker");
});
});
}
#[test]
fn test_session_05_nested_simple() {
// session-05-nested-simple.lex: Document with paragraphs and nested sessions
let doc = Lexplore::session(5).parse().unwrap();
// Document structure: Para, Session, Para, Session, Para
assert_ast(&doc)
.item_count(5)
.item(0, |item| {
item.assert_paragraph()
.text_contains("combination of paragraphs");
})
.item(1, |item| {
item.assert_session()
.label("1. Introduction {{session-title}}")
.child_count(2)
.child(0, |child| {
child
.assert_paragraph()
.text_contains("content of the session");
})
.child(1, |child| {
child
.assert_paragraph()
.text_contains("multiple paragraphs");
});
})
.item(2, |item| {
item.assert_paragraph()
.text_contains("paragraph comes after the session");
})
.item(3, |item| {
item.assert_session()
.label("Another Session {{session-title}}")
.child_count(1)
.child(0, |child| {
child
.assert_paragraph()
.text_contains("multiple sessions at the same level");
});
})
.item(4, |item| {
item.assert_paragraph()
.text_contains("Final paragraph at the root level");
});
}
#[test]
fn test_session_03_flat_multiple_paragraphs() {
let doc = Lexplore::session(3).parse().unwrap();
assert_ast(&doc).item_count(1).item(0, |item| {
item.assert_session()
.label("Background:")
.child_count(3)
.child(0, |child| {
child
.assert_paragraph()
.text_contains("contains multiple paragraphs");
})
.child(1, |child| {
child
.assert_paragraph()
.text_contains("Each paragraph is indented");
})
.child(2, |child| {
child.assert_paragraph().text_contains("third paragraph");
});
});
}
#[test]
fn test_session_04_flat_alphanumeric_title() {
let doc = Lexplore::session(4).parse().unwrap();
assert_ast(&doc).item_count(1).item(0, |item| {
item.assert_session()
.label("A. First Section:")
.child(0, |child| {
child
.assert_paragraph()
.text_contains("alphabetical markers in their titles");
});
});
}
#[test]
fn test_session_07_paragraphs_sessions_flat_multiple() {
let doc = Lexplore::session(7).parse().unwrap();
assert_ast(&doc)
.item_count(8)
.item(1, |item| {
item.assert_session()
.label("1. First Session {{session-title}}")
.child(0, |child| {
child
.assert_paragraph()
.text_contains("content of the first session");
});
})
.item(4, |item| {
item.assert_session()
.label("3. Third Session {{session-title}}")
.child(0, |child| {
child
.assert_paragraph()
.text_contains("different amounts of content");
});
})
.item(6, |item| {
item.assert_session()
.label("4. Session Without Numbering {{session-title}}")
.child(0, |child| {
child
.assert_session()
.label("Session titles don't require numbering markers. {{session-title}}")
.child(0, |grandchild| {
grandchild
.assert_paragraph()
.text_contains("followed by a blank line");
});
});
});
}
#[test]
fn test_session_08_paragraphs_sessions_nested_multiple() {
let doc = Lexplore::session(8).parse().unwrap();
assert_ast(&doc)
.item_count(4)
.item(1, |item| {
item.assert_session()
.label("1. Root Session {{session-title}}")
.child(1, |child| {
child
.assert_session()
.label("1.1. First Sub-session {{session-title}}")
.child(0, |grandchild| {
grandchild
.assert_paragraph()
.text_contains("second nesting level");
});
});
})
.item(2, |item| {
item.assert_session()
.label("2. Another Root Session {{session-title}}")
.child(0, |child| {
child
.assert_paragraph()
.text_contains("root level alongside the first");
});
});
}
#[test]
fn test_session_09_flat_colon_title() {
// session-09-flat-colon-title.lex: Session title ending with colon (bug #212)
// Tests that sessions can have colons in their titles, distinguished from definitions
// by blank lines between title and content
let doc = Lexplore::session(9).parse().unwrap();
assert_ast(&doc).item_count(1).item(0, |item| {
item.assert_session()
.label("Subject Title:")
.child(0, |child| {
child
.assert_paragraph()
.text_contains("session whose title ends with a colon");
});
});
}
#[test]
fn test_session_10_sandwich_document() {
// Validates the session-list-session "sandwich" document exercises:
// - Consecutive sessions without blank separators
// - Lists at the document root between sessions
// - Sessions nesting lists as their content
let doc = Lexplore::session(10).parse().unwrap();
assert_ast(&doc)
// Blank line groups are filtered out by assert_ast, so only the structural
// elements remain: session, session, list, session.
.item_count(4)
.item(0, |item| {
item.assert_session()
.label("1. Session Title")
.child(0, |child| {
child
.assert_session()
.label("1.1. Session Title")
.child(0, |grandchild| {
grandchild
.assert_paragraph()
.text_contains("1.1.1 Session Title");
});
});
})
.item(1, |item| {
item.assert_session()
.label("2. Session Title")
.child(0, |child| {
child.assert_paragraph().text_contains("2.1 Session Title");
});
})
.item(2, |item| {
item.assert_list()
.item_count(2)
.item(0, |list_item| {
list_item.text_contains("And this is a list");
})
.item(1, |list_item| {
list_item.text_contains("scond list item");
});
})
.item(3, |item| {
item.assert_session()
.label("3. Session title")
.child(0, |child| {
child
.assert_list()
.item_count(2)
.item(0, |list_item| {
list_item.text_contains("list item, first");
})
.item(1, |list_item| {
list_item.text_contains("second list item");
});
});
});
}