/* ==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- sub-strs Copyright (C) 2019-2023 Anonymous There are several releases over multiple years, they are listed as ranges, such as: "2019-2023". This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . ::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::-- */ #[test] #[cfg(feature="std")] fn test_sub_strs() { for (inner, start, end) in &[("1.2.3+something", concat!('`'), concat!('`'))] { let src = format!("//! # {start}{inner}{end} _(July 3rd, 2022)_", start=start, inner=inner, end=end); let mut parts = sub_strs::sub_strs(&src, start, end); let sub = parts.next().unwrap(); assert!(parts.next().is_none()); { let range = sub.range(); assert_eq!(range.start, sub.start()); assert_eq!(range.end, sub.end()); } { let range = sub.inner_range(); assert_eq!(range.start, sub.inner_start()); assert_eq!(range.end, sub.inner_end()); } assert_eq!(inner, &sub.inner()); let inner_start = src.find(inner).unwrap(); assert_eq!(inner_start, sub.inner_start()); assert_eq!(inner_start + inner.len(), sub.inner_end()); assert_eq!(inner, &&src[sub.inner_start()..sub.inner_end()]); assert_eq!(inner_start - start.len(), sub.start()); assert_eq!(inner_start + inner.len() + end.len(), sub.end()); } }