-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,7 @@ authors = ["Denys Zadorozhnyi <[email protected]>"] | |
repository.workspace = true | ||
edition.workspace = true | ||
description = "ErgoTree IR, serialization" | ||
exclude = [ | ||
"proptest-regressions/*" | ||
] | ||
exclude = ["proptest-regressions/*"] | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
@@ -22,7 +20,7 @@ elliptic-curve = { workspace = true } | |
thiserror = { workspace = true } | ||
lazy_static = { workspace = true } | ||
derive_more = { workspace = true } | ||
proptest = { workspace = true , optional = true } | ||
proptest = { workspace = true, optional = true } | ||
proptest-derive = { workspace = true, optional = true } | ||
bs58 = { workspace = true } | ||
base16 = { workspace = true } | ||
|
@@ -32,7 +30,7 @@ num-traits = { workspace = true } | |
num-derive = { workspace = true } | ||
num-integer = { workspace = true } | ||
indexmap = { workspace = true } | ||
serde = { workspace = true , optional = true } | ||
serde = { workspace = true, optional = true } | ||
serde_json = { workspace = true, optional = true } | ||
serde_with = { workspace = true, optional = true } | ||
num256 = "0.3.1" | ||
|
@@ -49,3 +47,4 @@ json = ["serde", "serde_json", "serde_with", "bounded-vec/serde"] | |
sigma-test-util = { workspace = true } | ||
rand = { workspace = true } | ||
pretty_assertions = { workspace = true } | ||
expect-test = { workspace = true } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ pub mod source_span; | |
pub mod type_check; | ||
pub mod types; | ||
pub mod util; | ||
mod pretty_printer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::mir::expr::Expr; | ||
|
||
pub(crate) struct PrintExpr { | ||
Check failure on line 3 in ergotree-ir/src/pretty_printer.rs GitHub Actions / Build without default features
Check failure on line 3 in ergotree-ir/src/pretty_printer.rs GitHub Actions / Tests on ubuntu-latest
Check failure on line 3 in ergotree-ir/src/pretty_printer.rs GitHub Actions / clippystruct `PrintExpr` is never constructed
|
||
expr: Expr, | ||
text: String, | ||
} | ||
|
||
#[derive(PartialEq, Eq, Debug, Clone)] | ||
pub(crate) enum PrintError {} | ||
|
||
#[allow(clippy::todo)] | ||
pub(crate) fn print_expr(expr: Expr) -> Result<PrintExpr, PrintError> { | ||
Check warning on line 12 in ergotree-ir/src/pretty_printer.rs GitHub Actions / Build without default features
Check failure on line 12 in ergotree-ir/src/pretty_printer.rs GitHub Actions / Build without default features
Check warning on line 12 in ergotree-ir/src/pretty_printer.rs GitHub Actions / Tests on ubuntu-latest
Check failure on line 12 in ergotree-ir/src/pretty_printer.rs GitHub Actions / Tests on ubuntu-latest
Check failure on line 12 in ergotree-ir/src/pretty_printer.rs GitHub Actions / clippyfunction `print_expr` is never used
Check failure on line 12 in ergotree-ir/src/pretty_printer.rs GitHub Actions / clippyunused variable: `expr`
Check warning on line 12 in ergotree-ir/src/pretty_printer.rs GitHub Actions / Check intra-documentation links
|
||
todo!() | ||
} | ||
|
||
#[allow(clippy::unwrap_used)] | ||
#[cfg(test)] | ||
mod tests { | ||
|
||
use expect_test::expect; | ||
|
||
use crate::mir::block::BlockValue; | ||
use crate::mir::val_def::ValDef; | ||
use crate::mir::val_use::ValUse; | ||
use crate::types::stype::SType; | ||
|
||
use super::*; | ||
|
||
fn check(expr: Expr, expected_tree: expect_test::Expect) { | ||
let expected_out = print_expr(expr).unwrap(); | ||
expected_tree.assert_eq(&expected_out.text); | ||
} | ||
|
||
#[test] | ||
fn smoke() { | ||
let val_id = 2.into(); | ||
let body = Expr::BlockValue(BlockValue { | ||
items: vec![ValDef { | ||
id: val_id, | ||
rhs: Box::new(Expr::Const(1i32.into())), | ||
} | ||
.into()], | ||
result: Box::new( | ||
ValUse { | ||
val_id, | ||
tpe: SType::SInt, | ||
} | ||
.into(), | ||
), | ||
}); | ||
let expr = Expr::Const(1i32.into()); | ||
check( | ||
expr, | ||
expect![[r#" | ||
{ | ||
val v1 = 1 | ||
v1 | ||
} | ||
"#]], | ||
); | ||
} | ||
} |