Skip to content

Commit

Permalink
Add more failing compilation tests for pdec!()
Browse files Browse the repository at this point in the history
  • Loading branch information
lrubasze committed Sep 21, 2023
1 parent 1a3b2d8 commit 2988094
Show file tree
Hide file tree
Showing 40 changed files with 195 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use radix_engine_interface::prelude::*;

fn main() {
const X: Decimal = dec!(1.0000000000000000000000000);
const X: Decimal = dec!(1.0000000000000000001);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: A decimal cannot have more than eighteen decimal places.
--> src/dec_err_too_many_decimal_places.rs:4:29
|
4 | const X: Decimal = dec!(1.0000000000000000000000000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 | const X: Decimal = dec!(1.0000000000000000001);
| ^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use radix_engine_interface::prelude::*;

fn main() {
const X: PreciseDecimal = pdec!(1.);
}
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/pdec_err_empty_fractional_part_1.rs:4:37
|
4 | const X: PreciseDecimal = pdec!(1.);
| ^^
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.");
}
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/pdec_err_empty_fractional_part_2.rs:4:29
|
4 | const X: Decimal = dec!("1.");
| ^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use radix_engine_interface::prelude::*;

fn main() {
const X: PreciseDecimal = pdec!(".0");
}
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/pdec_err_empty_integral_part.rs:4:37
|
4 | const X: PreciseDecimal = pdec!(".0");
| ^^^^
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: expected expression
--> src/pdec_err_expected_expr.rs:4:29
|
4 | const X: Decimal = dec!(.1);
| ^
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);
}
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/pdec_err_expr_not_supported.rs:4:29
|
4 | const X: Decimal = dec!(a);
| ^
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);
}
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/pdec_err_expr_unary_op_not_supported.rs:4:29
|
4 | const X: Decimal = dec!(!1);
| ^
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: No suffix is allowed. Remove the f64.
--> src/pdec_err_float_suffix.rs:4:29
|
4 | const X: Decimal = dec!(11.12f64);
| ^^^^^^^^
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: No suffix is allowed. Remove the i64.
--> src/pdec_err_int_suffix.rs:4:29
|
4 | const X: Decimal = dec!(11_i64);
| ^^^^^^
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: There is an invalid character.
--> src/pdec_err_invalid_digit.rs:4:29
|
4 | const X: Decimal = dec!(11.12e3);
| ^^^^^^^
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');
}
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/pdec_err_literal_not_supported.rs:4:29
|
4 | const X: Decimal = dec!('a');
| ^^^
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");
}
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/pdec_err_more_than_one_decimal_point.rs:4:29
|
4 | const X: Decimal = dec!("1.000.0");
| ^^^^^^^^^
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);
}
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/pdec_err_multiple_negations.rs:4:30
|
4 | const X: Decimal = dec!(--1);
| ^
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");
}
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/pdec_err_negation_and_string.rs:4:30
|
4 | const X: Decimal = dec!(-"112.3");
| ^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use radix_engine_interface::prelude::*;

fn main() {
const X: PreciseDecimal =
pdec!(-57896044618658097711785492504343953926634.992332820282019728792003956564819969);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: The number being too large to fit in a precise decimal
--> src/pdec_err_overflow_1.rs:5:16
|
5 | pdec!(-57896044618658097711785492504343953926634.992332820282019728792003956564819969);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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");
}
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/pdec_err_overflow_2.rs:4:29
|
4 | const X: Decimal = dec!("-3138550867693340381917894711603833208051.177722232017256449");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use radix_engine_interface::prelude::*;

fn main() {
const X: PreciseDecimal =
pdec!(57896044618658097711785492504343953926634.992332820282019728792003956564819968);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: The number being too large to fit in a precise decimal
--> src/pdec_err_overflow_3.rs:5:15
|
5 | pdec!(57896044618658097711785492504343953926634.992332820282019728792003956564819968);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use radix_engine_interface::prelude::*;

fn main() {
const X: PreciseDecimal =
pdec!("57896044618658097711785492504343953926634.992332820282019728792003956564819968");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: The number being too large to fit in a precise decimal
--> src/pdec_err_overflow_4.rs:5:15
|
5 | pdec!("57896044618658097711785492504343953926634.992332820282019728792003956564819968");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use radix_engine_interface::prelude::*;

fn main() {
const X: PreciseDecimal = pdec!(1.0000000000000000000000000000000000001);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: A precise decimal cannot have more than thirty-six decimal places.
--> src/pdec_err_too_many_decimal_places.rs:4:37
|
4 | const X: PreciseDecimal = pdec!(1.0000000000000000000000000000000000001);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 changes: 5 additions & 0 deletions radix-engine-tests/tests/dec_macros/src/pdec_success.rs
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");
}
6 changes: 4 additions & 2 deletions radix-engine-tests/tests/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use transaction::prelude::*;
use trybuild;

#[test]
fn test_dec_macro_try_build() {
fn test_dec_macro_try_compile() {
// Change CARGO_MANIFEST_DIR to tests/dec_macros, where the dec_macros test crate is located.
// By default 'trybuild' crate uses current manifest dir, but it does not work with
// radix-engine-tests dir (presumably too complicated set of dependencies and features).
Expand All @@ -24,6 +24,8 @@ fn test_dec_macro_try_build() {
// Paths must be relative to the manifest_dir
t.pass("src/dec_success.rs");
t.compile_fail("src/dec_err_*.rs");
t.pass("src/pdec_success.rs");
t.compile_fail("src/pdec_err_*.rs");
}

#[test]
Expand Down Expand Up @@ -87,7 +89,7 @@ fn test_dec_macro_valid() {
}

#[test]
fn test_pdec_macro() {
fn test_pdec_macro_valid() {
let x1 = pdec!("1.1");
assert_eq!(x1, PreciseDecimal::try_from("1.1").unwrap());

Expand Down

0 comments on commit 2988094

Please sign in to comment.