fluidattacks-blends-domain 0.44.3

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use super::build_try_expression;
use crate::ast::node_utils::AstNodeAndId;
use crate::syntax::_node_builders::languages::rust::tests_utils::{find_node, rust_ast_graph};
use crate::syntax::core_nodes::{
    CoreSyntaxNode, CoreSyntaxNodeWithId, StringLiteral, TryExpression,
};
use crate::NodeId;

fn mock_node(kind: &str) -> CoreSyntaxNode {
    CoreSyntaxNode::StringLiteral(StringLiteral {
        value: format!("mock: {kind}"),
    })
}
fn mock_build((node, n_id): AstNodeAndId) -> CoreSyntaxNodeWithId {
    (mock_node(&node.kind), n_id)
}

fn build(source: &str) -> TryExpression {
    let graph = rust_ast_graph(source);
    let node = find_node(&graph, "try_expression");
    build_try_expression(&graph, node, |p| Ok(mock_build(p))).unwrap()
}

const SOURCE_1: &str = include_str!("case_1.test.rs");

#[test]
fn builds_try_on_call() {
    let expected = TryExpression {
        expression: (mock_node("call_expression"), NodeId(15)),
    };
    assert_eq!(build(SOURCE_1), expected);
}

const SOURCE_2: &str = include_str!("case_2.test.rs");

#[test]
fn builds_try_on_identifier() {
    let expected = TryExpression {
        expression: (mock_node("identifier"), NodeId(26)),
    };
    assert_eq!(build(SOURCE_2), expected);
}

const SOURCE_3: &str = include_str!("case_3.test.rs");

#[test]
fn builds_chained_try() {
    let expected = TryExpression {
        expression: (mock_node("try_expression"), NodeId(15)),
    };
    assert_eq!(build(SOURCE_3), expected);
}