MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / verify_pretty_statement

Function verify_pretty_statement

src/sql-pretty/tests/parser.rs:79–117  ·  view source on GitHub ↗
(stmt: &str)

Source from the content-addressed store, hash-verified

77}
78
79fn verify_pretty_statement(stmt: &str) {
80 let original = match parse_statements(stmt) {
81 Ok(stmt) => match stmt.into_iter().next() {
82 Some(stmt) => stmt,
83 None => return,
84 },
85 Err(_) => return,
86 };
87 for width in &[1, 40, 1000000] {
88 let width = *width;
89 let pretty1 = to_pretty(
90 &original.ast,
91 PrettyConfig {
92 width,
93 format_mode: FormatMode::Simple,
94 },
95 );
96 let prettied = parse_statements(&pretty1)
97 .unwrap_or_else(|_| panic!("could not parse: {pretty1}, original: {stmt}"))
98 .into_iter()
99 .next()
100 .unwrap();
101 let pretty2 = to_pretty(
102 &prettied.ast,
103 PrettyConfig {
104 width,
105 format_mode: FormatMode::Simple,
106 },
107 );
108 assert_eq!(pretty1, pretty2);
109 assert_eq!(
110 original.ast.to_ast_string_stable(),
111 prettied.ast.to_ast_string_stable(),
112 "\noriginal: {stmt}",
113 );
114 // It'd be nice to assert that this squashes to a single line at high Ns, but literals and
115 // idents can contain newlines so that's not always possible.
116 }
117}

Callers 1

test_parserFunction · 0.85

Calls 5

to_prettyFunction · 0.85
unwrapMethod · 0.80
parse_statementsFunction · 0.50
nextMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected