MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_fstring_contains_await

Function test_fstring_contains_await

crates/codegen/src/compile.rs:10588–10706  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10586 /// Test if the compiler can correctly identify fstrings containing an `await` expression.
10587 #[test]
10588 fn test_fstring_contains_await() {
10589 let range = TextRange::default();
10590 let flags = ast::FStringFlags::empty();
10591
10592 // f'{x}'
10593 let expr_x = ast::Expr::Name(ast::ExprName {
10594 node_index: ast::AtomicNodeIndex::NONE,
10595 range,
10596 id: Name::new("x"),
10597 ctx: ast::ExprContext::Load,
10598 });
10599 let not_present = &ast::Expr::FString(ast::ExprFString {
10600 node_index: ast::AtomicNodeIndex::NONE,
10601 range,
10602 value: ast::FStringValue::single(ast::FString {
10603 node_index: ast::AtomicNodeIndex::NONE,
10604 range,
10605 elements: vec![ast::InterpolatedStringElement::Interpolation(
10606 ast::InterpolatedElement {
10607 node_index: ast::AtomicNodeIndex::NONE,
10608 range,
10609 expression: Box::new(expr_x),
10610 debug_text: None,
10611 conversion: ast::ConversionFlag::None,
10612 format_spec: None,
10613 },
10614 )]
10615 .into(),
10616 flags,
10617 }),
10618 });
10619 assert!(!Compiler::contains_await(not_present));
10620
10621 // f'{await x}'
10622 let expr_await_x = ast::Expr::Await(ast::ExprAwait {
10623 node_index: ast::AtomicNodeIndex::NONE,
10624 range,
10625 value: Box::new(ast::Expr::Name(ast::ExprName {
10626 node_index: ast::AtomicNodeIndex::NONE,
10627 range,
10628 id: Name::new("x"),
10629 ctx: ast::ExprContext::Load,
10630 })),
10631 });
10632 let present = &ast::Expr::FString(ast::ExprFString {
10633 node_index: ast::AtomicNodeIndex::NONE,
10634 range,
10635 value: ast::FStringValue::single(ast::FString {
10636 node_index: ast::AtomicNodeIndex::NONE,
10637 range,
10638 elements: vec![ast::InterpolatedStringElement::Interpolation(
10639 ast::InterpolatedElement {
10640 node_index: ast::AtomicNodeIndex::NONE,
10641 range,
10642 expression: Box::new(expr_await_x),
10643 debug_text: None,
10644 conversion: ast::ConversionFlag::None,
10645 format_spec: None,

Callers

nothing calls this directly

Calls 2

newFunction · 0.85
NameClass · 0.50

Tested by

no test coverage detected