Skip to content

Commit

Permalink
Added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pomettini committed Jul 29, 2019
1 parent e84f7e4 commit d37619d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "instagen"
version = "0.1.0"
version = "0.1.1"
authors = ["Giorgio Pomettini <giorgio.pomettini@gmail.com>"]
edition = "2018"
description = "Library and cli app to generate hashtags for Instagram"
Expand All @@ -14,4 +14,9 @@ readme = "readme.md"
clap = ">=2.33"
reqwest = ">=0.9.18"
serde = ">=1.0.97"
assert_cmd = ">=0.11.1"
assert_cmd = ">=0.11.1"
maplit = ">=1.0.1"

[badges]
appveyor = { repository = "Pomettini/instagen" }
travis-ci = { repository = "Pomettini/instagen" }
4 changes: 3 additions & 1 deletion README.md
@@ -1,9 +1,11 @@
# instagen

馃 Library and cli app to generate hashtags for [Instagram](https://www.instagram.com/)

[![Build Status](https://travis-ci.org/Pomettini/instagen.svg?branch=master)](https://travis-ci.org/Pomettini/instagen)
[![Build status](https://ci.appveyor.com/api/projects/status/3ogbcgxfdecn3pk5?svg=true)](https://ci.appveyor.com/project/Pomettini/instagen)
[![Coverage Status](https://coveralls.io/repos/github/Pomettini/instagen/badge.svg)](https://coveralls.io/github/Pomettini/instagen)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Usage

Expand All @@ -21,4 +23,4 @@ It will generate this output:

I'm still working on it! It might be useful someday 馃

This app uses [datamuse](https://www.datamuse.com) and their great [APIs](https://www.datamuse.com/api/) 鉂わ笍
This app uses [datamuse](https://www.datamuse.com) and their great [APIs](https://www.datamuse.com/api/) 鉂わ笍
2 changes: 2 additions & 0 deletions src/bin/instagen.rs
Expand Up @@ -23,7 +23,9 @@ fn main() {
}

mod tests {
#[allow(unused_imports)]
use assert_cmd::prelude::*;
#[allow(unused_imports)]
use std::process::Command;

#[test]
Expand Down
74 changes: 74 additions & 0 deletions src/lib.rs
@@ -1,4 +1,6 @@
extern crate reqwest;
#[macro_use]
extern crate maplit;

use serde::*;
use std::collections::HashSet;
Expand Down Expand Up @@ -74,4 +76,76 @@ impl Instagen {
.map(|hashtag| format!("#{} ", hashtag.replace(" ", "")))
.collect::<String>()
}

pub fn to_hashset(self) -> HashSet<String> {
self.output_tags
}
}

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

#[test]
fn test_load_sample_tags() {
let result = Instagen::generate(vec!["sweden", "summer", "sea"]);

assert_eq!(
result.output_tags,
hashset! {String::from("sweden"), String::from("sverige"), String::from("ocean"), String::from("summertime"), String::from("sea"), String::from("summer")}
);
}

#[test]
fn test_load_sample_tags_red() {
let result = Instagen::generate(vec!["sweden", "summer", "sea"]);

assert_ne!(result.output_tags, hashset! {String::from("italy")});
}

#[test]
fn test_load_empty() {
let result = Instagen::generate(vec![""]);

assert_eq!(result.output_tags, hashset! {String::from("")});
}

#[test]
fn test_load_empty_red() {
let result = Instagen::generate(vec![""]);

assert_ne!(result.output_tags, hashset! {String::from("italy")});
}

#[test]
fn test_load_sample_tags_return_hashset() {
let result = Instagen::generate(vec!["cow"]).to_hashset();

assert_eq!(
result,
hashset! {String::from("cow"), String::from("overawe"), String::from("moo-cow")}
);
}

#[test]
fn test_load_sample_tags_return_hashset_red() {
let result = Instagen::generate(vec!["cow"]).to_hashset();

assert_ne!(result, hashset! {String::from("dog")});
}

#[test]
fn test_load_sample_tags_return_hashtags() {
let result = Instagen::generate(vec!["kitten"]).to_hashtags();

assert!(result.contains("#kitty"));
}

#[test]
fn test_load_sample_tags_return_hashtags_red() {
let result = Instagen::generate(vec!["kitten"]).to_hashtags();

assert!(!result.contains("#italy"));
}
}

0 comments on commit d37619d

Please sign in to comment.