tamer: nir::air::test: Formatting and enum prefix elision

This just makes easier to read and more concise.  I'm about to add a number
of tests and the verbosity was off-putting.

DEV-13708
main
Mike Gerwitz 2023-04-06 09:32:47 -04:00
parent e8371c452e
commit 7b2acb65c5
1 changed files with 51 additions and 46 deletions

View File

@ -17,7 +17,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use super::super::NirEntity;
use super::*; use super::*;
use crate::{parse::util::SPair, span::dummy::*}; use crate::{parse::util::SPair, span::dummy::*};
@ -27,10 +26,7 @@ use Parsed::Object as O;
#[test] #[test]
fn package_to_pkg() { fn package_to_pkg() {
let toks = vec![ let toks = vec![Open(Package, S1), Close(Package, S2)];
Nir::Open(NirEntity::Package, S1),
Nir::Close(NirEntity::Package, S2),
];
assert_eq!( assert_eq!(
Ok(vec![O(Air::PkgStart(S1)), O(Air::PkgEnd(S2)),]), Ok(vec![O(Air::PkgStart(S1)), O(Air::PkgEnd(S2)),]),
@ -42,16 +38,18 @@ fn package_to_pkg() {
fn rate_to_sum_expr() { fn rate_to_sum_expr() {
let id = SPair("foo".into(), S2); let id = SPair("foo".into(), S2);
#[rustfmt::skip]
let toks = vec![ let toks = vec![
Nir::Open(NirEntity::Rate, S1), Open(Rate, S1),
Nir::BindIdent(id), BindIdent(id),
Nir::Close(NirEntity::Rate, S3), Close(Rate, S3),
]; ];
assert_eq!( assert_eq!(
#[rustfmt::skip]
Ok(vec![ Ok(vec![
O(Air::ExprStart(ExprOp::Sum, S1)), O(Air::ExprStart(ExprOp::Sum, S1)),
O(Air::BindIdent(id)), O(Air::BindIdent(id)),
O(Air::ExprEnd(S3)), O(Air::ExprEnd(S3)),
]), ]),
Sut::parse(toks.into_iter()).collect(), Sut::parse(toks.into_iter()).collect(),
@ -60,18 +58,20 @@ fn rate_to_sum_expr() {
#[test] #[test]
fn calc_exprs() { fn calc_exprs() {
#[rustfmt::skip]
let toks = vec![ let toks = vec![
Nir::Open(NirEntity::Sum, S1), Open(Sum, S1),
Nir::Open(NirEntity::Product, S2), Open(Product, S2),
Nir::Close(NirEntity::Product, S3), Close(Product, S3),
Nir::Close(NirEntity::Sum, S4), Close(Sum, S4),
]; ];
assert_eq!( assert_eq!(
#[rustfmt::skip]
Ok(vec![ Ok(vec![
O(Air::ExprStart(ExprOp::Sum, S1)), O(Air::ExprStart(ExprOp::Sum, S1)),
O(Air::ExprStart(ExprOp::Product, S2)), O(Air::ExprStart(ExprOp::Product, S2)),
O(Air::ExprEnd(S3)), O(Air::ExprEnd(S3)),
O(Air::ExprEnd(S4)), O(Air::ExprEnd(S4)),
]), ]),
Sut::parse(toks.into_iter()).collect(), Sut::parse(toks.into_iter()).collect(),
@ -82,16 +82,18 @@ fn calc_exprs() {
fn classify_to_conj_expr() { fn classify_to_conj_expr() {
let id = SPair("always".into(), S2); let id = SPair("always".into(), S2);
#[rustfmt::skip]
let toks = vec![ let toks = vec![
Nir::Open(NirEntity::Classify, S1), Open(Classify, S1),
Nir::BindIdent(id), BindIdent(id),
Nir::Close(NirEntity::Classify, S3), Close(Classify, S3),
]; ];
assert_eq!( assert_eq!(
#[rustfmt::skip]
Ok(vec![ Ok(vec![
O(Air::ExprStart(ExprOp::Conj, S1)), O(Air::ExprStart(ExprOp::Conj, S1)),
O(Air::BindIdent(id)), O(Air::BindIdent(id)),
O(Air::ExprEnd(S3)), O(Air::ExprEnd(S3)),
]), ]),
Sut::parse(toks.into_iter()).collect(), Sut::parse(toks.into_iter()).collect(),
@ -100,18 +102,20 @@ fn classify_to_conj_expr() {
#[test] #[test]
fn logic_exprs() { fn logic_exprs() {
#[rustfmt::skip]
let toks = vec![ let toks = vec![
Nir::Open(NirEntity::All, S1), Open(All, S1),
Nir::Open(NirEntity::Any, S2), Open(Any, S2),
Nir::Close(NirEntity::Any, S3), Close(Any, S3),
Nir::Close(NirEntity::All, S4), Close(All, S4),
]; ];
assert_eq!( assert_eq!(
#[rustfmt::skip]
Ok(vec![ Ok(vec![
O(Air::ExprStart(ExprOp::Conj, S1)), O(Air::ExprStart(ExprOp::Conj, S1)),
O(Air::ExprStart(ExprOp::Disj, S2)), O(Air::ExprStart(ExprOp::Disj, S2)),
O(Air::ExprEnd(S3)), O(Air::ExprEnd(S3)),
O(Air::ExprEnd(S4)), O(Air::ExprEnd(S4)),
]), ]),
Sut::parse(toks.into_iter()).collect(), Sut::parse(toks.into_iter()).collect(),
@ -122,17 +126,18 @@ fn logic_exprs() {
fn tpl_with_name() { fn tpl_with_name() {
let name = SPair("_tpl_name_".into(), S2); let name = SPair("_tpl_name_".into(), S2);
#[rustfmt::skip]
let toks = vec![ let toks = vec![
Nir::Open(NirEntity::Tpl, S1), Open(Tpl, S1),
Nir::BindIdent(name), BindIdent(name),
Nir::Close(NirEntity::Tpl, S3), Close(Tpl, S3),
]; ];
#[rustfmt::skip]
assert_eq!( assert_eq!(
#[rustfmt::skip]
Ok(vec![ Ok(vec![
O(Air::TplStart(S1)), O(Air::TplStart(S1)),
O(Air::BindIdent(name)), O(Air::BindIdent(name)),
O(Air::TplEnd(S3)), O(Air::TplEnd(S3)),
]), ]),
Sut::parse(toks.into_iter()).collect(), Sut::parse(toks.into_iter()).collect(),
@ -147,13 +152,13 @@ fn apply_template_long_form_nullary() {
#[rustfmt::skip] #[rustfmt::skip]
let toks = vec![ let toks = vec![
Nir::Open(NirEntity::TplApply, S1), Open(TplApply, S1),
Nir::Ref(name), Ref(name),
Nir::Close(NirEntity::TplApply, S3), Close(TplApply, S3),
]; ];
#[rustfmt::skip]
assert_eq!( assert_eq!(
#[rustfmt::skip]
Ok(vec![ Ok(vec![
O(Air::TplStart(S1)), O(Air::TplStart(S1)),
O(Air::RefIdent(name)), O(Air::RefIdent(name)),
@ -173,23 +178,23 @@ fn apply_template_long_form_args() {
#[rustfmt::skip] #[rustfmt::skip]
let toks = vec![ let toks = vec![
Nir::Open(NirEntity::TplApply, S1), Open(TplApply, S1),
Nir::Ref(name), Ref(name),
Nir::Open(NirEntity::TplParam, S3), Open(TplParam, S3),
Nir::BindIdent(p1), BindIdent(p1),
Nir::Text(v1), Text(v1),
Nir::Close(NirEntity::TplParam, S6), Close(TplParam, S6),
Nir::Open(NirEntity::TplParam, S7), Open(TplParam, S7),
Nir::BindIdent(p2), BindIdent(p2),
Nir::Text(v2), Text(v2),
Nir::Close(NirEntity::TplParam, S10), Close(TplParam, S10),
Nir::Close(NirEntity::TplApply, S11), Close(TplApply, S11),
]; ];
#[rustfmt::skip]
assert_eq!( assert_eq!(
#[rustfmt::skip]
Ok(vec![ Ok(vec![
O(Air::TplStart(S1)), O(Air::TplStart(S1)),
O(Air::RefIdent(name)), O(Air::RefIdent(name)),