Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase coverage test in src/lib.rs #62

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading