tamer: asg::air: Common asg_from_toks for tests
The previous commit introduced a duplicate `asg_from_toks`; this just makes it available publicly for any tests that might utilize AIR to lower the barrier to writing such tests and provide some guidance in doing so. DEV-13162main
parent
79fa10f26b
commit
b61e1ce952
|
@ -779,4 +779,4 @@ impl From<Asg> for AirAggregateCtx {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
pub mod test;
|
||||
|
|
|
@ -21,7 +21,7 @@ use super::*;
|
|||
use crate::asg::{
|
||||
air::{
|
||||
test::{
|
||||
asg_from_toks, parse_as_pkg_body, pkg_expect_ident_obj,
|
||||
asg_from_pkg_body_toks, parse_as_pkg_body, pkg_expect_ident_obj,
|
||||
pkg_expect_ident_oi, pkg_lookup,
|
||||
},
|
||||
Air, AirAggregate,
|
||||
|
@ -498,7 +498,7 @@ fn sibling_subexprs_have_ordered_edges_to_parent() {
|
|||
Air::ExprEnd(S9),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
// The root is the parent expression that should contain edges to each
|
||||
// subexpression
|
||||
|
@ -541,7 +541,7 @@ fn nested_subexprs_related_to_relative_parent() {
|
|||
Air::ExprEnd(S6),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
let oi_0 = pkg_expect_ident_oi::<Expr>(&asg, id_root);
|
||||
let subexprs_0 = collect_subexprs(&asg, oi_0);
|
||||
|
@ -721,7 +721,7 @@ fn expr_ref_to_ident() {
|
|||
Air::ExprEnd(S7),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
let oi_foo = pkg_expect_ident_oi::<Expr>(&asg, id_foo);
|
||||
|
||||
|
@ -807,7 +807,7 @@ fn expr_doc_short_desc() {
|
|||
Air::ExprEnd(S4),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
let oi_expr = pkg_expect_ident_oi::<Expr>(&asg, id_expr);
|
||||
let oi_docs = oi_expr
|
||||
|
|
|
@ -602,7 +602,7 @@ fn pkg_doc() {
|
|||
DocText(doc_b),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
let oi_pkg = asg
|
||||
.root(S1)
|
||||
|
@ -635,7 +635,9 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
pub fn asg_from_toks<I: IntoIterator<Item = Air>>(toks: I) -> Asg
|
||||
pub(super) fn asg_from_pkg_body_toks<I: IntoIterator<Item = Air>>(
|
||||
toks: I,
|
||||
) -> Asg
|
||||
where
|
||||
I::IntoIter: Debug,
|
||||
{
|
||||
|
@ -644,8 +646,8 @@ where
|
|||
sut.finalize().unwrap().into_context()
|
||||
}
|
||||
|
||||
/// [`asg_from_toks`] without creating a package automatically.
|
||||
pub fn asg_from_toks_raw<I: IntoIterator<Item = Air>>(toks: I) -> Asg
|
||||
/// Create and yield a new [`Asg`] from an [`Air`] token stream.
|
||||
pub fn asg_from_toks<I: IntoIterator<Item = Air>>(toks: I) -> Asg
|
||||
where
|
||||
I::IntoIter: Debug,
|
||||
{
|
||||
|
|
|
@ -83,7 +83,7 @@ macro_rules! test_scopes {
|
|||
#[test]
|
||||
fn $name() {
|
||||
$($setup)*
|
||||
let asg = asg_from_toks_raw($toks);
|
||||
let asg = asg_from_toks($toks);
|
||||
|
||||
let given = derive_scopes_from_asg(&asg, $name);
|
||||
let expected = [
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::asg::{
|
|||
air::{
|
||||
expr::test::collect_subexprs,
|
||||
test::{
|
||||
asg_from_toks, parse_as_pkg_body, pkg_expect_ident_obj,
|
||||
asg_from_pkg_body_toks, parse_as_pkg_body, pkg_expect_ident_obj,
|
||||
pkg_expect_ident_oi, pkg_lookup,
|
||||
},
|
||||
Air, AirAggregate,
|
||||
|
@ -187,7 +187,7 @@ fn tpl_apply_within_expr() {
|
|||
Air::ExprEnd(S10),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
// The inner template.
|
||||
let tpl = pkg_expect_ident_obj::<Tpl>(&asg, id_tpl);
|
||||
|
@ -262,7 +262,7 @@ fn tpl_with_reachable_expression() {
|
|||
Air::TplEnd(S9),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
let oi_tpl = pkg_expect_ident_oi::<Tpl>(&asg, id_tpl);
|
||||
let tpl = oi_tpl.resolve(&asg);
|
||||
|
@ -332,7 +332,7 @@ fn tpl_holds_dangling_expressions() {
|
|||
Air::TplEnd(S7),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
let oi_tpl = pkg_expect_ident_oi::<Tpl>(&asg, id_tpl);
|
||||
|
||||
assert_eq!(
|
||||
|
@ -483,7 +483,7 @@ fn tpl_with_param() {
|
|||
Air::TplEnd(S10),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
let oi_tpl = pkg_expect_ident_oi::<Tpl>(&asg, id_tpl);
|
||||
|
||||
// The template should have an edge to each identifier for each
|
||||
|
@ -524,7 +524,7 @@ fn tpl_nested() {
|
|||
Air::TplEnd(S6),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
// The outer template should be defined globally,
|
||||
// but not the inner,
|
||||
|
@ -567,7 +567,7 @@ fn tpl_apply_nested() {
|
|||
Air::TplEnd(S5),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
let oi_tpl_outer = pkg_expect_ident_oi::<Tpl>(&asg, id_tpl_outer);
|
||||
assert_eq!(S1.merge(S5).unwrap(), oi_tpl_outer.resolve(&asg).span());
|
||||
|
@ -616,7 +616,7 @@ fn tpl_apply_nested_missing() {
|
|||
Air::TplEnd(S12),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
let oi_tpl_outer = pkg_expect_ident_oi::<Tpl>(&asg, id_tpl_outer);
|
||||
assert_eq!(S1.merge(S12).unwrap(), oi_tpl_outer.resolve(&asg).span());
|
||||
|
@ -668,7 +668,7 @@ fn tpl_doc_short_desc() {
|
|||
Air::TplEnd(S4),
|
||||
];
|
||||
|
||||
let asg = asg_from_toks(toks);
|
||||
let asg = asg_from_pkg_body_toks(toks);
|
||||
|
||||
let oi_expr = pkg_expect_ident_oi::<Tpl>(&asg, id_tpl);
|
||||
let oi_docs = oi_expr
|
||||
|
|
|
@ -20,25 +20,17 @@
|
|||
use super::*;
|
||||
use crate::{
|
||||
asg::{
|
||||
air::{Air, AirAggregate},
|
||||
air::{test::asg_from_toks, Air},
|
||||
AsgError, FragmentText, Ident, IdentKind, Source,
|
||||
},
|
||||
ld::xmle::{section::PushResult, Sections},
|
||||
parse::{util::SPair, ParseState},
|
||||
parse::util::SPair,
|
||||
span::dummy::*,
|
||||
sym::SymbolId,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
||||
use Air::*;
|
||||
|
||||
fn asg_from_toks(toks: impl IntoIterator<Item = Air, IntoIter: Debug>) -> Asg {
|
||||
let mut sut = AirAggregate::parse(toks.into_iter());
|
||||
assert!(sut.all(|x| x.is_ok()));
|
||||
|
||||
sut.finalize().unwrap().into_context()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graph_sort() -> SortResult<()> {
|
||||
// We care only about the order of pushes, not the sections they end
|
||||
|
|
Loading…
Reference in New Issue