1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::prompt::Prompt;
use std::collections::LinkedList;
pub struct PromptList {
prompts: LinkedList<Prompt>,
}
impl PromptList {
pub fn new() -> PromptList {
PromptList {
prompts: LinkedList::new(),
}
}
pub fn add(mut self, prompt: Prompt) -> Self {
self.prompts.push_back(prompt);
self
}
pub fn next(&mut self) -> Option<Prompt> {
self.prompts.pop_front()
}
}
#[cfg(test)]
mod tests {
use crate::{Prompt, PromptList};
#[test]
fn prompt_list_builder() {
let prompt_list = PromptList::new()
.add(Prompt::new())
.add(Prompt::not_blank());
assert_eq!(prompt_list.prompts.len(), 2);
}
#[test]
fn prompt_list_next() {
let mut prompt_list = PromptList::new()
.add(Prompt::new())
.add(Prompt::not_blank());
assert!(prompt_list.next().is_some());
assert!(prompt_list.next().is_some());
assert!(prompt_list.next().is_none());
}
}