-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1586 from radixdlt/test/dec_pdec_macro_tests
Fix `dec!()`/`pdec!()` macros and more tests
- Loading branch information
Showing
83 changed files
with
600 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "decimal" | ||
version = "1.0.0-rc1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
sbor = { path = "../../../../sbor" } | ||
scrypto = { path = "../../../../scrypto" } | ||
|
||
[dev-dependencies] | ||
radix-engine = { path = "../../../../radix-engine" } | ||
|
||
[lib] | ||
doctest = false | ||
crate-type = ["cdylib", "lib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use scrypto::prelude::*; | ||
|
||
#[blueprint] | ||
mod cast_test { | ||
const GD: Decimal = dec!(2); | ||
const GP: PreciseDecimal = pdec!(2); | ||
|
||
struct DecimalTest {} | ||
|
||
impl DecimalTest { | ||
pub fn test_dec_macro() -> Decimal { | ||
const C: Decimal = dec!("1111.2222"); | ||
static S: Decimal = dec!(2222.1111); | ||
|
||
C.checked_add(S) | ||
.unwrap() | ||
.checked_add(dec!(-0.3333)) | ||
.unwrap() | ||
.checked_mul(GD) | ||
.unwrap() | ||
} | ||
|
||
pub fn test_pdec_macro() -> PreciseDecimal { | ||
const C: PreciseDecimal = pdec!("1111.2222"); | ||
static S: PreciseDecimal = pdec!(2222.1111); | ||
|
||
C.checked_add(S) | ||
.unwrap() | ||
.checked_add(pdec!(-0.3333)) | ||
.unwrap() | ||
.checked_mul(GP) | ||
.unwrap() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[workspace] | ||
members = ["."] | ||
|
||
[package] | ||
name = "dec_macros" | ||
version = "1.0.0-rc1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
radix-engine-interface = { path = "../../../radix-engine-interface", default-features = false } | ||
|
||
# Stub lib to make 'trybuild' crate happy | ||
[lib] | ||
path = "src/lib.rs" | ||
|
||
# Below targets are not required to for the 'dec_macro' tests. | ||
# Adding just a few as a template. | ||
# If one needs to build some other target with 'cargo build' then below shall be updated. | ||
[[bin]] | ||
name = "dec_success" | ||
path = "src/dec_success.rs" | ||
|
||
[[bin]] | ||
name = "dec_err_expr_not_supported" | ||
path = "src/dec_err_expr_not_supported.rs" | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["radix-engine-interface/std"] | ||
alloc = ["radix-engine-interface/alloc"] | ||
|
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_empty_fractional_part_1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(1.); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_empty_fractional_part_1.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: If there is a decimal point, the number must include at least one digit after it. | ||
--> src/dec_err_empty_fractional_part_1.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!(1.); | ||
| ^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_empty_fractional_part_2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!("1."); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_empty_fractional_part_2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: If there is a decimal point, the number must include at least one digit after it. | ||
--> src/dec_err_empty_fractional_part_2.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!("1."); | ||
| ^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_empty_integral_part.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(".0"); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_empty_integral_part.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: If there is a decimal point, the number must include at least one digit before it. Use a 0 if necessary. | ||
--> src/dec_err_empty_integral_part.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!(".0"); | ||
| ^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_expected_expr.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(.1); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_expected_expr.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: expected expression | ||
--> src/dec_err_expected_expr.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!(.1); | ||
| ^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_expr_not_supported.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(a); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_expr_not_supported.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: This macro only supports string, integer and float literals. | ||
--> src/dec_err_expr_not_supported.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!(a); | ||
| ^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_expr_unary_op_not_supported.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(!1); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_expr_unary_op_not_supported.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: This macro only supports string, integer and float literals. | ||
--> src/dec_err_expr_unary_op_not_supported.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!(!1); | ||
| ^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_float_suffix.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(11.12f64); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_float_suffix.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: No suffix is allowed. Remove the f64. | ||
--> src/dec_err_float_suffix.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!(11.12f64); | ||
| ^^^^^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_int_suffix.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(11_i64); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_int_suffix.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: No suffix is allowed. Remove the i64. | ||
--> src/dec_err_int_suffix.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!(11_i64); | ||
| ^^^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_invalid_digit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(11.12e3); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_invalid_digit.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: There is an invalid character. | ||
--> src/dec_err_invalid_digit.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!(11.12e3); | ||
| ^^^^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_literal_not_supported.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!('a'); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_literal_not_supported.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: This macro only supports string, integer and float literals. | ||
--> src/dec_err_literal_not_supported.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!('a'); | ||
| ^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_more_than_one_decimal_point.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!("1.000.0"); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_more_than_one_decimal_point.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: A decimal cannot have more than one decimal point. | ||
--> src/dec_err_more_than_one_decimal_point.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!("1.000.0"); | ||
| ^^^^^^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_multiple_negations.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(--1); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_multiple_negations.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: This macro only supports string, integer and float literals. | ||
--> src/dec_err_multiple_negations.rs:4:30 | ||
| | ||
4 | const X: Decimal = dec!(--1); | ||
| ^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_negation_and_string.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(-"112.3"); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_negation_and_string.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: This macro only supports string, integer and float literals. | ||
--> src/dec_err_negation_and_string.rs:4:30 | ||
| | ||
4 | const X: Decimal = dec!(-"112.3"); | ||
| ^^^^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_overflow_1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(-3138550867693340381917894711603833208051.177722232017256449); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_overflow_1.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: The number is too large to fit in a decimal. | ||
--> src/dec_err_overflow_1.rs:4:30 | ||
| | ||
4 | const X: Decimal = dec!(-3138550867693340381917894711603833208051.177722232017256449); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_overflow_2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!("-3138550867693340381917894711603833208051.177722232017256449"); | ||
} |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_overflow_2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: The number is too large to fit in a decimal. | ||
--> src/dec_err_overflow_2.rs:4:29 | ||
| | ||
4 | const X: Decimal = dec!("-3138550867693340381917894711603833208051.177722232017256449"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
5 changes: 5 additions & 0 deletions
5
radix-engine-tests/tests/dec_macros/src/dec_err_overflow_3.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use radix_engine_interface::prelude::*; | ||
|
||
fn main() { | ||
const X: Decimal = dec!(3138550867693340381917894711603833208051.177722232017256448); | ||
} |
Oops, something went wrong.