mirror of
https://github.com/Tribufu/rust-gamedig
synced 2026-08-10 07:31:07 +00:00
feat: Move ID tests into their own crate with a CLI (#177)
* fix: ID tests not in correct directory * refactor: Move game-id test logic into its own crate * id-tests: Add CLI that reads JSON input * id-tests: Update crate docs * Remove node ID test * id-tests: Don't try to parse unneeded info * id-tests: Enable cli feature by default
This commit is contained in:
parent
88bf996a5e
commit
b248a7661e
7 changed files with 144 additions and 113 deletions
31
crates/id-tests/src/main.rs
Normal file
31
crates/id-tests/src/main.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#![cfg(feature = "cli")]
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Format for input games (the same as used in node-gamedig/lib/games.js).
|
||||
type GamesInput = HashMap<String, Game>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
|
||||
struct Game {
|
||||
name: String,
|
||||
}
|
||||
|
||||
use gamedig_id_tests::test_game_name_rules;
|
||||
|
||||
fn main() {
|
||||
let games: GamesInput = if let Some(file) = std::env::args_os().skip(1).next() {
|
||||
let file = std::fs::OpenOptions::new().read(true).open(file).unwrap();
|
||||
|
||||
serde_json::from_reader(file).unwrap()
|
||||
} else {
|
||||
serde_json::from_reader(std::io::stdin().lock()).unwrap()
|
||||
};
|
||||
|
||||
let failed = test_game_name_rules(
|
||||
games
|
||||
.iter()
|
||||
.map(|(key, game)| (key.as_str(), game.name.as_str())),
|
||||
);
|
||||
|
||||
assert!(failed.is_empty());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue