Debian Codegraph @

tests/test_arbitrary_precision.rs

raw symbols SCIP
1 #![cfg(feature = "arbitrary_precision")]
2
3 use pyo3rust-analyzer cargo pyo3 0.28.1 crate/::preluderust-analyzer cargo pyo3 0.28.1 prelude/::*;
4 use pythonizerust-analyzer cargo pythonize 0.28.0 crate/::{depythonizerust-analyzer cargo pythonize 0.28.0 de/depythonize()., pythonizerust-analyzer cargo pythonize 0.28.0 ser/pythonize().};
5 use serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::Valuerust-analyzer cargo serde_json 1.0.149 value/Value#;
6
7 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
8 fn test_greater_than_u64_maxrust-analyzer cargo pythonize 0.28.0 test_greater_than_u64_max().() {
9 Pythonrust-analyzer cargo pyo3 0.28.1 marker/Python#::attachrust-analyzer cargo pyo3 0.28.1 marker/impl#[`Python<'_>`]attach().(|py| {
10 let json_str = r#"18446744073709551616"#;
11 let value: Valuerust-analyzer cargo serde_json 1.0.149 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::from_strrust-analyzer cargo serde_json 1.0.149 de/from_str().(json_str).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
12 let result = pythonizerust-analyzer cargo pythonize 0.28.0 ser/pythonize().(py, &value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
13 let number_str = result.strrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
14
15 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_instance_ofrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]is_instance_of().::<pyo3rust-analyzer cargo pyo3 0.28.1 crate/::typesrust-analyzer cargo pyo3 0.28.1 types/::PyIntrust-analyzer cargo pyo3 0.28.1 types/num/PyInt#>());
16 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(number_str, "18446744073709551616");
17 });
18 }
19
20 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
21 fn test_less_than_i64_minrust-analyzer cargo pythonize 0.28.0 test_less_than_i64_min().() {
22 Pythonrust-analyzer cargo pyo3 0.28.1 marker/Python#::attachrust-analyzer cargo pyo3 0.28.1 marker/impl#[`Python<'_>`]attach().(|py| {
23 let json_str = r#"-9223372036854775809"#;
24 let value: Valuerust-analyzer cargo serde_json 1.0.149 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::from_strrust-analyzer cargo serde_json 1.0.149 de/from_str().(json_str).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
25 let result = pythonizerust-analyzer cargo pythonize 0.28.0 ser/pythonize().(py, &value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
26 let number_str = result.strrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
27
28 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_instance_ofrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]is_instance_of().::<pyo3rust-analyzer cargo pyo3 0.28.1 crate/::typesrust-analyzer cargo pyo3 0.28.1 types/::PyIntrust-analyzer cargo pyo3 0.28.1 types/num/PyInt#>());
29 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(number_str, "-9223372036854775809");
30 });
31 }
32
33 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
34 fn test_floatrust-analyzer cargo pythonize 0.28.0 test_float().() {
35 Pythonrust-analyzer cargo pyo3 0.28.1 marker/Python#::attachrust-analyzer cargo pyo3 0.28.1 marker/impl#[`Python<'_>`]attach().(|py| {
36 let json_str = r#"3.141592653589793238"#;
37 let value: Valuerust-analyzer cargo serde_json 1.0.149 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::from_strrust-analyzer cargo serde_json 1.0.149 de/from_str().(json_str).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
38 let result = pythonizerust-analyzer cargo pythonize 0.28.0 ser/pythonize().(py, &value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
39 let num: f32 = result.extractrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]extract().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
40
41 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_instance_ofrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]is_instance_of().::<pyo3rust-analyzer cargo pyo3 0.28.1 crate/::typesrust-analyzer cargo pyo3 0.28.1 types/::PyFloatrust-analyzer cargo pyo3 0.28.1 types/float/PyFloat#>());
42 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(num, 3.141592653589793238); // not {'$serde_json::private::Number': ...}
43 });
44 }
45
46 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
47 fn test_intrust-analyzer cargo pythonize 0.28.0 test_int().() {
48 Pythonrust-analyzer cargo pyo3 0.28.1 marker/Python#::attachrust-analyzer cargo pyo3 0.28.1 marker/impl#[`Python<'_>`]attach().(|py| {
49 let json_str = r#"2"#;
50 let value: Valuerust-analyzer cargo serde_json 1.0.149 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::from_strrust-analyzer cargo serde_json 1.0.149 de/from_str().(json_str).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
51 let result = pythonizerust-analyzer cargo pythonize 0.28.0 ser/pythonize().(py, &value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
52 let num: i32 = result.extractrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]extract().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
53
54 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_instance_ofrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]is_instance_of().::<pyo3rust-analyzer cargo pyo3 0.28.1 crate/::typesrust-analyzer cargo pyo3 0.28.1 types/::PyIntrust-analyzer cargo pyo3 0.28.1 types/num/PyInt#>());
55 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(num, 2); // not {'$serde_json::private::Number': '2'}
56 });
57 }
58
59 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
60 fn test_serde_error_if_token_emptyrust-analyzer cargo pythonize 0.28.0 test_serde_error_if_token_empty().() {
61 let json_str = r#"{"$serde_json::private::Number": ""}"#;
62 let result: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.149 value/Value#, _> = serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::from_strrust-analyzer cargo serde_json 1.0.149 de/from_str().(json_str);
63
64 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
65 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result
66 .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().()
67 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
68 .containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("EOF while parsing a value"));
69 }
70
71 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
72 fn test_serde_error_if_token_invalidrust-analyzer cargo pythonize 0.28.0 test_serde_error_if_token_invalid().() {
73 let json_str = r#"{"$serde_json::private::Number": 2}"#;
74 let result: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.149 value/Value#, _> = serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::from_strrust-analyzer cargo serde_json 1.0.149 de/from_str().(json_str);
75
76 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
77 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result
78 .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().()
79 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
80 .containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("invalid type: integer `2`, expected string containing a number"));
81 }
82
83 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
84 fn test_token_validrust-analyzer cargo pythonize 0.28.0 test_token_valid().() {
85 Pythonrust-analyzer cargo pyo3 0.28.1 marker/Python#::attachrust-analyzer cargo pyo3 0.28.1 marker/impl#[`Python<'_>`]attach().(|py| {
86 let json_str = r#"{"$serde_json::private::Number": "2"}"#;
87 let value: Valuerust-analyzer cargo serde_json 1.0.149 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::from_strrust-analyzer cargo serde_json 1.0.149 de/from_str().(json_str).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
88 let result = pythonizerust-analyzer cargo pythonize 0.28.0 ser/pythonize().(py, &value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
89 let num: i32 = result.extractrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]extract().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
90
91 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_instance_ofrust-analyzer cargo pyo3 0.28.1 types/any/impl#[`Bound<'py, PyAny>`][`PyAnyMethods<'py>`]is_instance_of().::<pyo3rust-analyzer cargo pyo3 0.28.1 crate/::typesrust-analyzer cargo pyo3 0.28.1 types/::PyIntrust-analyzer cargo pyo3 0.28.1 types/num/PyInt#>());
92 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(num, 2);
93 });
94 }
95
96 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
97 fn test_depythonize_greater_than_u128_maxrust-analyzer cargo pythonize 0.28.0 test_depythonize_greater_than_u128_max().() {
98 Pythonrust-analyzer cargo pyo3 0.28.1 marker/Python#::attachrust-analyzer cargo pyo3 0.28.1 marker/impl#[`Python<'_>`]attach().(|py| {
99 // u128::MAX + 1
100 let py_int = py
101 .evalrust-analyzer cargo pyo3 0.28.1 marker/impl#[`Python<'py>`]eval().(c"340282366920938463463374607431768211456", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
102 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
103 let value: Valuerust-analyzer cargo serde_json 1.0.149 value/Value# = depythonizerust-analyzer cargo pythonize 0.28.0 de/depythonize().(&py_int).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
104
105 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(value.is_numberrust-analyzer cargo serde_json 1.0.149 value/impl#[Value]is_number().());
106 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "340282366920938463463374607431768211456");
107 });
108 }