dtee 0.0.6

Decision table editor engine
Documentation
use super::*;
use dtee::Controller;

/// Decision table is fully visible.
/// Viewport is not moved.
#[test]
fn _0001() {
  let expected = r#"
    ╭───────────────────────────────────────────────────────────────────────────╮
    │┌─────────────────┐░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    ││  Order options  │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │├───┬───────────┬─┴─────╥─────────────────────╥─────────────┬───────────┐░░│
    ││ U │           │       ║    Order options    ║             │           │░░│
    ││   │ Customer  │ Order ╟──────────┬──────────╢ Description │ Reference │░░│
    ││   │   type    │ size  ║ Discount │ Priority ║             │           │░░│
    ││   ├───────────┼───────╫──────────┼──────────╫─────────────┼───────────┤░░│
    ││   │"Business",│       ║          │"Normal", ║             │           │░░│
    ││   │"Private"  │       ║          │ "High",  ║             │           │░░│
    ││   │           │       ║          │ "Low"    ║             │           │░░│
    │╞═══╪═══════════╪═══════╬══════════╪══════════╬═════════════╪═══════════╡░░│
    ││ 1 │"Business" │  <10  ║   0.10   │ "Normal" ║ Small order │   Ref 1   │░░│
    │├───┼───────────┼───────╫──────────┼──────────╫─────────────┼───────────┤░░│
    ││ 2 │"Business" │ >=10  ║   0.15   │  "High"  ║ Large order │   Ref 2   │░░│
    │├───┼───────────┼───────╫──────────┼──────────╫─────────────┼───────────┤░░│
    ││ 3 │"Private"  │   -   ║   0.05   │  "Low"   ║ All orders  │   Ref 3   │░░│
    │└───┴───────────┴───────╨──────────┴──────────╨─────────────┴───────────┘░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    ╰───────────────────────────────────────────────────────────────────────────╯
  "#;
  let controller = Controller::new(INPUT_0002).with_viewport(75, 19);
  assert_eq!(expected, view(&controller));
}

/// Moving cursor down should shift the visible content up.
/// The viewport is shifted down relative to the content.
#[test]
fn _0002() {
  let expected = r#"
    ╭─────────────────────────────────────────────────────────────────────╮
    ││ U │           │       ║    Order options    ║             │        │
    ││   │ Customer  │ Order ╟──────────┬──────────╢ Description │ Referen│
    ││   │   type    │ size  ║ Discount │ Priority ║             │        │
    ││   ├───────────┼───────╫──────────┼──────────╫─────────────┼────────│
    ││   │"Business",│       ║          │"Normal", ║             │        │
    ││   │"Private"  │       ║          │ "High",  ║             │        │
    ││   │           │       ║          │ "Low"    ║             │        │
    │╞═══╪═══════════╪═══════╬══════════╪══════════╬═════════════╪════════│
    ││ 1 │"Business" │  <10  ║   0.10   │ "Normal" ║ Small order │   Ref 1│
    │├───┼───────────┼───────╫──────────┼──────────╫─────────────┼────────│
    ││ 2 │"Business" │ >=10  ║   0.15   │  "High"  ║ Large order │   Ref 2│
    │├───┼───────────┼───────╫──────────┼──────────╫─────────────┼────────│
    ││ 3 │"Private"  │   -   ║   0.05   │  "Low"   ║ All orders  │   Ref 3│
    │└───┴───────────┴───────╨──────────┴──────────╨─────────────┴────────│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    ╰─────────────────────────────────────────────────────────────────────╯
  "#;
  let mut controller = Controller::new(INPUT_0002).with_viewport(69, 15);
  assert_eq!("(0, 0, 69, 15)", controller.viewport().to_string());
  assert_eq!("(0, 0, 73, 17)", controller.content_region().to_string());
  actions(&mut controller, &[MoveDown(9), AssertPos(1, 13)]);
  assert_eq!("(0, 1, 69, 15)", controller.viewport().to_string());
  assert_eq!((1, 13), controller.cursor().pos());
  actions(&mut controller, &[MoveDown(1)]);
  assert_eq!("(0, 3, 69, 15)", controller.viewport().to_string());
  assert_eq!(expected, view(&controller));
}

#[test]
fn _0003() {
  let expected = r#"
    ╭──────────────────────────────╮
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │─╥─────────────┬───────────┐░░│
    │ ║             │           │░░│
    │─╢ Description │ Reference │░░│
    │ ║             │           │░░│
    │─╫─────────────┼───────────┤░░│
    │ ║             │           │░░│
    │ ║             │           │░░│
    │ ║             │           │░░│
    │═╬═════════════╪═══════════╡░░│
    │ ║ Small order │   Ref 1   │░░│
    │─╫─────────────┼───────────┤░░│
    │ ║ Large order │   Ref 2   │░░│
    │─╫─────────────┼───────────┤░░│
    │ ║ All orders  │   Ref 3   │░░│
    │─╨─────────────┴───────────┘░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    ╰──────────────────────────────╯
  "#;
  let mut controller = Controller::new(INPUT_0002).with_viewport(30, 19);
  actions(&mut controller, &[MoveDown(1), RowEnd(1)]);
  assert_eq!(expected, view(&controller));
}

#[test]
fn _0004() {
  let expected = r#"
    ╭──────────────────────────────╮
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │───────────┬───────────────┐░░│
    │           │           aaaa│░░│
    │escription │ Reference     │░░│
    │           │               │░░│
    │───────────┼───────────────┤░░│
    │           │               │░░│
    │           │               │░░│
    │           │               │░░│
    │═══════════╪═══════════════╡░░│
    │mall order │   Ref 1       │░░│
    │───────────┼───────────────┤░░│
    │arge order │   Ref 2       │░░│
    │───────────┼───────────────┤░░│
    │ll orders  │   Ref 3       │░░│
    │───────────┴───────────────┘░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    ╰──────────────────────────────╯
  "#;
  let mut controller = Controller::new(INPUT_0002).with_viewport(30, 19);
  actions(&mut controller, &[MoveDown(1), RowEnd(1), Insert('a', 4)]);
  assert_eq!(expected, view(&controller));
}

#[test]
fn _0005() {
  let expected = r#"
    ╭──────────────────────────────╮
    │┌─────────────────┐░░░░░░░░░░░│
    ││  Order options  │░░░░░░░░░░░│
    │├──────┬──────────┴┬───────╥──│
    ││aaaa U│           │       ║  │
    ││      │ Customer  │ Order ╟──│
    ││      │   type    │ size  ║ D│
    ││      ├───────────┼───────╫──│
    ││      │"Business",│       ║  │
    ││      │"Private"  │       ║  │
    ││      │           │       ║  │
    │╞══════╪═══════════╪═══════╬══│
    ││ 1    │"Business" │  <10  ║  │
    │├──────┼───────────┼───────╫──│
    ││ 2    │"Business" │ >=10  ║  │
    │├──────┼───────────┼───────╫──│
    ││ 3    │"Private"  │   -   ║  │
    │└──────┴───────────┴───────╨──│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
    ╰──────────────────────────────╯
  "#;
  let mut controller = Controller::new(INPUT_0002).with_viewport(30, 19);
  actions(&mut controller, &[MoveDown(1), Insert('a', 4)]);
  assert_eq!(expected, view(&controller));
}