use cpp_parser::{
CppParser, CppSyntaxKind, CppSyntaxNode, CppSyntaxTree, CppTokenKind, ParserConfig, is_trivia,
};
fn collect_nodes(root: &CppSyntaxNode) -> Vec<(CppSyntaxKind, usize, usize, usize)> {
let mut out = Vec::new();
let mut stack = vec![(root.clone(), 0usize)];
while let Some((node, depth)) = stack.pop() {
let range = node.text_range();
out.push((
CppSyntaxKind::from(node.kind()),
usize::from(range.start()),
usize::from(range.end()),
depth,
));
let children: Vec<_> = node.children().collect();
for child in children.into_iter().rev() {
stack.push((child, depth + 1));
}
}
out
}
#[track_caller]
fn assert_lossless(source: &str, tree: &CppSyntaxTree) {
assert_eq!(
tree.to_source_text(),
source,
"I1 violated: the tree does not reproduce the input"
);
assert_eq!(
tree.text_len(),
source.len(),
"I1 violated: tree length differs from input length"
);
}
#[track_caller]
fn assert_well_formed(tree: &CppSyntaxTree) {
let root = tree.get_red_root();
assert_eq!(
root.descendants()
.filter(|node| CppSyntaxKind::from(node.kind()) == CppSyntaxKind::TranslationUnit)
.count(),
1,
"I2 violated: the tree contains more than one TranslationUnit"
);
for node in root.descendants() {
let parent = node.text_range();
let mut previous_end: Option<usize> = None;
let mut first_start: Option<usize> = None;
for child in node.children_with_tokens() {
let range = child.text_range();
let start = usize::from(range.start());
let end = usize::from(range.end());
assert!(
start <= end,
"I2 violated: inverted range {start}..{end} inside {node:?}"
);
assert!(
start >= usize::from(parent.start()) && end <= usize::from(parent.end()),
"I2 violated: child {start}..{end} escapes parent {}..{} inside {node:?}",
usize::from(parent.start()),
usize::from(parent.end())
);
if let Some(prev_end) = previous_end {
assert!(
start >= prev_end,
"I2 violated: sibling overlap or out-of-order tokens ({prev_end} > {start}) \
inside {node:?}"
);
}
first_start.get_or_insert(start);
previous_end = Some(end);
}
if let (Some(first), Some(last)) = (first_start, previous_end) {
assert_eq!(
first,
usize::from(parent.start()),
"I2 violated: leading gap in {node:?}"
);
assert_eq!(
last,
usize::from(parent.end()),
"I2 violated: trailing gap in {node:?}"
);
} else {
assert!(
parent.is_empty(),
"I2 violated: childless node {node:?} covers {}..{}",
usize::from(parent.start()),
usize::from(parent.end())
);
}
}
}
#[track_caller]
fn assert_parses(source: &str) -> CppSyntaxTree {
let tree = CppParser::parse(source, ParserConfig::default());
assert_eq!(
tree.root_kind(),
CppSyntaxKind::TranslationUnit,
"I4 violated: root is {:?}",
tree.root_kind()
);
assert_lossless(source, &tree);
assert_well_formed(&tree);
tree
}
const CORPUS: &[(&str, &str)] = &[
("empty", ""),
("whitespace only", " \n\t\n "),
("comment only", "// just a comment\n/* and a block */\n"),
(
"documentation comments",
"/// Computes the distance.\n\
/// @param[in] a the first point\n\
/// @param[in] b the second point\n\
/// @returns the distance\n\
/// @code\n\
/// double d = distance(p, q);\n\
/// @endcode\n\
double distance(const Point& a, const Point& b);\n\
\n\
/** A point.\n * @brief Short.\n */\n\
struct Point { double x; };\n\
\n\
class C {\npublic:\n /// documents m\n int m;\n};\n",
),
(
"comments in every position",
"int /* before the name */ x;\n\
int y; ///< trailing\n\
void f() {\n /// inside a body\n int z = 1;\n}\n\
/* unterminated at the end of the file",
),
(
"hello world",
"#include <iostream>\n\nint main() {\n std::cout << \"hi\" << std::endl;\n return 0;\n}\n",
),
(
"class with access specifiers",
"class Foo : public Bar, private Baz {\npublic:\n Foo();\n ~Foo();\n int value() const noexcept;\nprivate:\n int value_;\n};\n",
),
(
"templates and nested angles",
"template <typename T, int N>\nstruct Vec {\n T data[N];\n auto begin() -> T* { return data; }\n};\n",
),
(
"nested template-id with non-type argument",
"Vec<std::vector<int>, 3> v;\n",
),
(
"lambdas",
"auto f = [x = 1](int y) mutable -> int { return x + y; };\n",
),
(
"raw strings",
concat!(
"auto a = R\"(plain)\";\n",
"auto b = R\"(has \"quotes\" and \\backslashes)\";\n",
"auto c = R\"delim(contains )\" without ending)delim\";\n",
"auto d = u8R\"(utf8 raw)\";\n",
"auto e = LR\"(wide raw)\";\n",
),
),
(
"prefixed literals",
"auto a = u8\"utf8\";\nauto b = u\"utf16\";\nauto c = U\"utf32\";\nauto d = L\"wide\";\nauto e = u'c';\n",
),
(
"numbers and suffixes",
"auto a = 1'000'000;\nauto b = 0xFF'FF;\nauto c = 0b1010'1010;\nauto d = 42_km;\nauto e = 1.5_deg;\n",
),
(
"line splices",
"#define GREETING \\\n \"hi\"\nint x = 1 + \\\n 2;\n",
),
(
"unicode identifiers",
"int café = 1;\nint λ = 2;\nint \\u00e9 = 3;\n",
),
(
"structured bindings",
concat!(
"auto [a, b] = pair;\n",
"const auto& [k, v] = map;\n",
"auto&& [x, y] = other;\n",
"auto [... pack] = rest;\n",
),
),
(
"consteval if",
"if consteval { f(); } else { g(); }\nif !consteval { h(); }\nif constexpr (x) {}\n",
),
(
"literal operator templates",
concat!(
"long double operator\"\"_km(long double x);\n",
"constexpr unsigned long long operator\"\"_km(unsigned long long x) { return x; }\n",
),
),
(
"nested-looking block comment",
"/* /* this does not nest */ int x;\n",
),
(
"modules",
concat!(
"export module my.mod;\n",
"import std;\n",
"export import :part;\n",
"import <iostream>;\n",
"export { void exported(); }\n",
),
),
(
"module partitions and fragments",
concat!(
"module;\n",
"#include <stdlib.h>\n",
"export module A:B;\n",
"import :C;\n",
"export int f();\n",
"module : private;\n",
"int f() { return 42; }\n",
),
),
(
"module and import as ordinary names",
"int module = 1;\nauto import = module;\n",
),
(
"requires and concept as ordinary names",
concat!(
"int requires = 1;\n",
"int concept = 2;\n",
"void f() { int requires = 1; int concept = 2; }\n",
"void f() { requires = 1; concept = 2; }\n",
"void f() { requires(); concept(); }\n",
"void f() { g(requires, concept); }\n",
"void f(int requires, int concept);\n",
"struct S { int requires; int concept; };\n",
"void requires();\n",
),
),
("labels", "void f() {\nagain:\n goto again;\n}\n"),
(
"range-based for",
concat!(
"void f() {\n",
" for (auto x : items) {}\n",
" for (int y : items) {}\n",
" for (auto& z : items) {}\n",
" for (const auto& w : items) {}\n",
" for (auto [key, value] : map) {}\n",
" for (auto x : make_items()) {}\n",
" for (auto x : a ? b : c) {}\n",
" for (;;) { break; }\n",
" for (int i = 0; i < 3; ++i) {}\n",
" for (int i = c ? 1 : 2; i < 3; ++i) {}\n",
" for co_await (auto v : gen()) {}\n",
"}\n",
),
),
(
"assignment and compound assignment",
concat!(
"void f() {\n",
" a = b;\n",
" i += 1;\n",
" i -= 1;\n",
" i *= 2;\n",
" i /= 2;\n",
" i %= 2;\n",
" flags &= mask;\n",
" flags |= mask;\n",
" flags ^= mask;\n",
" value <<= 2;\n",
" value >>= 2;\n",
" *p = *q = 5;\n",
" arr[0] = 1;\n",
" arr[0] += 1;\n",
" p->field = 1;\n",
" obj.field = obj.other;\n",
" x = y + z * w;\n",
"}\n",
),
),
(
"member initializer lists",
concat!(
"struct S {\n",
" S() : a(1), b(2) {}\n",
" S(int x) : a(x) {}\n",
" S() noexcept : a(0) {}\n",
" S() : a{1} {}\n",
" int a;\n",
" int b;\n",
"};\n",
"struct D : B {\n",
" D() : B(1) {}\n",
"};\n",
),
),
(
"parenthesized expressions and the conditional operator",
concat!(
"void f() {\n",
" x = (a);\n",
" x = (a + b);\n",
" x = (f());\n",
" x = a * (b + c);\n",
" x = ((a));\n",
" x = a ? b : c;\n",
" x = (a > b) ? a : b;\n",
" x = (a ? b : c) ? d : e;\n",
" x = cond ? (a + b) : (c + d);\n",
" f((a), (b));\n",
" if ((a)) { }\n",
" while ((a && b)) { }\n",
" auto y = (a > b) ? a : b;\n",
" return (a) ? (b) : (c);\n",
"}\n",
),
),
(
"lambda expressions",
concat!(
"void f() {\n",
" auto a = [] {};\n",
" auto b = []() { return 1; };\n",
" auto c = [](int x) { return x; };\n",
" auto d = [&](int x) { return x + 1; };\n",
" auto e = [x](int y) { return x + y; };\n",
" auto g = [&x, y]() { return x + y; };\n",
" auto h = [=]() { return x; };\n",
" auto i = [this]() { return n; };\n",
" auto j = [*this]() { return n; };\n",
" auto k = []() mutable { };\n",
" auto l = []() constexpr { };\n",
" auto m = []() noexcept { };\n",
" auto n = [](int x) -> int { return x; };\n",
" auto o = [p = 1]() { return p; };\n",
" auto q = [n](auto x) { return x; };\n",
" auto r = [x, &y]() { };\n",
" std::sort(v.begin(), v.end(), [](int i, int j) { return i < j; });\n",
" call([](int i) { return i; }, 1);\n",
" arr[index] = 1;\n",
" auto s = a[b];\n",
" int t[] = {1, 2};\n",
"}\n",
"auto file_scope = [](int x) { return x; };\n",
),
),
(
"preprocessor soup",
"#pragma once\n#include <vector>\n#include \"local.h\"\n#define MAX(a, b) ((a) > (b) ? (a) : (b))\n#if defined(FOO) && FOO > 2\nextern \"C\" {\n#endif\nvoid f();\n#ifdef BAR\n}\n#endif\n",
),
(
"modules",
"export module my.mod:part;\nimport <iostream>;\nimport :other;\nexport import std.core;\nexport {\n void exported();\n}\n",
),
("namespace", "namespace a {\nint x;\n}\n"),
("using declarations", "using std::vector;\n"),
("enums", "enum Color { Red, Green = 2 };\n"),
(
"scoped enum with underlying type",
"enum class Color : unsigned char { Red, Green = 2 };\n",
),
(
"preprocessor directives",
"#include <vector>\n#include \"local.h\"\n#define MAX 10\nint x;\n",
),
("missing closing brace", "int main() {\n return 0;\n"),
("missing semicolon", "int x = 1\nint y = 2;\n"),
("stray closing brace", "int f() { return 1; } }\nint g();\n"),
("truncated mid-expression", "int f() { return a + \n"),
("unterminated string", "const char* s = \"oops\nint x;\n"),
("unterminated block comment", "int x; /* never closed\n"),
("garbage", "@#$%^&* \u{1F600} \u{4e2d}\u{6587} ???\n"),
(
"unbalanced preprocessor branch",
"#if A\nvoid f() {\n#else\nvoid f() {}\n#endif\n}\n",
),
(
"macro that hides braces",
"BEGIN_NAMESPACE(foo)\nclass A {};\nEND_NAMESPACE(foo)\n",
),
];
#[test]
fn corpus_satisfies_structural_invariants() {
for (name, source) in CORPUS {
let tree = assert_parses(source);
let nodes = collect_nodes(&tree.get_red_root());
assert!(
nodes.len() <= source.len() + 1,
"{name}: tree has {} nodes for {} bytes, which suggests runaway node creation",
nodes.len(),
source.len()
);
}
}
#[test]
fn corpus_reparse_is_idempotent() {
for (name, source) in CORPUS {
let first = assert_parses(source);
let text = first.to_source_text();
let second = assert_parses(&text);
let first_shape = format!("{:#?}", first.get_red_root());
let second_shape = format!("{:#?}", second.get_red_root());
assert_eq!(
first_shape, second_shape,
"{name}: re-parsing the tree's own text produced a different structure"
);
}
}
#[test]
fn every_prefix_of_every_sample_is_parseable() {
for (name, source) in CORPUS {
for (end, _) in source.char_indices() {
let prefix = &source[..end];
let tree = CppParser::parse(prefix, ParserConfig::default());
assert_eq!(
tree.to_source_text(),
prefix,
"{name}: I1 violated for prefix of length {end}"
);
assert_well_formed(&tree);
}
}
}
#[test]
fn single_character_deletions_are_parseable() {
for (name, source) in CORPUS {
for (offset, ch) in source.char_indices() {
let mut mutated = String::with_capacity(source.len());
mutated.push_str(&source[..offset]);
mutated.push_str(&source[offset + ch.len_utf8()..]);
let tree = CppParser::parse(&mutated, ParserConfig::default());
assert_eq!(
tree.to_source_text(),
mutated,
"{name}: I1 violated after deleting {ch:?} at {offset}"
);
assert_well_formed(&tree);
}
}
}
#[test]
fn parsing_is_deterministic() {
for (name, source) in CORPUS {
let first = format!(
"{:#?}",
CppParser::parse(source, ParserConfig::default()).get_red_root()
);
let second = format!(
"{:#?}",
CppParser::parse(source, ParserConfig::default()).get_red_root()
);
assert_eq!(first, second, "{name}: parse is not deterministic");
}
}
#[test]
fn trivia_is_preserved() {
let source = "// leading\nint x = 1; // trailing\n\n/* block */ int y;\n";
let tree = assert_parses(source);
let text = tree.to_source_text();
for needle in ["// leading", "// trailing", "/* block */"] {
assert!(
text.contains(needle),
"trivia {needle:?} was dropped from the tree"
);
}
}
#[test]
fn trivia_tokens_tile_the_source_exactly() {
for (name, source) in CORPUS {
let tree = assert_parses(source);
let tokens: Vec<(usize, usize, CppTokenKind)> = tree
.get_red_root()
.descendants_with_tokens()
.filter_map(|element| element.into_token())
.map(|token| {
let range = token.text_range();
(
u32::from(range.start()) as usize,
u32::from(range.end()) as usize,
CppTokenKind::from(token.kind()),
)
})
.collect();
let mut expected = 0usize;
for (start, end, kind) in &tokens {
assert_eq!(
*start, expected,
"{name}: the token {kind:?} at {start}..{end} leaves a hole or overlaps at {expected}"
);
assert!(
end > start || source.is_empty(),
"{name}: the token {kind:?} at {start}..{end} covers nothing"
);
expected = *end;
}
assert_eq!(
expected,
source.len(),
"{name}: the tree's tokens cover {expected} of {} bytes",
source.len()
);
for lexed in lex_source(source)
.iter()
.filter(|token| is_trivia(token.kind))
{
for offset in lexed.range.start_offset..lexed.range.end_offset() {
let covering = tokens
.iter()
.find(|(start, end, _)| *start <= offset && offset < *end);
assert!(
covering.is_some(),
"{name}: byte {offset} is {:?} at {}..{} in the file and no token in the tree \
covers it",
lexed.kind,
lexed.range.start_offset,
lexed.range.end_offset()
);
}
}
let in_tree: std::collections::HashSet<(usize, usize, CppTokenKind)> =
tokens.iter().copied().collect();
for lexed in lex_source(source).iter().filter(|token| {
matches!(
token.kind,
CppTokenKind::Whitespace | CppTokenKind::Newline | CppTokenKind::LineContinuation
)
}) {
assert!(
in_tree.contains(&(
lexed.range.start_offset,
lexed.range.end_offset(),
lexed.kind
)),
"{name}: the {:?} at {}..{} is layout in the file but is spelled differently or \
missing in the tree",
lexed.kind,
lexed.range.start_offset,
lexed.range.end_offset()
);
}
}
}
fn lex_source(source: &str) -> Vec<cpp_parser::CppTokenData> {
cpp_parser::lex(source, &cpp_parser::LexerConfig::default()).0
}
#[test]
fn the_parser_reads_the_stream_the_lexer_produces() {
for (name, source) in CORPUS {
let (lexed, lexical_errors) = cpp_parser::lex(source, &cpp_parser::LexerConfig::default());
let tree = CppParser::parse(source, ParserConfig::default());
for (which, tokens) in [("lex", lexed.as_slice()), ("the tree", tree.get_tokens())] {
let mut text = String::with_capacity(source.len());
for token in tokens {
text.push_str(&source[token.range.start_offset..token.range.end_offset()]);
}
assert_eq!(
text, *source,
"{name}: {which}'s token stream does not reproduce the file"
);
}
assert_only_header_names_were_folded(&lexed, tree.get_tokens(), source, name);
assert_eq!(
&tree.get_errors()[..lexical_errors.len()],
lexical_errors.as_slice(),
"{name}: the lexical diagnostics are not the ones the tree carries"
);
}
}
#[track_caller]
fn assert_only_header_names_were_folded(
lexed: &[cpp_parser::CppTokenData],
parsed: &[cpp_parser::CppTokenData],
source: &str,
name: &str,
) {
let (mut i, mut j) = (0usize, 0usize);
while i < lexed.len() && j < parsed.len() {
if lexed[i] == parsed[j] {
i += 1;
j += 1;
continue;
}
let folded = parsed[j];
assert_eq!(
folded.kind,
cpp_parser::CppTokenKind::HeaderName,
"{name}: the streams differ at {:?} (lexed) against {:?} (parsed), and the difference is \
not a header name",
&source[lexed[i].range.start_offset..lexed[i].range.end_offset()],
&source[folded.range.start_offset..folded.range.end_offset()],
);
let start = folded.range.start_offset;
let end = folded.range.end_offset();
let first = i;
while i < lexed.len() && lexed[i].range.start_offset < end {
assert!(
lexed[i].range.start_offset >= start,
"{name}: run escapes it"
);
i += 1;
}
assert!(i > first, "{name}: a header name replaced no token at all");
j += 1;
}
assert_eq!(
(i, j),
(lexed.len(), parsed.len()),
"{name}: one stream ran out before the other"
);
}
#[test]
fn recovery_leaves_the_event_stream_balanced() {
for (name, source) in CORPUS {
let (_, audit) = CppParser::parse_with_audit(source, ParserConfig::default());
assert_eq!(
audit.min_depth, 0,
"{name}: recovery emitted a NodeEnd for a node that was already closed; \
a whole subtree would be re-parented"
);
assert!(
audit.unclosed.is_empty(),
"{name}: {} node(s) left open ({:?}); everything after them would be swallowed",
audit.unclosed.len(),
audit.unclosed
);
assert!(
audit.is_balanced(),
"{name}: event stream is not balanced: {audit:?}"
);
let (_, events) = CppParser::parse_with_events(source, ParserConfig::default());
let mut starts = 0isize;
let mut ends = 0isize;
for event in &events {
match event {
cpp_parser::MarkEvent::NodeStart {
kind: cpp_parser::CppSyntaxKind::None,
..
} => {}
cpp_parser::MarkEvent::NodeStart { .. } => starts += 1,
cpp_parser::MarkEvent::NodeEnd => ends += 1,
_ => {}
}
}
assert!(
ends <= starts,
"{name}: {ends} node end(s) but only {starts} start(s); the extra ones close the \
wrong node"
);
}
}
fn has_code(source: &str) -> bool {
let mut rest = source;
let mut out = String::new();
while let Some(index) = rest.find("//").or_else(|| rest.find("/*")) {
out.push_str(&rest[..index]);
if rest[index..].starts_with("//") {
match rest[index..].find('\n') {
Some(newline) => rest = &rest[index + newline..],
None => return !out.trim().is_empty(),
}
} else {
match rest[index + 2..].find("*/") {
Some(end) => rest = &rest[index + 2 + end + 2..],
None => return !out.trim().is_empty(),
}
}
}
out.push_str(rest);
!out.trim().is_empty()
}
const MUST_PARSE_CLEANLY: &[&str] = &[
"empty",
"whitespace only",
"comment only",
"hello world",
"class with access specifiers",
"templates and nested angles",
"nested template-id with non-type argument",
"structured bindings",
"consteval if",
"literal operator templates",
"namespace",
"using declarations",
"enums",
"scoped enum with underlying type",
"preprocessor directives",
"modules",
"module partitions and fragments",
"module and import as ordinary names",
"labels",
"range-based for",
"member initializer lists",
"assignment and compound assignment",
"parenthesized expressions and the conditional operator",
"lambda expressions",
"documentation comments",
];
const MUST_REPORT: &[&str] = &[
"missing closing brace",
"missing semicolon",
"stray closing brace",
"truncated mid-expression",
"unterminated string",
"unterminated block comment",
"garbage",
];
const KNOWN_SILENT_ACCEPTANCE: &[&str] = &[
"unbalanced preprocessor branch",
];
#[test]
fn valid_code_parses_cleanly() {
for (name, source) in CORPUS {
if !MUST_PARSE_CLEANLY.contains(name) {
continue;
}
let tree = CppParser::parse(source, ParserConfig::default());
assert!(
tree.get_errors().is_empty(),
"{name}: valid code must parse cleanly, got {:?}",
tree.get_errors()
);
}
}
#[test]
fn malformed_code_is_never_silently_accepted() {
for (name, source) in CORPUS {
if !MUST_REPORT.contains(name) {
continue;
}
let tree = CppParser::parse(source, ParserConfig::default());
if !tree.get_errors().is_empty() {
continue;
}
let recoveries = tree
.get_red_root()
.descendants()
.filter(|node| {
matches!(
CppSyntaxKind::from(node.kind()),
CppSyntaxKind::ErrorNode | CppSyntaxKind::MissingNode
)
})
.count();
assert!(
recoveries > 0 && has_code(source),
"{name}: malformed input produced neither a diagnostic nor an error/missing node, \
so the problem was silently swallowed"
);
}
}
#[test]
fn known_silent_acceptance_set_is_accurate() {
for (name, source) in CORPUS {
if !KNOWN_SILENT_ACCEPTANCE.contains(name) {
continue;
}
let tree = CppParser::parse(source, ParserConfig::default());
assert!(
tree.get_errors().is_empty(),
"{name}: this input is now reported ({:?}); move it from KNOWN_SILENT_ACCEPTANCE to \
MUST_REPORT",
tree.get_errors()
);
}
}
fn known_unparsed() -> [(&'static str, &'static str, &'static str); 0] {
[]
}
#[test]
fn known_unparsed_set_is_accurate() {
for (name, source, reason) in known_unparsed() {
let tree = CppParser::parse(source, ParserConfig::default());
assert_eq!(
tree.to_source_text(),
source,
"{name}: losslessness broken on a known-unparsed input"
);
assert!(
!tree.get_errors().is_empty(),
"{name} now parses cleanly — remove it from known_unparsed. (Documented reason was: \
{reason})"
);
}
}
#[test]
fn a_query_past_the_end_of_the_tree_has_no_token() {
let text = "int main() { return 0; }\n";
let tree = CppParser::parse(text, ParserConfig::default());
let root = tree.get_red_root();
assert!(cpp_parser::token_at(&root, 0).is_some());
assert!(
cpp_parser::token_at(&root, text.len() + 358).is_none(),
"an offset from another text's coordinates is not a token here"
);
assert!(cpp_parser::token_at(&root, usize::MAX).is_none());
}
#[test]
fn a_column_read_inside_a_multibyte_character_is_the_character_before_it() {
let text = "// 汉字译 the word\nint x;\n";
let index = cpp_parser::LineIndex::parse(text);
let inside = text.find('译').expect("the fixture") + 1;
assert!(
!text.is_char_boundary(inside),
"the offset is inside the character"
);
assert_eq!(
index.position_of(inside, text),
Some((0, "// 汉字".chars().count())),
"the column of the character the offset is in, not a panic"
);
assert_eq!(
index.position_of(text.len(), text),
Some((2, 0)),
"and an offset at the very end is still a real position"
);
}
#[test]
fn a_group_that_is_missing_its_closer_leaves_no_marker_open() {
for source in [
"class A { A(; };",
"void f() { std::sort(a(), b(, [](int i, int j) { return i < j; }); }",
] {
let (tree, audit) = CppParser::parse_with_audit(source, ParserConfig::default());
assert_eq!(tree.to_source_text(), source, "I1 violated for {source:?}");
assert!(
audit.is_balanced(),
"{source:?} left a node open: {audit:?}"
);
assert_well_formed(&tree);
}
}