MCPcopy Create free account
hub / github.com/Glyphack/enderpy / assert_ast_eq

Function assert_ast_eq

compat/src/parser_compat.rs:47–91  ·  view source on GitHub ↗
(python_ast: &Value, enderpy_ast: &Value, source: &str)

Source from the content-addressed store, hash-verified

45}
46
47fn assert_ast_eq(python_ast: &Value, enderpy_ast: &Value, source: &str) {
48 let include_source = std::env::var("INCLUDE_SOURCE").is_ok();
49 let side_by_side = std::env::var("SIDE_BY_SIDE").is_ok();
50
51 let formatted_source = if include_source {
52 format!("\nSource:\n{}\n", source)
53 } else {
54 "".to_string()
55 };
56 if !side_by_side {
57 pretty_assertions::assert_eq!(
58 &python_ast,
59 &enderpy_ast,
60 "Enderpy AST does not match Python AST.\n{}\x1b[31mPython AST\x1b[0m / \x1b[32mEnderpy AST\x1b[0m",
61 formatted_source,
62 );
63 } else if let Err(message) = assert_json_matches_no_panic(
64 &python_ast,
65 &enderpy_ast,
66 assert_json_diff::Config::new(assert_json_diff::CompareMode::Strict),
67 ) {
68 let mut table_builder = Builder::default();
69 table_builder.push_record(["Python AST", "Enderpy AST"]);
70 table_builder.push_record([
71 serde_json::to_string_pretty(&python_ast).unwrap(),
72 serde_json::to_string_pretty(&enderpy_ast).unwrap(),
73 ]);
74 let mut table = table_builder.build();
75 table.with(Style::modern());
76 // If run in a terminal, don't expand table beyond terminal width.
77 if let Some((TerminalWidth(width), _)) = terminal_size() {
78 table
79 .with(
80 Width::wrap(width as usize)
81 .keep_words(true)
82 .priority(PriorityMax),
83 )
84 .with(Width::increase(width as usize));
85 }
86 panic!(
87 "Enderpy AST does not match Python AST.\n{}{}\n{}",
88 formatted_source, table, message
89 );
90 }
91}
92fn remove_unimplemented_attributes(value: &mut Value) {
93 match value {
94 Value::Object(map) => {

Callers 1

python_parser_test_astFunction · 0.85

Calls 2

to_stringMethod · 0.80
buildMethod · 0.45

Tested by

no test coverage detected