Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3dc77f

Browse files
committed
add proptest and fix 0 case
1 parent544abaa commite3dc77f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

‎postgres-protocol/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ rand = "0.9"
2424
sha2 ="0.10"
2525
stringprep ="0.1"
2626
getrandom = {version ="0.3",optional =true }
27+
28+
[dev-dependencies]
29+
proptest ="1.6.0"

‎postgres-protocol/src/types/numeric.rs‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl FromStr for Numeric {
261261
integer.pop_front();
262262
}
263263

264-
letmut weight =if integer.is_empty()|| integer ==b"0"{
264+
letmut weight =if integer.is_empty(){
265265
-1
266266
}else{
267267
integer.len().div_ceil(4)asi16 -1
@@ -365,6 +365,15 @@ mod test {
365365
#[test]
366366
fntest_string_deserialization_and_serialization(){
367367
let cases =&[
368+
(
369+
"0",
370+
Numeric{
371+
sign:NumericSign::Positive,
372+
scale:0,
373+
weight:0,
374+
digits:vec![],
375+
},
376+
),
368377
(
369378
"1",
370379
Numeric{
@@ -810,4 +819,22 @@ mod test {
810819
assert_eq!(num.to_string(),*str,"{e} back to string");
811820
}
812821
}
822+
823+
use proptest::prelude::*;
824+
proptest!{
825+
#[test]
826+
fn test_arbitrary_f32_to_string_and_back(value in any::<f64>()){
827+
let prop_val = value.to_string();
828+
let numeric =Numeric::from_str(&prop_val).expect("parse numeric");
829+
let str_val = numeric.to_string();
830+
assert_eq!(prop_val, str_val,"proprty test value {value}");
831+
}
832+
#[test]
833+
fn test_arbitrary_i32_to_string_and_back(value in any::<i64>()){
834+
let prop_val = value.to_string();
835+
let numeric =Numeric::from_str(&prop_val).expect("parse numeric");
836+
let str_val = numeric.to_string();
837+
assert_eq!(prop_val, str_val,"proprty test value {value}");
838+
}
839+
}
813840
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp