use super::build_comment;
use super::build_multi_comment;
use crate::syntax::_node_builders::languages::rust::tests_utils::{find_node, rust_ast_graph};
use crate::syntax::SyntaxNode;
use alloc::borrow::ToOwned;
const SINGLE_COMMENT_SOURCE: &str = include_str!("single_comment.test.rs");
const DOC_COMMENT_SOURCE: &str = include_str!("doc_comment.test.rs");
const DOC_COMMENT_2_SOURCE: &str = include_str!("doc_comment_2.test.rs");
const MULTI_COMMENT_SOURCE: &str = include_str!("multi_comment.test.rs");
#[test]
fn builds_a_single_line_comment() {
let graph = rust_ast_graph(SINGLE_COMMENT_SOURCE);
let node = find_node(&graph, "line_comment");
assert_eq!(
build_comment(&graph, node),
Ok(SyntaxNode::Comment {
comment: "//".to_owned(),
})
);
}
#[test]
fn builds_a_doc_comment() {
let graph = rust_ast_graph(DOC_COMMENT_SOURCE);
let node = find_node(&graph, "line_comment");
assert_eq!(
build_comment(&graph, node),
Ok(SyntaxNode::Comment {
comment: "//! const ENABLED: bool = true;\n".to_owned(),
})
);
}
#[test]
fn builds_a_doc_comment_2() {
let graph = rust_ast_graph(DOC_COMMENT_2_SOURCE);
let node = find_node(&graph, "line_comment");
assert_eq!(
build_comment(&graph, node),
Ok(SyntaxNode::Comment {
comment: "/// const ENABLED: bool = true;\n".to_owned(),
})
);
}
#[test]
fn builds_a_multi_line_comment() {
let graph = rust_ast_graph(MULTI_COMMENT_SOURCE);
let node = find_node(&graph, "block_comment");
let built = build_multi_comment(&graph, node).unwrap();
assert!(
built
== SyntaxNode::Comment {
comment: "/**/".to_owned(),
}
);
}