use super::build_await_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::{
AwaitExpression, CoreSyntaxNode, CoreSyntaxNodeWithId, StringLiteral,
};
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) -> AwaitExpression {
let graph = rust_ast_graph(source);
let node = find_node(&graph, "await_expression");
build_await_expression(&graph, node, |p| Ok(mock_build(p))).unwrap()
}
const SOURCE_1: &str = include_str!("case_1.test.rs");
#[test]
fn builds_await_on_call() {
let expected = AwaitExpression {
expression: (mock_node("call_expression"), NodeId(17)),
};
assert_eq!(build(SOURCE_1), expected);
}
const SOURCE_2: &str = include_str!("case_2.test.rs");
#[test]
fn builds_await_on_identifier() {
let expected = AwaitExpression {
expression: (mock_node("identifier"), NodeId(27)),
};
assert_eq!(build(SOURCE_2), expected);
}
const SOURCE_3: &str = include_str!("case_3.test.rs");
#[test]
fn builds_chained_await() {
let expected = AwaitExpression {
expression: (mock_node("await_expression"), NodeId(17)),
};
assert_eq!(build(SOURCE_3), expected);
}