]> piware.de Git - learn-rust.git/blobdiff - concepts/src/main.rs
concepts: require two Post approvals
[learn-rust.git] / concepts / src / main.rs
index 94bdb960aa7e79b80d4ad22f082ab2822e6c1fbc..20826216bbd4c0ec5a0e8e3cec408f507b28140b 100644 (file)
@@ -247,6 +247,31 @@ fn test_threads() {
     println!("counter: {}", *counter.lock().unwrap());
 }
 
+fn test_dyn_traits() {
+    let text = "I ate a salad for lunch today";
+    let mut post = Post::new();
+    post.add_text(text);
+    assert_eq!("", post.content());
+
+    post.request_review();
+    assert_eq!("", post.content());
+
+    post.reject();
+    assert_eq!("", post.content());
+
+    post.request_review();
+    assert_eq!("", post.content());
+
+    post.approve();  // first
+    assert_eq!("", post.content());
+
+    post.approve();  // second
+    assert_eq!(text, post.content());
+
+    post.reject();  // no-op
+    assert_eq!(text, post.content());
+}
+
 fn main() {
     test_strings();
     test_vectors();
@@ -256,4 +281,5 @@ fn main() {
     test_closures();
     test_iterators();
     test_threads();
+    test_dyn_traits();
 }