Skip to content

Commit

Permalink
test: increase coverage test in src/lib.rs (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad authored Apr 15, 2024
1 parent 10cdd41 commit c65d6dd
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,31 @@ env:
jobs:
build:
runs-on: ${{matrix.os}}
env:
DISPLAY: ':99'
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
headless: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &

steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2

with:
# To only cache runs from `master`
save-if: ${{ github.ref == 'refs/heads/main' }}
- if: matrix.os == 'ubuntu-latest'
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libxtst-dev libevdev-dev libxdo-dev
version: 1.0

- name: Setup headless environment
run: ${{matrix.headless}}

- name: Add components
run: rustup component add clippy rustfmt

Expand Down
56 changes: 56 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,59 @@ impl Frontend for Wish {
self.predicates_widget.text(&texts.join("\n"));
}
}

#[cfg(test)]
mod tests {
use crate::{Config, Wish};
use afrim::frontend::Frontend;
use std::path::Path;
use std::thread;
use std::time::Duration;

#[test]
fn test_api() {
let config = Config::from_file(Path::new("data/full_sample.toml")).unwrap();
let mut afrim_wish = Wish::init(config);
afrim_wish.build();

// Test without data.
afrim_wish.clear_predicates();
afrim_wish.next_predicate();
afrim_wish.previous_predicate();
assert!(afrim_wish.get_selected_predicate().is_none());
afrim_wish.display();

// Test the adding of predicates.
afrim_wish.set_page_size(3);
afrim_wish.set_input("Test started!");
afrim_wish.add_predicate("test", "123", "ok");
afrim_wish.add_predicate("test1", "23", "ok");
afrim_wish.add_predicate("test12", "1", "ok");
afrim_wish.add_predicate("test123", "", "ok");
afrim_wish.add_predicate("test1234", "", "");
afrim_wish.display();

// Test the geometry.
(0..100).for_each(|i| {
if i % 10 != 0 {
return;
};
let i = i as f64;
afrim_wish.update_position((i, i));
thread::sleep(Duration::from_millis(100));
});

// Test the navigation.
afrim_wish.previous_predicate();
assert_eq!(
afrim_wish.get_selected_predicate(),
Some(&("test1234".to_owned(), "".to_owned(), "".to_owned()))
);
afrim_wish.next_predicate();
assert_eq!(
afrim_wish.get_selected_predicate(),
Some(&("test".to_owned(), "123".to_owned(), "ok".to_owned()))
);
afrim_wish.display();
}
}

0 comments on commit c65d6dd

Please sign in to comment.