mirror of
https://github.com/Tribufu/rust-gamedig
synced 2026-08-09 23:21:06 +00:00
* 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
31 lines
805 B
Rust
31 lines
805 B
Rust
#![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());
|
|
}
|