Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-jiter for openSUSE:Factory checked in at 2026-06-28 21:10:23 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-jiter (Old) and /work/SRC/openSUSE:Factory/.python-jiter.new.11887 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-jiter" Sun Jun 28 21:10:23 2026 rev:5 rq:1362135 version:0.15.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-jiter/python-jiter.changes 2026-04-12 20:17:49.763453438 +0200 +++ /work/SRC/openSUSE:Factory/.python-jiter.new.11887/python-jiter.changes 2026-06-28 21:11:33.772260914 +0200 @@ -1,0 +2,7 @@ +Sun Jun 28 09:50:31 UTC 2026 - Dirk Müller <[email protected]> + +- update to 0.15.0: + * expose `known_number_bytes` and parser methods for bytes -> + number + +------------------------------------------------------------------- Old: ---- jiter-0.14.0.tar.gz New: ---- jiter-0.15.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-jiter.spec ++++++ --- /var/tmp/diff_new_pack.mwsLA2/_old 2026-06-28 21:11:36.356348293 +0200 +++ /var/tmp/diff_new_pack.mwsLA2/_new 2026-06-28 21:11:36.380349105 +0200 @@ -18,7 +18,7 @@ %{?sle15_python_module_pythons} Name: python-jiter -Version: 0.14.0 +Version: 0.15.0 Release: 0 Summary: Fast iterable JSON parser License: MIT ++++++ _service ++++++ --- /var/tmp/diff_new_pack.mwsLA2/_old 2026-06-28 21:11:36.680359250 +0200 +++ /var/tmp/diff_new_pack.mwsLA2/_new 2026-06-28 21:11:36.724360737 +0200 @@ -1,7 +1,7 @@ <services> <service name="download_files" mode="manual"/> <service name="cargo_vendor" mode="manual"> - <param name="srctar">jiter-0.14.0.tar.gz</param> + <param name="srctar">jiter-0.15.0.tar.gz</param> <param name="compression">xz</param> <param name="update">true</param> </service> ++++++ jiter-0.14.0.tar.gz -> jiter-0.15.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jiter-0.14.0/Cargo.lock new/jiter-0.15.0/Cargo.lock --- old/jiter-0.14.0/Cargo.lock 2006-07-24 03:21:28.000000000 +0200 +++ new/jiter-0.15.0/Cargo.lock 2006-07-24 03:21:28.000000000 +0200 @@ -50,9 +50,9 @@ [[package]] name = "bitflags" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "bitvec" @@ -80,9 +80,9 @@ [[package]] name = "cc" -version = "1.2.60" +version = "1.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" dependencies = [ "find-msvc-tools", "shlex", @@ -123,9 +123,9 @@ [[package]] name = "clap" -version = "4.6.0" +version = "4.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" dependencies = [ "clap_builder", ] @@ -279,6 +279,30 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] name = "getrandom" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -325,9 +349,9 @@ [[package]] name = "hashbrown" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" [[package]] name = "heck" @@ -354,7 +378,7 @@ checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown 0.17.0", + "hashbrown 0.17.1", "serde", "serde_core", ] @@ -387,7 +411,7 @@ [[package]] name = "jiter" -version = "0.14.0" +version = "0.15.0" dependencies = [ "ahash", "bitvec", @@ -405,7 +429,7 @@ [[package]] name = "jiter-python" -version = "0.14.0" +version = "0.15.0" dependencies = [ "jiter", "pyo3", @@ -413,10 +437,12 @@ [[package]] name = "js-sys" -version = "0.3.94" +version = "0.3.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e04e2ef80ce82e13552136fabeef8a5ed1f985a96805761cbb9a2c34e7664d9" +checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08" dependencies = [ + "cfg-if", + "futures-util", "once_cell", "wasm-bindgen", ] @@ -460,9 +486,9 @@ [[package]] name = "libc" -version = "0.2.184" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "log" @@ -523,6 +549,12 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] name = "plotters" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -674,9 +706,9 @@ [[package]] name = "rayon" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d" dependencies = [ "either", "rayon-core", @@ -793,6 +825,12 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -845,9 +883,9 @@ [[package]] name = "uuid" -version = "1.23.0" +version = "1.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ac8b6f42ead25368cf5b098aeb3dc8a1a2c05a3eee8a9a1a68c640edbfc79d9" +checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" dependencies = [ "getrandom 0.4.2", "js-sys", @@ -872,11 +910,11 @@ [[package]] name = "wasip2" -version = "1.0.2+wasi-0.2.9" +version = "1.0.3+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.57.1", ] [[package]] @@ -885,14 +923,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.51.0", ] [[package]] name = "wasm-bindgen" -version = "0.2.117" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0551fc1bb415591e3372d0bc4780db7e587d84e2a7e79da121051c5c4b89d0b0" +checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790" dependencies = [ "cfg-if", "once_cell", @@ -903,9 +941,9 @@ [[package]] name = "wasm-bindgen-macro" -version = "0.2.117" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fbdf9a35adf44786aecd5ff89b4563a90325f9da0923236f6104e603c7e86be" +checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -913,9 +951,9 @@ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.117" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca9693ef2bab6d4e6707234500350d8dad079eb508dca05530c85dc3a529ff2" +checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2" dependencies = [ "bumpalo", "proc-macro2", @@ -926,9 +964,9 @@ [[package]] name = "wasm-bindgen-shared" -version = "0.2.117" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39129a682a6d2d841b6c429d0c51e5cb0ed1a03829d8b3d1e69a011e62cb3d3b" +checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441" dependencies = [ "unicode-ident", ] @@ -969,9 +1007,9 @@ [[package]] name = "web-sys" -version = "0.3.94" +version = "0.3.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd70027e39b12f0849461e08ffc50b9cd7688d942c1c8e3c7b22273236b4dd0a" +checksum = "4b572dff8bcf38bad0fa19729c89bb5748b2b9b1d8be70cf90df697e3a8f32aa" dependencies = [ "js-sys", "wasm-bindgen", @@ -1084,6 +1122,12 @@ ] [[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] name = "wit-bindgen-core" version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jiter-0.14.0/Cargo.toml new/jiter-0.15.0/Cargo.toml --- old/jiter-0.14.0/Cargo.toml 2006-07-24 03:21:28.000000000 +0200 +++ new/jiter-0.15.0/Cargo.toml 2006-07-24 03:21:28.000000000 +0200 @@ -5,7 +5,7 @@ [workspace.package] authors = ["Samuel Colvin <[email protected]>"] -version = "0.14.0" +version = "0.15.0" edition = "2024" license = "MIT" keywords = ["JSON", "parsing", "deserialization", "iter"] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jiter-0.14.0/PKG-INFO new/jiter-0.15.0/PKG-INFO --- old/jiter-0.14.0/PKG-INFO 2006-07-24 03:21:28.000000000 +0200 +++ new/jiter-0.15.0/PKG-INFO 2006-07-24 03:21:28.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.4 Name: jiter -Version: 0.14.0 +Version: 0.15.0 Classifier: Development Status :: 4 - Beta Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jiter-0.14.0/crates/jiter/src/jiter.rs new/jiter-0.15.0/crates/jiter/src/jiter.rs --- old/jiter-0.14.0/crates/jiter/src/jiter.rs 2006-07-24 03:21:28.000000000 +0200 +++ new/jiter-0.15.0/crates/jiter/src/jiter.rs 2006-07-24 03:21:28.000000000 +0200 @@ -168,6 +168,7 @@ pub fn known_float(&mut self, peek: Peek) -> JiterResult<f64> { self.parser .consume_number::<NumberFloat>(peek.into_inner(), self.allow_inf_nan) + .map(|f| f.0) .map_err(|e| self.maybe_number_error(e, JsonType::Float, peek)) } @@ -178,7 +179,7 @@ } /// Knowing the next value is a number, parse it and return bytes from the original JSON data. - fn known_number_bytes(&mut self, peek: Peek) -> JiterResult<&[u8]> { + pub fn known_number_bytes(&mut self, peek: Peek) -> JiterResult<&[u8]> { match self .parser .consume_number::<NumberRange>(peek.into_inner(), self.allow_inf_nan) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jiter-0.14.0/crates/jiter/src/lib.rs new/jiter-0.15.0/crates/jiter/src/lib.rs --- old/jiter-0.14.0/crates/jiter/src/lib.rs 2006-07-24 03:21:28.000000000 +0200 +++ new/jiter-0.15.0/crates/jiter/src/lib.rs 2006-07-24 03:21:28.000000000 +0200 @@ -165,7 +165,7 @@ pub use errors::{JiterError, JiterErrorType, JsonError, JsonErrorType, JsonResult, JsonType, LinePosition}; pub use jiter::{Jiter, JiterResult}; -pub use number_decoder::{NumberAny, NumberInt}; +pub use number_decoder::{NumberAny, NumberFloat, NumberInt}; pub use parse::Peek; pub use value::{JsonArray, JsonObject, JsonValue}; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jiter-0.14.0/crates/jiter/src/number_decoder.rs new/jiter-0.15.0/crates/jiter/src/number_decoder.rs --- old/jiter-0.14.0/crates/jiter/src/number_decoder.rs 2006-07-24 03:21:28.000000000 +0200 +++ new/jiter-0.15.0/crates/jiter/src/number_decoder.rs 2006-07-24 03:21:28.000000000 +0200 @@ -11,10 +11,8 @@ use crate::errors::{JsonError, JsonResult, json_err, json_error}; -pub trait AbstractNumberDecoder { - type Output; - - fn decode(data: &[u8], index: usize, first: u8, allow_inf_nan: bool) -> JsonResult<(Self::Output, usize)>; +pub trait AbstractNumberDecoder: Sized { + fn decode(data: &[u8], index: usize, first: u8, allow_inf_nan: bool) -> JsonResult<(Self, usize)>; } /// A number that can be either an [i64] or a [BigInt](num_bigint::BigInt) @@ -40,25 +38,25 @@ type Error = JsonError; fn try_from(value: &[u8]) -> Result<Self, Self::Error> { - let first = *value.first().ok_or_else(|| json_error!(InvalidNumber, 0))?; - let (int_parse, index) = IntParse::parse(value, 0, first)?; + Self::from_bytes(value) + } +} + +impl NumberInt { + /// Parse `data` as a JSON integer, erroring if the input is not a valid integer, + /// is empty, or contains trailing bytes. + pub fn from_bytes(data: &[u8]) -> JsonResult<Self> { + let first = *data.first().ok_or_else(|| json_error!(InvalidNumber, 0))?; + let (int_parse, index) = IntParse::parse(data, 0, first)?; match int_parse { - IntParse::Int(int) => { - if index == value.len() { - Ok(int) - } else { - json_err!(InvalidNumber, index) - } - } + IntParse::Int(int) if index == data.len() => Ok(int), _ => json_err!(InvalidNumber, index), } } } impl AbstractNumberDecoder for NumberInt { - type Output = NumberInt; - - fn decode(data: &[u8], index: usize, first: u8, _allow_inf_nan: bool) -> JsonResult<(Self::Output, usize)> { + fn decode(data: &[u8], index: usize, first: u8, _allow_inf_nan: bool) -> JsonResult<(Self, usize)> { let (int_parse, index) = IntParse::parse(data, index, first)?; match int_parse { IntParse::Int(int) => Ok((int, index)), @@ -67,16 +65,31 @@ } } -pub struct NumberFloat; +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct NumberFloat(pub f64); -impl AbstractNumberDecoder for NumberFloat { - type Output = f64; +impl From<NumberFloat> for f64 { + fn from(num: NumberFloat) -> Self { + num.0 + } +} + +impl NumberFloat { + /// Parse `data` as a JSON float, erroring if the input is empty or contains trailing bytes. + pub fn from_bytes(data: &[u8], allow_inf_nan: bool) -> JsonResult<Self> { + from_bytes_complete(data, allow_inf_nan) + } +} - fn decode(data: &[u8], mut index: usize, first: u8, allow_inf_nan: bool) -> JsonResult<(Self::Output, usize)> { +impl AbstractNumberDecoder for NumberFloat { + fn decode(data: &[u8], mut index: usize, first: u8, allow_inf_nan: bool) -> JsonResult<(Self, usize)> { let start = index; let positive = match first { - b'N' => return consume_nan(data, index, allow_inf_nan), + b'N' => { + let (f, end) = consume_nan(data, index, allow_inf_nan)?; + return Ok((Self(f), end)); + } b'-' => false, _ => true, }; @@ -91,7 +104,7 @@ const JSON: u128 = lexical_format::JSON; let options = ParseFloatOptions::new(); match f64::from_lexical_partial_with_options::<JSON>(&data[start..], &options) { - Ok((float, index)) => Ok((float, index + start)), + Ok((float, index)) => Ok((Self(float), index + start)), Err(_) => { // it's impossible to work out the right error from LexicalError here, so we parse again // with NumberRange and use that error @@ -104,7 +117,8 @@ } } } else if digit == &b'I' { - consume_inf_f64(data, index, positive, allow_inf_nan) + let (f, end) = consume_inf_f64(data, index, positive, allow_inf_nan)?; + Ok((Self(f), end)) } else { json_err!(InvalidNumber, index) } @@ -131,16 +145,21 @@ } } -impl AbstractNumberDecoder for NumberAny { - type Output = NumberAny; +impl NumberAny { + /// Parse `data` as a JSON number, erroring if the input is empty or contains trailing bytes. + pub fn from_bytes(data: &[u8], allow_inf_nan: bool) -> JsonResult<Self> { + from_bytes_complete(data, allow_inf_nan) + } +} - fn decode(data: &[u8], index: usize, first: u8, allow_inf_nan: bool) -> JsonResult<(Self::Output, usize)> { +impl AbstractNumberDecoder for NumberAny { + fn decode(data: &[u8], index: usize, first: u8, allow_inf_nan: bool) -> JsonResult<(Self, usize)> { let start = index; let (int_parse, index) = IntParse::parse(data, index, first)?; match int_parse { IntParse::Int(int) => Ok((Self::Int(int), index)), IntParse::Float => { - NumberFloat::decode(data, start, first, allow_inf_nan).map(|(f, index)| (Self::Float(f), index)) + NumberFloat::decode(data, start, first, allow_inf_nan).map(|(f, index)| (Self::Float(f.0), index)) } IntParse::FloatInf(positive) => { consume_inf_f64(data, index, positive, allow_inf_nan).map(|(f, index)| (Self::Float(f), index)) @@ -150,6 +169,16 @@ } } +fn from_bytes_complete<D: AbstractNumberDecoder>(data: &[u8], allow_inf_nan: bool) -> JsonResult<D> { + let first = *data.first().ok_or_else(|| json_error!(InvalidNumber, 0))?; + let (output, index) = D::decode(data, 0, first, allow_inf_nan)?; + if index == data.len() { + Ok(output) + } else { + json_err!(InvalidNumber, index) + } +} + fn consume_inf(data: &[u8], index: usize, positive: bool, allow_inf_nan: bool) -> JsonResult<usize> { if allow_inf_nan { crate::parse::consume_infinity(data, index) @@ -396,9 +425,7 @@ } impl AbstractNumberDecoder for NumberRange { - type Output = Self; - - fn decode(data: &[u8], mut index: usize, first: u8, allow_inf_nan: bool) -> JsonResult<(Self::Output, usize)> { + fn decode(data: &[u8], mut index: usize, first: u8, allow_inf_nan: bool) -> JsonResult<(Self, usize)> { let start = index; let positive = match first { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jiter-0.14.0/crates/jiter/src/parse.rs new/jiter-0.15.0/crates/jiter/src/parse.rs --- old/jiter-0.14.0/crates/jiter/src/parse.rs 2006-07-24 03:21:28.000000000 +0200 +++ new/jiter-0.15.0/crates/jiter/src/parse.rs 2006-07-24 03:21:28.000000000 +0200 @@ -209,11 +209,7 @@ Ok(output) } - pub fn consume_number<D: AbstractNumberDecoder>( - &mut self, - first: u8, - allow_inf_nan: bool, - ) -> JsonResult<D::Output> { + pub fn consume_number<D: AbstractNumberDecoder>(&mut self, first: u8, allow_inf_nan: bool) -> JsonResult<D> { let (output, index) = D::decode(self.data, self.index, first, allow_inf_nan)?; self.index = index; Ok(output) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jiter-0.14.0/crates/jiter/tests/main.rs new/jiter-0.15.0/crates/jiter/tests/main.rs --- old/jiter-0.14.0/crates/jiter/tests/main.rs 2006-07-24 03:21:28.000000000 +0200 +++ new/jiter-0.15.0/crates/jiter/tests/main.rs 2006-07-24 03:21:28.000000000 +0200 @@ -11,7 +11,7 @@ use jiter::{ Jiter, JiterErrorType, JiterResult, JsonErrorType, JsonObject, JsonType, JsonValue, LinePosition, NumberAny, - NumberInt, PartialMode, Peek, + NumberFloat, NumberInt, PartialMode, Peek, }; fn json_vec(jiter: &mut Jiter, peek: Option<Peek>) -> JiterResult<Vec<String>> { @@ -1351,6 +1351,116 @@ } #[test] +fn test_number_any_from_bytes() { + assert_eq!( + NumberAny::from_bytes(b"123", false).unwrap(), + NumberAny::Int(NumberInt::Int(123)) + ); + assert_eq!( + NumberAny::from_bytes(b"-123", false).unwrap(), + NumberAny::Int(NumberInt::Int(-123)) + ); + assert_eq!( + NumberAny::from_bytes(b"0", false).unwrap(), + NumberAny::Int(NumberInt::Int(0)) + ); + assert_eq!(NumberAny::from_bytes(b"1.5", false).unwrap(), NumberAny::Float(1.5)); + assert_eq!(NumberAny::from_bytes(b"-1.5", false).unwrap(), NumberAny::Float(-1.5)); + assert_eq!(NumberAny::from_bytes(b"1e3", false).unwrap(), NumberAny::Float(1e3)); + assert_eq!( + NumberAny::from_bytes(b"0.5e-2", false).unwrap(), + NumberAny::Float(0.5e-2) + ); + + #[cfg(feature = "num-bigint")] + { + let twenty_nines = "9".repeat(29); + let n = NumberAny::from_bytes(twenty_nines.as_bytes(), false).unwrap(); + match n { + NumberAny::Int(NumberInt::BigInt(v)) => assert_eq!(v.to_string(), twenty_nines), + _ => panic!("expected big int"), + } + } + + let e = NumberAny::from_bytes(b"", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 0"); + + let e = NumberAny::from_bytes(b"x23", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 0"); + + let e = NumberAny::from_bytes(b"123 ", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 3"); + + let e = NumberAny::from_bytes(b"1.5x", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 3"); + + let e = NumberAny::from_bytes(b"0123", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 1"); + + // allow_inf_nan toggles + let e = NumberAny::from_bytes(b"NaN", false).unwrap_err(); + assert_eq!(e.error_type, JsonErrorType::ExpectedSomeValue); + let e = NumberAny::from_bytes(b"Infinity", false).unwrap_err(); + assert_eq!(e.error_type, JsonErrorType::ExpectedSomeValue); + + match NumberAny::from_bytes(b"NaN", true).unwrap() { + NumberAny::Float(f) => assert!(f.is_nan()), + other @ NumberAny::Int(_) => panic!("expected NaN, got {other:?}"), + } + assert_eq!( + NumberAny::from_bytes(b"Infinity", true).unwrap(), + NumberAny::Float(f64::INFINITY) + ); + assert_eq!( + NumberAny::from_bytes(b"-Infinity", true).unwrap(), + NumberAny::Float(f64::NEG_INFINITY) + ); +} + +#[test] +fn test_number_float_from_bytes() { + assert_eq!(NumberFloat::from_bytes(b"1.5", false).unwrap(), NumberFloat(1.5)); + assert_eq!(NumberFloat::from_bytes(b"-1.5", false).unwrap(), NumberFloat(-1.5)); + assert_eq!(NumberFloat::from_bytes(b"0", false).unwrap(), NumberFloat(0.0)); + // integer-shaped input parses as float + assert_eq!(NumberFloat::from_bytes(b"42", false).unwrap(), NumberFloat(42.0)); + assert_eq!(NumberFloat::from_bytes(b"1e3", false).unwrap(), NumberFloat(1e3)); + assert_eq!(NumberFloat::from_bytes(b"1.5e-2", false).unwrap(), NumberFloat(1.5e-2)); + + let e = NumberFloat::from_bytes(b"", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 0"); + + let e = NumberFloat::from_bytes(b"x", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 0"); + + let e = NumberFloat::from_bytes(b"1.5 ", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 3"); + + let e = NumberFloat::from_bytes(b"1.5x", false).unwrap_err(); + assert_eq!(e.to_string(), "invalid number at index 3"); + + // allow_inf_nan toggles + let e = NumberFloat::from_bytes(b"NaN", false).unwrap_err(); + assert_eq!(e.error_type, JsonErrorType::ExpectedSomeValue); + let e = NumberFloat::from_bytes(b"Infinity", false).unwrap_err(); + assert_eq!(e.error_type, JsonErrorType::ExpectedSomeValue); + + assert!(NumberFloat::from_bytes(b"NaN", true).unwrap().0.is_nan()); + assert_eq!( + NumberFloat::from_bytes(b"Infinity", true).unwrap(), + NumberFloat(f64::INFINITY) + ); + assert_eq!( + NumberFloat::from_bytes(b"-Infinity", true).unwrap(), + NumberFloat(f64::NEG_INFINITY) + ); + + // From<NumberFloat> for f64 + let f: f64 = NumberFloat::from_bytes(b"2.5", false).unwrap().into(); + assert_eq!(f, 2.5); +} + +#[test] fn jiter_skip_whole_object() { let mut jiter = Jiter::new(br#"{"x": 1}"#); jiter.next_skip().unwrap(); ++++++ vendor.tar.xz ++++++ /work/SRC/openSUSE:Factory/python-jiter/vendor.tar.xz /work/SRC/openSUSE:Factory/.python-jiter.new.11887/vendor.tar.xz differ: char 15, line 1
