| 1 | #![cfg(any(feature = "parse-floats", feature = "parse-integers"))] |
| 2 | |
| 3 | use lexical_utilrust-analyzer cargo lexical-util 1.0.7 crate/::iteratorrust-analyzer cargo lexical-util 1.0.7 iterator/::{AsBytesrust-analyzer cargo lexical-util 1.0.7 skip/AsBytes#, Bytesrust-analyzer cargo lexical-util 1.0.7 skip/Bytes#, DigitsIterrust-analyzer cargo lexical-util 1.0.7 iterator/DigitsIter#, Iterrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#}; |
| 4 | |
| 5 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6 | #[cfg(not(feature = "format"))] |
| 7 | fn digits_iterator_test() { |
| 8 | use lexical_utilrust-analyzer cargo lexical-util 1.0.7 crate/::formatrust-analyzer cargo lexical-util 1.0.7 format/::STANDARDrust-analyzer cargo lexical-util 1.0.7 format/STANDARD.; |
| 9 | |
| 10 | type Digits<'a> = Bytesrust-analyzer cargo lexical-util 1.0.7 skip/Bytes#<'a, { STANDARD }>; |
| 11 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Digits::IS_CONTIGUOUS); |
| 12 | |
| 13 | let digits = b"12345"; |
| 14 | let mut byte1 = Digits::new(digits); |
| 15 | let mut byte2 = Digits::new(digits); |
| 16 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(byte1.integer_iter().eq(byte2.integer_iter())); |
| 17 | |
| 18 | let mut byte = digits.bytes::<{ STANDARD }>(); |
| 19 | let mut iter = byte.integer_iter(); |
| 20 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.as_slice(), &digits[..]); |
| 21 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.as_ptr(), digits.as_ptr()); |
| 22 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.is_consumed(), false); |
| 23 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.is_buffer_empty(), false); |
| 24 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(u32::from_le(iter.peek_u32().unwrap()), 0x34333231); |
| 25 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.buffer_length(), 5); |
| 26 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.cursor(), 0); |
| 27 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.current_count(), 0); |
| 28 | unsafe { |
| 29 | iter.step_by_unchecked(4); |
| 30 | } |
| 31 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.buffer_length(), 5); |
| 32 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.cursor(), 4); |
| 33 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.current_count(), 4); |
| 34 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.peek(), Some(&b'5')); |
| 35 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.peek(), Some(&b'5')); |
| 36 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.next(), Some(&b'5')); |
| 37 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.peek(), None); |
| 38 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.next(), None); |
| 39 | |
| 40 | let mut byte = digits.bytes::<{ STANDARD }>(); |
| 41 | let mut iter = byte.integer_iter(); |
| 42 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.peek_u64(), None); |
| 43 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nth(4).unwrap(), &b'5'); |
| 44 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.as_slice(), &digits[digits.len()..]); |
| 45 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.as_ptr(), digits[digits.len()..].as_ptr()); |
| 46 | |
| 47 | let mut byte = digits.bytes::<{ STANDARD }>(); |
| 48 | let mut iter = byte.integer_iter(); |
| 49 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.peek(), Some(&b'1')); |
| 50 | unsafe { |
| 51 | iter.step_unchecked(); |
| 52 | } |
| 53 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.peek(), Some(&b'2')); |
| 54 | unsafe { |
| 55 | iter.step_unchecked(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 60 | #[cfg(feature = "format")] |
| 61 | fn skip_iterator_testrust-analyzer cargo lexical-util 1.0.7 skip_iterator_test().() { |
| 62 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::numrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/; |
| 63 | |
| 64 | use lexical_utilrust-analyzer cargo lexical-util 1.0.7 crate/::formatrust-analyzer cargo lexical-util 1.0.7 format/::NumberFormatBuilderrust-analyzer cargo lexical-util 1.0.7 format_builder/NumberFormatBuilder#; |
| 65 | |
| 66 | pub const FORMATrust-analyzer cargo lexical-util 1.0.7 FORMAT.: u128 = NumberFormatBuilderrust-analyzer cargo lexical-util 1.0.7 format_builder/NumberFormatBuilder#::newrust-analyzer cargo lexical-util 1.0.7 format_builder/impl#[NumberFormatBuilder]new().() |
| 67 | .digit_separatorrust-analyzer cargo lexical-util 1.0.7 format_builder/impl#[NumberFormatBuilder]digit_separator().(numrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/::NonZeroU8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU8#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new().(b'_')) |
| 68 | .digit_separator_flagsrust-analyzer cargo lexical-util 1.0.7 format_builder/impl#[NumberFormatBuilder]digit_separator_flags().(true) |
| 69 | .build_strictrust-analyzer cargo lexical-util 1.0.7 format_builder/impl#[NumberFormatBuilder]build_strict().(); |
| 70 | |
| 71 | type Digitsrust-analyzer cargo lexical-util 1.0.7 Digits#<'a> = Bytesrust-analyzer cargo lexical-util 1.0.7 skip/Bytes#<'a, { FORMATrust-analyzer cargo lexical-util 1.0.7 FORMAT. }>; |
| 72 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Digitsrust-analyzer cargo lexical-util 1.0.7 Digits#::IS_CONTIGUOUSrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#IS_CONTIGUOUS.); |
| 73 | |
| 74 | let digits = b"123_45"; |
| 75 | let mut byte1 = Digitsrust-analyzer cargo lexical-util 1.0.7 Digits#::newrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`Bytes<'a, FORMAT>`]new().(digits); |
| 76 | let mut byte2 = Digitsrust-analyzer cargo lexical-util 1.0.7 Digits#::newrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`Bytes<'a, FORMAT>`]new().(digits); |
| 77 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(byte1.integer_iterrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`Bytes<'a, FORMAT>`]integer_iter().().eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#eq().(byte2.integer_iterrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`Bytes<'a, FORMAT>`]integer_iter().())); |
| 78 | |
| 79 | let mut byte = digits.bytesrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`[u8]`][`AsBytes<'a>`]bytes().::<{ FORMATrust-analyzer cargo lexical-util 1.0.7 FORMAT. }>(); |
| 80 | let mut iter = byte.integer_iterrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`Bytes<'a, FORMAT>`]integer_iter().(); |
| 81 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.as_slicerust-analyzer cargo lexical-util 1.0.7 iterator/Iter#as_slice().(), &digits[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 82 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.as_ptrrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#as_ptr().(), digits.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().()); |
| 83 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.is_consumedrust-analyzer cargo lexical-util 1.0.7 iterator/DigitsIter#is_consumed().(), false); |
| 84 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.is_buffer_emptyrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#is_buffer_empty().(), false); |
| 85 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.buffer_lengthrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#buffer_length().(), 6); |
| 86 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.cursorrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#cursor().(), 0); |
| 87 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.current_countrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#current_count().(), 0); |
| 88 | unsafe { iter.step_uncheckedrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#step_unchecked().() }; |
| 89 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.cursorrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#cursor().(), 1); |
| 90 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.current_countrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#current_count().(), 0); |
| 91 | iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(); |
| 92 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.cursorrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#cursor().(), 2); |
| 93 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.current_countrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#current_count().(), 1); |
| 94 | |
| 95 | let mut byte = digits.bytesrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`[u8]`][`AsBytes<'a>`]bytes().::<{ FORMATrust-analyzer cargo lexical-util 1.0.7 FORMAT. }>(); |
| 96 | let mut iter = byte.integer_iterrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`Bytes<'a, FORMAT>`]integer_iter().(); |
| 97 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.peekrust-analyzer cargo lexical-util 1.0.7 iterator/DigitsIter#peek().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&b'1')); |
| 98 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.peekrust-analyzer cargo lexical-util 1.0.7 iterator/DigitsIter#peek().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&b'1')); |
| 99 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&b'1')); |
| 100 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&b'2')); |
| 101 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&b'3')); |
| 102 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.cursorrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#cursor().(), 3); |
| 103 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.current_countrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#current_count().(), 3); |
| 104 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&b'4')); |
| 105 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.cursorrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#cursor().(), 5); |
| 106 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.current_countrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#current_count().(), 4); |
| 107 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&b'5')); |
| 108 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 109 | |
| 110 | let mut byte = digits.bytesrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`[u8]`][`AsBytes<'a>`]bytes().::<{ FORMATrust-analyzer cargo lexical-util 1.0.7 FORMAT. }>(); |
| 111 | let mut iter = byte.integer_iterrust-analyzer cargo lexical-util 1.0.7 skip/impl#[`Bytes<'a, FORMAT>`]integer_iter().(); |
| 112 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), &b'5'); |
| 113 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.as_slicerust-analyzer cargo lexical-util 1.0.7 iterator/Iter#as_slice().(), &digits[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().digits.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()..]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 114 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.as_ptrrust-analyzer cargo lexical-util 1.0.7 iterator/Iter#as_ptr().(), digits[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().digits.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()..]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().()); |
| 115 | } |