Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
Unit tests (#11)
Browse files Browse the repository at this point in the history
* add some tests
* update GitHub Actions
refered from https://github.com/xd009642/tarpaulin
  • Loading branch information
tamada authored Sep 10, 2021
1 parent c70ec98 commit 5551e7d
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 36 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/build.yaml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Coverage
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run tests
run: cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out Lcov
- name: show current status
run: |
ls -F
cat lcov.info
- name: Upload coverage
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: lcov.info
21 changes: 21 additions & 0 deletions .github/workflows/regression.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Regression

on: [push, pull_request]
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable]

runs-on: ${{ matrix.os }}

steps:
- name: Setup Rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: ${{ matrix.rust }}
- name: Checkout
uses: actions/checkout@v2
- name: Run rust
run: cargo test
22 changes: 22 additions & 0 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,25 @@ pub fn open(
let output = open_output(output)?;
Ok((input, output))
}

mod tests {
use super::*;

#[test]
fn test_input_with_none() {
let input = open_input(None);
assert!(input.is_ok());
}

#[test]
fn test_input_with_minus() {
let input = open_input(Some("-".to_string()));
assert!(input.is_ok());
}

#[test]
fn test_input_with_file() {
let input = open_input(Some("testdata/test1.txt".to_string()));
assert!(input.is_ok());
}
}
71 changes: 71 additions & 0 deletions src/uniqer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,74 @@ impl Uniqer for PlainUniqer {
return Some(line);
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_plain_uniqer() {
let mut uniqer = PlainUniqer {
lines: vec![
"line1".to_string(),
"line2".to_string(),
"line3".to_string(),
],
};
assert!(uniqer.next("line0".to_string()).is_some());
assert!(uniqer.next("line1".to_string()).is_none());
assert!(uniqer.next("line2".to_string()).is_none());
assert!(uniqer.next("line3".to_string()).is_none());
}

#[test]
fn test_adjacent_uniqer() {
let mut uniqer = AdjacentUniqer {
prev: String::new(),
};
assert!(uniqer.next("hogehoge".to_string()).is_some());
assert!(uniqer.next("hogehoge".to_string()).is_none());
assert!(uniqer.next("previous".to_string()).is_some());
assert!(uniqer.next("previous".to_string()).is_none());
}

#[test]
fn test_default_uniqer_with_adjacent_and_ignore_case() {
let mut uniqer = construct_uniqer(true, false, true);
assert!(uniqer.next("hogehoge".to_string()).is_some());
assert!(uniqer.next("HOGEhoge".to_string()).is_none());
assert!(uniqer.next("previous".to_string()).is_some());
assert!(uniqer.next("previous".to_string()).is_none());
assert!(uniqer.next("HOGEhoge".to_string()).is_some());
}

#[test]
fn test_default_uniqer_with_none_adjacent_and_ignore_case() {
let mut uniqer = construct_uniqer(false, false, true);
assert!(uniqer.next("hogehoge".to_string()).is_some());
assert!(uniqer.next("HOGEhoge".to_string()).is_none());
assert!(uniqer.next("previous".to_string()).is_some());
assert!(uniqer.next("previous".to_string()).is_none());
assert!(uniqer.next("HOGEhoge".to_string()).is_none());
}

#[test]
fn test_default_uniqer_with_adjacent_and_ignore_case_delete() {
let mut uniqer = construct_uniqer(true, true, true);
assert!(uniqer.next("hogehoge".to_string()).is_none());
assert!(uniqer.next("HOGEhoge".to_string()).is_some());
assert!(uniqer.next("previous".to_string()).is_none());
assert!(uniqer.next("previous".to_string()).is_some());
assert!(uniqer.next("HOGEhoge".to_string()).is_none());
}

#[test]
fn test_default_uniqer_with_none_adjacent_and_ignore_case_delete() {
let mut uniqer = construct_uniqer(false, true, true);
assert!(uniqer.next("hogehoge".to_string()).is_none());
assert!(uniqer.next("HOGEhoge".to_string()).is_some());
assert!(uniqer.next("previous".to_string()).is_none());
assert!(uniqer.next("previous".to_string()).is_some());
assert!(uniqer.next("HOGEhoge".to_string()).is_some());
}
}

0 comments on commit 5551e7d

Please sign in to comment.