summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-12-20 16:12:43 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-12-20 16:12:43 +0100
commit0e33622304c9c3b49f41c6d81c61176b8f248a7f (patch)
tree9b472dc69dd82290f95485836f62dacd3a16260a
parent67352734864b4387c95de60b4259daf0744263a6 (diff)
add umlauf sanity checker
-rwxr-xr-xbin/sanity-check51
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/sanity-check b/bin/sanity-check
new file mode 100755
index 0000000..3e6957e
--- /dev/null
+++ b/bin/sanity-check
@@ -0,0 +1,51 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use 5.020;
+use utf8;
+
+use File::Slurp qw(read_file);
+use JSON;
+
+sub show_usage {
+ my ($exit_code) = @_;
+
+ say STDERR "Usage: sanity-check <zugbildung.json>";
+
+ exit $exit_code;
+}
+
+binmode( STDOUT, ':encoding(utf-8)' );
+
+if ( @ARGV < 1 ) {
+ show_usage(1);
+}
+
+my ($file) = @ARGV;
+
+my $file_content = read_file($file);
+my $json = JSON->new->utf8->decode($file_content);
+
+my $map = $json->{train};
+
+for my $train_number ( sort { $a <=> $b } keys %{$map} ) {
+ for my $cycle_from ( @{ $map->{$train_number}{cycle}{from} // [] } ) {
+ if ( not exists $map->{$cycle_from} ) {
+ printf(
+ "%s %d references unknown train %d\n",
+ $map->{$train_number}{raw},
+ $train_number, $cycle_from
+ );
+ }
+ }
+ for my $cycle_to ( @{ $map->{$train_number}{cycle}{to} // [] } ) {
+ if ( not exists $map->{$cycle_to} ) {
+ printf(
+ "%s %d references unknown train %d\n",
+ $map->{$train_number}{raw},
+ $train_number, $cycle_to
+ );
+ }
+ }
+}