Skip to content

Commit 7330de7

Browse files
committed
feat: Enable rust_decimal macros and update tests to use dec! for concise decimal creation.
1 parent 0504067 commit 7330de7

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ serde = { version = "1.0", features = ["derive"] }
3535
serde_json = "1.0"
3636
anyhow = { version = "1.0.100" }
3737
codespan-reporting = { version = "0.13.1",default-features = false , features = ["std"]}
38-
rust_decimal = { version = "1.39.0", features = ["serde-float"] }
38+
rust_decimal = { version = "1.39.0", features = ["serde-float", "macros"] }
3939

4040
[dev-dependencies]
4141
assert_cmd = "2"

docs/pkg/chen_lang_bg.wasm

0 Bytes
Binary file not shown.

src/value.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -715,22 +715,22 @@ mod tests {
715715

716716
#[test]
717717
fn test_float_operations() {
718-
let a = Value::float(Decimal::from_f32(5.5).unwrap());
718+
let a = Value::float(dec!(5.5));
719719
let b = Value::int(2);
720720

721721
assert_eq!(
722722
a.add(&b).unwrap().unwrap_value(),
723-
Value::float(Decimal::from_f32(7.5).unwrap())
723+
Value::float(dec!(7.5))
724724
);
725725
assert_eq!(
726726
a.subtract(&b).unwrap().unwrap_value(),
727-
Value::float(Decimal::from_f32(3.5).unwrap())
727+
Value::float(dec!(3.5))
728728
);
729729
assert_eq!(
730730
a.multiply(&b).unwrap().unwrap_value(),
731-
Value::float(Decimal::from_f32(11.0).unwrap())
731+
Value::float(dec!(11.0))
732732
);
733-
assert_eq!(a.divide(&b).unwrap(), Value::float(Decimal::from_f32(2.75).unwrap()));
733+
assert_eq!(a.divide(&b).unwrap(), Value::float(dec!(2.75)));
734734
}
735735

736736
#[test]
@@ -768,12 +768,12 @@ mod tests {
768768
#[test]
769769
fn test_type_conversions() {
770770
let int_val = Value::int(42);
771-
let float_val = Value::float(Decimal::from_f32(3.14).unwrap());
771+
let float_val = Value::float(dec!(3.14));
772772

773-
assert_eq!(int_val.to_float(), Some(Decimal::from(42)));
773+
assert_eq!(int_val.to_float(), Some(dec!(42)));
774774
assert_eq!(float_val.to_int(), Some(3));
775775
assert_eq!(int_val.to_int(), Some(42));
776-
assert_eq!(float_val.to_float(), Some(Decimal::from_f32(3.14).unwrap()));
776+
assert_eq!(float_val.to_float(), Some(dec!(3.14)));
777777
}
778778

779779
#[test]

0 commit comments

Comments
 (0)