Skip to main content

russy/
lib.rs

1//!# russy
2//!`russy` is a utility crate for adding "ussy" to the end of things.
3//!
4//!## Usage
5//!```rust
6//!use russy::mussy::fussy;
7//!
8//!fn main(){
9//!    let rust = "rust".to_string();
10//!    assert_eq!("russy", fussy(&rust));
11//!}
12//!```
13//!
14//!## Limitations
15//!
16//!Only works with Roman alphanumeric characters.
17//!
18//!## License
19//!
20//!This project is licensed under [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
21use std::io::BufRead;
22use std::{fs::File, io, path::Path};
23pub mod mussy;
24
25// The output is wrapped in a Result to allow matching on errors
26// Returns an Iterator to the Reader of the lines of the file.
27#[allow(unused)]
28pub(crate) fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
29where
30    P: AsRef<Path>,
31{
32    let file = File::open(filename)?;
33    Ok(io::BufReader::new(file).lines())
34}
35
36#[cfg(test)]
37mod tests {
38    use crate::mussy::fussy;
39    use crate::read_lines;
40
41    #[test]
42    fn tested_words() {
43        let lines = read_lines("test_words.txt").unwrap();
44
45        let expected_results = lines
46            .map(|x| {
47                let x = x.unwrap();
48                let index = x.find("-").unwrap();
49                (x[..index].to_string(), x[index + 1..].to_string())
50            })
51            .collect::<Vec<(String, String)>>();
52
53        expected_results
54            .iter()
55            .for_each(|x| assert_eq!(x.1, fussy(&x.0)));
56    }
57}