Refactor UI trait, add fake ui
Dependencies
- [2]
3VVQWLOXMajor refactor: modularisation - [3]
FZIABKEVNew tests, refactor to be more modular, improve prompt ui, add test run parameter - [4]
WGRFJRTEAdd tests, rename Status to Header, implement redirect and proper input handling - [*]
DBKKKHC2Initial commit
Change contents
- edit in src/main.rs at line 14
/// Represents a user interface - replacement in src/main.rs at line 16
fn show(&self, content: media::Media);fn warn<D: Display>(&self, warning: D);fn read(&self, prompt: impl Display) -> Option<String>;fn read_secret(&self, prompt: impl Display) -> Option<String>;/// Render a page to the screenfn show(&mut self, content: media::Media);/// Display a warningfn warn<D: Display>(&mut self, warning: D);/// Display a prompt and read input from the userfn read(&mut self, prompt: impl Display) -> Option<String>;/// Display a prompt and read hidden input from the userfn read_secret(&mut self, prompt: impl Display) -> Option<String>; - edit in src/main.rs at line 25
impl Ui for () {fn show(&self, _content: media::Media) {} - replacement in src/main.rs at line 26[3.501]→[2.1262:1309](∅→∅),[2.1309]→[3.761:762](∅→∅),[3.761]→[3.761:762](∅→∅),[3.762]→[2.1310:1372](∅→∅)
fn warn<D: Display>(&self, _warning: D) {}fn read(&self, _prompt: impl Display) -> Option<String> {/// User interface that does nothingpub struct NopUi;impl Ui for NopUi {fn show(&mut self, _content: media::Media) {}fn warn<D: Display>(&mut self, _warning: D) {}fn read(&mut self, _prompt: impl Display) -> Option<String> { - edit in src/main.rs at line 34
fn read_secret(&mut self, _prompt: impl Display) -> Option<String> {None}} - replacement in src/main.rs at line 39
fn read_secret(&self, _prompt: impl Display) -> Option<String> {None/// User interface that records method calls and returns canned inputs#[cfg(test)]#[derive(Default)]struct FakeUi {inputs: Vec<String>,events: Vec<FUIEvent>,}#[cfg(test)]enum FUIEvent {//TODO figure out how to solve lifetime issues// and store Media in this variant// Or just convert it to a string? idkShow,Warn(String),Read(String),ReadSecret(String),}#[cfg(test)]impl FakeUi {pub fn new() -> Self {Default::default()}}#[cfg(test)]impl Ui for FakeUi {fn show(&mut self, _content: media::Media) {self.events.push(FUIEvent::Show)}fn warn<D: Display>(&mut self, warning: D) {self.events.push(FUIEvent::Warn(warning.to_string()))}fn read(&mut self, prompt: impl Display) -> Option<String> {self.events.push(FUIEvent::Read(prompt.to_string()));self.inputs.pop()}fn read_secret(&mut self, prompt: impl Display) -> Option<String> {self.events.push(FUIEvent::ReadSecret(prompt.to_string()));self.inputs.pop() - edit in src/main.rs at line 103
use crate::NopUi; - replacement in src/main.rs at line 109
crate::core::run_url::<crate::network::TcpNetwork<crate::danger::Naive>>(&mut crate::cli::Cli {},url,);crate::core::run_url::<crate::network::TcpNetwork<crate::danger::Naive>>(&mut NopUi, url); - replacement in src/core.rs at line 129
pub fn read_response_header(ui: &impl Ui, mut stream: impl Read) -> ioResult<response::Header> {pub fn read_response_header(ui: &mut impl Ui, mut stream: impl Read) -> ioResult<response::Header> { - replacement in src/core.rs at line 212
let head = read_response_header(&(), &mut &*resp_head).expect("failed to read response");let head = read_response_header(&mut crate::NopUi, &mut &*resp_head).expect("failed to read response"); - replacement in src/cli.rs at line 32
test_run(&cli);test_run(&mut cli); - replacement in src/cli.rs at line 45
fn test_run(cli: &Cli) {fn test_run(cli: &mut Cli) { - replacement in src/cli.rs at line 139
fn show(&self, content: Media) {fn show(&mut self, content: Media) { - replacement in src/cli.rs at line 146
fn read(&self, prompt: impl Display) -> Option<String> {fn read(&mut self, prompt: impl Display) -> Option<String> { - replacement in src/cli.rs at line 157
fn read_secret(&self, prompt: impl Display) -> Option<String> {fn read_secret(&mut self, prompt: impl Display) -> Option<String> { - replacement in src/cli.rs at line 174
fn warn<D: std::fmt::Display>(&self, warning: D) {fn warn<D: std::fmt::Display>(&mut self, warning: D) {