From f2ae43e85f636cec4c9cf46a885f6614c4a9cf2a Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 26 Jul 2020 12:36:29 +0100 Subject: [PATCH] add bitsy-parse executable for independent testing of import/export --- src/bin/bitsy-parse.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/bitsy-parse.rs diff --git a/src/bin/bitsy-parse.rs b/src/bin/bitsy-parse.rs new file mode 100644 index 0000000..06118d2 --- /dev/null +++ b/src/bin/bitsy-parse.rs @@ -0,0 +1,15 @@ +extern crate bitsy_parser; +use bitsy_parser::game::Game; +use std::{env, fs}; + +const SYNTAX_ERROR: &str = "Usage: `bitsy-parse input.bitsy output.bitsy`"; + +/// simply parses and re-exports a game. use to test whether output matches input. +fn main() { + let input = env::args().nth(1).expect(SYNTAX_ERROR); + let output = env::args().nth(2).expect(SYNTAX_ERROR); + + let game = Game::from(fs::read_to_string(input).unwrap()).unwrap(); + + fs::write(output, game.to_string()).expect("Failed to write output file"); +}