diff options
author | Nao Pross <np@0hm.ch> | 2021-03-10 00:17:44 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2021-03-10 00:17:44 +0100 |
commit | 089c649ee3e9b219ff90d88a2aad95e730507410 (patch) | |
tree | b67e332d013f97efd83d9bf74626a6b999758c95 /src | |
parent | Update .gitignore (diff) | |
download | testbench-ui-089c649ee3e9b219ff90d88a2aad95e730507410.tar.gz testbench-ui-089c649ee3e9b219ff90d88a2aad95e730507410.zip |
Create tests windows
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 11 | ||||
-rw-r--r-- | src/testbench.rs | 100 |
2 files changed, 108 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index df1a475..9e7d545 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use imgui::*; use rlua::{Lua, MultiValue}; mod support; +mod testbench; #[derive(Default)] struct State { @@ -21,7 +22,9 @@ impl State { } fn draw_console(_run: &mut bool, ui: &mut Ui, state: &mut State) { - let win = Window::new(im_str!("Lua Console")).size([400., 500.], Condition::Appearing); + let win = Window::new(im_str!("Lua Console")) + .size([400., 500.], Condition::Appearing) + .position([440., 20.], Condition::Appearing); win.build(&ui, || { ChildWindow::new("console") @@ -35,7 +38,7 @@ fn draw_console(_run: &mut bool, ui: &mut Ui, state: &mut State) { ui.separator(); ui.input_text(im_str!("Lua"), &mut state.repl_input).build(); - ui.same_line(350.); + ui.same_line(0.); if ui.button(im_str!("Eval"), [0., 0.]) { let input = state.repl_input.to_str().clone(); let mut new_text = String::new(); @@ -67,9 +70,11 @@ fn draw_console(_run: &mut bool, ui: &mut Ui, state: &mut State) { fn main() { let system = support::init(file!()); let mut state = State::new(); + let mut bench = testbench::Bench::new(); system.main_loop(move |run, ui| { - ui.show_demo_window(run); + // ui.show_demo_window(run); + bench.draw(run, ui); draw_console(run, ui, &mut state); }); } diff --git a/src/testbench.rs b/src/testbench.rs new file mode 100644 index 0000000..ed0a2c1 --- /dev/null +++ b/src/testbench.rs @@ -0,0 +1,100 @@ +use std::fs; +use std::io; +use std::option::Option; +use std::path::{Path, PathBuf}; +use std::ffi::OsStr; + +use imgui; +use rlua::Lua; + +#[derive(Default, PartialEq)] +pub struct Test { + pub path: PathBuf, +} + +#[derive(Default)] +pub struct Bench { + lua: Lua, + tests: Vec<Test>, + selected_test: Option<usize>, +} + +impl Bench { + pub fn new() -> Bench { + let mut b = Bench { + lua: Lua::new(), + tests: Vec::new(), + selected_test: None, + }; + + // TODO: set graphically and use RV + b.load_tests("lua"); + + return b; + } + + pub fn load_tests<P>(&mut self, path: P) -> io::Result<()> + where + P: AsRef<Path>, + { + let entries: Result<Vec<PathBuf>, io::Error> = fs::read_dir(path)? + .into_iter() + .map(|r| r.map(|f| f.path())) + .collect(); + + match entries { + Ok(files) => { + self.tests = files + .into_iter() + .filter(|f| f.is_file()) + .filter(|f| f.extension().unwrap_or(OsStr::new("")) == "lua") + .map(|f| Test { path: f }) + .collect(); + + return Ok(()); + } + Err(e) => return Err(e), + } + } + + pub fn draw(&mut self, _: &mut bool, ui: &mut imgui::Ui) { + use imgui::*; + + let win = Window::new(im_str!("Testbench")) + .size([400., 500.], Condition::Appearing) + .position([20., 20.], Condition::Appearing); + + win.build(&ui, || { + for (index, test) in self.tests.iter().enumerate() { + if let Some(test_name) = test.path.to_str() { + let test_name: ImString = test_name.to_string().into(); + let selected = matches!(self.selected_test, Some(i) if i == index); + + if Selectable::new(&test_name).selected(selected).build(ui) { + self.selected_test = Some(index) + } + } + } + + ui.separator(); + if let Some(index) = self.selected_test { + if let Some(test_name) = self.tests[index].path.to_str() { + let imstr: ImString = + format!("Selected Test: {}", test_name).to_string().into(); + ui.text_wrapped(&imstr); + ui.same_line(0.); + if ui.button(im_str!("Run"), [0., 0.]) { + } + ui.same_line(0.); + if ui.button(im_str!("Show"), [0., 0.]) {} + } + } + }); + } + + fn run_test(&self, index: usize) { + self.lua.context(|context| { + + }); + } +} |