Skip to content

Commit d76f543

Browse files
committed
task: change dependency versions
- lock to specific versions - remove `rust_decimal_macros` dev dependency
1 parent 2117e89 commit d76f543

6 files changed

Lines changed: 81 additions & 72 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@ license = "MIT"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
regex = { version = "~1", default-features = false, features = [] }
11-
rust_decimal = { version = "~1", default-features = false, features = [] }
12-
13-
[dev-dependencies]
14-
rust_decimal_macros = { version = "~1", default-features = false, features = [] }
10+
regex = { version = "1.11.1", default-features = false, features = [] }
11+
rust_decimal = { version = "1.37.2", default-features = false, features = [] }

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Invoice::new(
3030
)
3131
.with_item(
3232
DetailsItem::new(
33-
dec!(100),
33+
Decimal::from(100),
3434
"STK",
35-
dec!(10.20),
36-
TaxItem::new(dec!(20), TaxCategory::S),
35+
Decimal::new(1020, 2),
36+
TaxItem::new(Decimal::from(20), TaxCategory::S),
3737
)
3838
.with_description("Schraubenzieher"),
3939
)

src/details.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ impl ToXml for Details<'_> {
160160
#[cfg(test)]
161161
mod tests {
162162
use super::*;
163-
use rust_decimal_macros::dec;
164163

165164
use crate::{
166165
reduction_and_surcharge::{ReductionAndSurchargeValue, SurchargeListLineItem},
@@ -170,14 +169,14 @@ mod tests {
170169

171170
#[test]
172171
fn rounds_line_item_amount_result_after_calculation() {
173-
let quantity = dec!(0.005);
174-
let unit_price = dec!(0.005);
172+
let quantity = Decimal::new(5, 3);
173+
let unit_price = Decimal::new(5, 3);
175174

176175
let result = DetailsItem::new(
177176
quantity,
178177
"KGM",
179178
unit_price,
180-
TaxItem::new(dec!(20), TaxCategory::S),
179+
TaxItem::new(Decimal::from(20), TaxCategory::S),
181180
)
182181
.with_description("Sand")
183182
.to_xml();
@@ -190,14 +189,14 @@ mod tests {
190189

191190
#[test]
192191
fn rounds_correctly_up() {
193-
let quantity = dec!(100.123456);
194-
let unit_price = dec!(10.20005);
192+
let quantity = Decimal::new(100123456, 6);
193+
let unit_price = Decimal::new(1020005, 5);
195194

196195
let result = DetailsItem::new(
197196
quantity,
198197
"KGM",
199198
unit_price,
200-
TaxItem::new(dec!(20), TaxCategory::S),
199+
TaxItem::new(Decimal::from(20), TaxCategory::S),
201200
)
202201
.with_description("Sand")
203202
.to_xml();
@@ -211,15 +210,15 @@ mod tests {
211210
#[test]
212211
fn calculates_reduction_correctly() {
213212
let result = DetailsItem::new(
214-
dec!(1),
213+
Decimal::from(1),
215214
"STK",
216-
dec!(5.00),
217-
TaxItem::new(dec!(10), TaxCategory::AA),
215+
Decimal::from(5),
216+
TaxItem::new(Decimal::from(10), TaxCategory::AA),
218217
)
219218
.with_description("Handbuch zur Schraube")
220219
.with_reduction(ReductionListLineItem::new(
221-
dec!(5),
222-
ReductionAndSurchargeValue::Amount(dec!(2.3399)),
220+
Decimal::from(5),
221+
ReductionAndSurchargeValue::Amount(Decimal::new(23399, 4)),
223222
))
224223
.to_xml();
225224

@@ -232,15 +231,15 @@ mod tests {
232231
#[test]
233232
fn calculates_surcharge_correctly() {
234233
let result = DetailsItem::new(
235-
dec!(1),
234+
Decimal::from(1),
236235
"STK",
237-
dec!(5.00),
238-
TaxItem::new(dec!(10), TaxCategory::AA),
236+
Decimal::from(5),
237+
TaxItem::new(Decimal::from(10), TaxCategory::AA),
239238
)
240239
.with_description("Handbuch zur Schraube")
241240
.with_surcharge(SurchargeListLineItem::new(
242-
dec!(5),
243-
ReductionAndSurchargeValue::Amount(dec!(2)),
241+
Decimal::from(5),
242+
ReductionAndSurchargeValue::Amount(Decimal::from(2)),
244243
))
245244
.to_xml();
246245

@@ -252,14 +251,14 @@ mod tests {
252251

253252
#[test]
254253
fn rounds_correctly_down() {
255-
let quantity = dec!(100.12344);
256-
let unit_price = dec!(10.20001);
254+
let quantity = Decimal::new(10012344, 5);
255+
let unit_price = Decimal::new(1020001, 5);
257256

258257
let result = DetailsItem::new(
259258
quantity,
260259
"KGM",
261260
unit_price,
262-
TaxItem::new(dec!(20), TaxCategory::S),
261+
TaxItem::new(Decimal::from(20), TaxCategory::S),
263262
)
264263
.with_description("Sand")
265264
.to_xml();

src/invoice.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,10 @@ impl<'a> Invoice<'a> {
148148

149149
#[cfg(test)]
150150
mod tests {
151-
use rust_decimal_macros::dec;
151+
use super::*;
152152

153153
use crate::payment_method::PaymentMethodPaymentCard;
154154

155-
use super::*;
156-
157155
#[test]
158156
fn readme_example() {
159157
let invoice = Invoice::new(
@@ -166,10 +164,10 @@ mod tests {
166164
)
167165
.with_item(
168166
DetailsItem::new(
169-
dec!(100),
167+
Decimal::from(100),
170168
"STK",
171-
dec!(10.20),
172-
TaxItem::new(dec!(20), TaxCategory::S),
169+
Decimal::new(1020, 2),
170+
TaxItem::new(Decimal::from(20), TaxCategory::S),
173171
)
174172
.with_description("Schraubenzieher"),
175173
)
@@ -203,39 +201,42 @@ mod tests {
203201
)
204202
.with_items(vec![
205203
DetailsItem::new(
206-
dec!(5.19),
204+
Decimal::new(519, 2),
207205
"h",
208-
dec!(106.23),
209-
TaxItem::new(dec!(20), TaxCategory::S),
206+
Decimal::new(10623, 2),
207+
TaxItem::new(Decimal::from(20), TaxCategory::S),
210208
),
211209
DetailsItem::new(
212-
dec!(3.2),
210+
Decimal::new(32, 1),
213211
"h",
214-
dec!(106.23),
215-
TaxItem::new(dec!(20), TaxCategory::S),
212+
Decimal::new(10623, 2),
213+
TaxItem::new(Decimal::from(20), TaxCategory::S),
216214
),
217215
DetailsItem::new(
218-
dec!(3.00),
216+
Decimal::from(3),
219217
"h",
220-
dec!(106.23),
221-
TaxItem::new(dec!(20), TaxCategory::S),
218+
Decimal::new(10623, 2),
219+
TaxItem::new(Decimal::from(20), TaxCategory::S),
222220
),
223221
DetailsItem::new(
224-
dec!(0.84),
222+
Decimal::new(84, 2),
225223
"h",
226-
dec!(106.23),
227-
TaxItem::new(dec!(20), TaxCategory::S),
224+
Decimal::new(10623, 2),
225+
TaxItem::new(Decimal::from(20), TaxCategory::S),
228226
),
229227
DetailsItem::new(
230-
dec!(14.62),
228+
Decimal::new(1462, 2),
231229
"h",
232-
dec!(106.23),
233-
TaxItem::new(dec!(20), TaxCategory::S),
230+
Decimal::new(10623, 2),
231+
TaxItem::new(Decimal::from(20), TaxCategory::S),
234232
),
235233
]);
236234

237235
let tax_items = invoice.invoice_tax_items();
238236

239-
assert_eq!(tax_items.first().map_or(dec!(0), |i| i.1), dec!(2852.27))
237+
assert_eq!(
238+
tax_items.first().map_or(Decimal::from(0), |i| i.1),
239+
Decimal::new(285227, 2)
240+
)
240241
}
241242
}

src/lib.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ pub(crate) mod xml;
1515

1616
#[cfg(test)]
1717
mod tests {
18+
use rust_decimal::Decimal;
19+
1820
use super::*;
19-
use rust_decimal_macros::dec;
2021

2122
use address::Address;
2223
use biller::Biller;
@@ -60,28 +61,31 @@ mod tests {
6061
)
6162
.with_item(
6263
DetailsItem::new(
63-
dec!(100),
64+
Decimal::from(100),
6465
"STK",
65-
dec!(10.20),
66-
TaxItem::new(dec!(20), TaxCategory::S),
66+
Decimal::new(1020, 2),
67+
TaxItem::new(Decimal::from(20), TaxCategory::S),
6768
)
6869
.with_position_number(1)
6970
.with_description("Schraubenzieher")
70-
.with_base_quantity(dec!(1)),
71+
.with_base_quantity(Decimal::from(1)),
7172
)
7273
.with_item(
7374
DetailsItem::new(
74-
dec!(1),
75+
Decimal::from(1),
7576
"STK",
76-
dec!(5.00),
77-
TaxItem::new(dec!(10), TaxCategory::AA),
77+
Decimal::from(5),
78+
TaxItem::new(Decimal::from(10), TaxCategory::AA),
7879
)
7980
.with_position_number(2)
8081
.with_description("Handbuch zur Schraube")
81-
.with_base_quantity(dec!(1))
82+
.with_base_quantity(Decimal::from(1))
8283
.with_reduction(
83-
ReductionListLineItem::new(dec!(5), ReductionAndSurchargeValue::Amount(dec!(2)))
84-
.with_comment("reduction"),
84+
ReductionListLineItem::new(
85+
Decimal::from(5),
86+
ReductionAndSurchargeValue::Amount(Decimal::from(2)),
87+
)
88+
.with_comment("reduction"),
8589
),
8690
)
8791
.with_document_title("An invoice")

src/reduction_and_surcharge.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ impl ToXml for ReductionAndSurchargeListLineItemDetails<'_> {
205205
#[cfg(test)]
206206
mod tests {
207207
use super::*;
208-
use rust_decimal_macros::dec;
209208

210209
use crate::xml::ToXml;
211210

@@ -214,14 +213,17 @@ mod tests {
214213
let result = ReductionAndSurchargeListLineItemDetails::new()
215214
.with_reduction(
216215
ReductionListLineItem::new(
217-
dec!(100),
218-
ReductionAndSurchargeValue::Percentage(dec!(2)),
216+
Decimal::from(100),
217+
ReductionAndSurchargeValue::Percentage(Decimal::from(2)),
219218
)
220219
.with_comment("reduction"),
221220
)
222221
.with_surcharge(
223-
SurchargeListLineItem::new(dec!(200), ReductionAndSurchargeValue::Amount(dec!(3)))
224-
.with_comment("surcharge"),
222+
SurchargeListLineItem::new(
223+
Decimal::from(200),
224+
ReductionAndSurchargeValue::Amount(Decimal::from(3)),
225+
)
226+
.with_comment("surcharge"),
225227
)
226228
.to_xml();
227229

@@ -232,13 +234,16 @@ mod tests {
232234

233235
let result = ReductionAndSurchargeListLineItemDetails::new()
234236
.with_reduction(
235-
ReductionListLineItem::new(dec!(100), ReductionAndSurchargeValue::Amount(dec!(2)))
236-
.with_comment("reduction"),
237+
ReductionListLineItem::new(
238+
Decimal::from(100),
239+
ReductionAndSurchargeValue::Amount(Decimal::from(2)),
240+
)
241+
.with_comment("reduction"),
237242
)
238243
.with_surcharge(
239244
SurchargeListLineItem::new(
240-
dec!(200),
241-
ReductionAndSurchargeValue::Percentage(dec!(3)),
245+
Decimal::from(200),
246+
ReductionAndSurchargeValue::Percentage(Decimal::from(3)),
242247
)
243248
.with_comment("surcharge"),
244249
)
@@ -252,8 +257,11 @@ mod tests {
252257
let result = ReductionAndSurchargeListLineItemDetails::new()
253258
.with_reduction(
254259
ReductionListLineItem::new(
255-
dec!(100),
256-
ReductionAndSurchargeValue::PercentageAndAmount(dec!(2), dec!(3.4599)),
260+
Decimal::from(100),
261+
ReductionAndSurchargeValue::PercentageAndAmount(
262+
Decimal::from(2),
263+
Decimal::new(34599, 4),
264+
),
257265
)
258266
.with_comment("reduction"),
259267
)

0 commit comments

Comments
 (0)