Skip to main content

python_ast/ast/tree/
list.rs

1//! Python list expressions are represented as `ExprType::List` and generated
2//! by the `"List"` arm of the expression codegen (see `expression.rs`). The
3//! second, unused `List<'a>` AST type that used to live here — with its own,
4//! divergent codegen — was removed as dead code.
5
6// It's fairly easy to break the automatic parsing of parameter structs, so we need to have fairly sophisticated
7// test coverage for the various types of
8#[cfg(test)]
9mod tests {
10    use crate::ExprType;
11    use crate::StatementType;
12    use std::panic;
13    use test_log::test;
14
15    #[test]
16    fn parse_list() {
17        let module = crate::parse("[1, 2, 3]", "nothing.py").unwrap();
18        let statement = module.raw.body[0].statement.clone();
19        match statement {
20            StatementType::Expr(e) => match e.value {
21                ExprType::List(list) => {
22                    tracing::debug!("{:#?}", list);
23                    assert_eq!(list.len(), 3);
24                }
25                _ => panic!("Could not find inner expression"),
26            },
27            _ => panic!("Could not find outer expression."),
28        }
29    }
30}