summaryrefslogtreecommitdiffstats
path: root/third_party/rust/anyhow/tests/test_chain.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/anyhow/tests/test_chain.rs
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/anyhow/tests/test_chain.rs')
-rw-r--r--third_party/rust/anyhow/tests/test_chain.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/third_party/rust/anyhow/tests/test_chain.rs b/third_party/rust/anyhow/tests/test_chain.rs
new file mode 100644
index 0000000000..47d98afe20
--- /dev/null
+++ b/third_party/rust/anyhow/tests/test_chain.rs
@@ -0,0 +1,68 @@
+use anyhow::{anyhow, Chain, Error};
+
+fn error() -> Error {
+ anyhow!({ 0 }).context(1).context(2).context(3)
+}
+
+#[test]
+fn test_iter() {
+ let e = error();
+ let mut chain = e.chain();
+ assert_eq!("3", chain.next().unwrap().to_string());
+ assert_eq!("2", chain.next().unwrap().to_string());
+ assert_eq!("1", chain.next().unwrap().to_string());
+ assert_eq!("0", chain.next().unwrap().to_string());
+ assert!(chain.next().is_none());
+ assert!(chain.next_back().is_none());
+}
+
+#[test]
+fn test_rev() {
+ let e = error();
+ let mut chain = e.chain().rev();
+ assert_eq!("0", chain.next().unwrap().to_string());
+ assert_eq!("1", chain.next().unwrap().to_string());
+ assert_eq!("2", chain.next().unwrap().to_string());
+ assert_eq!("3", chain.next().unwrap().to_string());
+ assert!(chain.next().is_none());
+ assert!(chain.next_back().is_none());
+}
+
+#[test]
+fn test_len() {
+ let e = error();
+ let mut chain = e.chain();
+ assert_eq!(4, chain.len());
+ assert_eq!((4, Some(4)), chain.size_hint());
+ assert_eq!("3", chain.next().unwrap().to_string());
+ assert_eq!(3, chain.len());
+ assert_eq!((3, Some(3)), chain.size_hint());
+ assert_eq!("0", chain.next_back().unwrap().to_string());
+ assert_eq!(2, chain.len());
+ assert_eq!((2, Some(2)), chain.size_hint());
+ assert_eq!("2", chain.next().unwrap().to_string());
+ assert_eq!(1, chain.len());
+ assert_eq!((1, Some(1)), chain.size_hint());
+ assert_eq!("1", chain.next_back().unwrap().to_string());
+ assert_eq!(0, chain.len());
+ assert_eq!((0, Some(0)), chain.size_hint());
+ assert!(chain.next().is_none());
+}
+
+#[test]
+fn test_default() {
+ let mut c = Chain::default();
+ assert!(c.next().is_none());
+}
+
+#[test]
+fn test_clone() {
+ let e = error();
+ let mut chain = e.chain().clone();
+ assert_eq!("3", chain.next().unwrap().to_string());
+ assert_eq!("2", chain.next().unwrap().to_string());
+ assert_eq!("1", chain.next().unwrap().to_string());
+ assert_eq!("0", chain.next().unwrap().to_string());
+ assert!(chain.next().is_none());
+ assert!(chain.next_back().is_none());
+}