Commit b0eb2aa4 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add some actual parser tests

parent d2f853a9
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ my $walk_speed;
my $with_bike;
my $debug = 0;
my $ignore_info = 'Fahrradmitnahme';
my ($test_dump, $test_parse);

sub check_ambiguous {
	my $html = shift;
@@ -217,6 +218,8 @@ GetOptions(
	'P|prefer=s'     => \$prefer,
	'p|proximity'    => \$proximity,
	'i|include=s'    => \$include,
	'test-dump'      => \$test_dump,
	'test-parse'     => \$test_parse,
	't|time=s'       => \$time,
	'to=s{2}'        => \@to,
	'to-type=s'      => \$to_type,
@@ -288,7 +291,7 @@ if ($time) {
	@post{'itdTimeHour', 'itdTimeMinute'} = split(/:/, $time);
}
if ($date) {
	if ($date !~ /^ [0-3]? \d \. [01]? \d (?: \. \d{4} )? $/x) {
	if ($date !~ /^ [0-3]? \d \. [01]? \d \. (?: \d{4} )? $/x) {
		die("Invalid argument: Usage: --date DD.MM[.YYYY]\n");
	}
	@post{'itdDateDay', 'itdDateMonth', 'itdDateYear'} = split(/\./, $date);
@@ -361,6 +364,11 @@ if ($with_bike) {
	$post{bikeTakeAlong} = 1;
}

if ($test_parse) {
	local $/;
	$content = <STDIN>;
}
else {
	$www->get($firsturl);
	$www->submit_form(
		form_name => 'jp',
@@ -370,6 +378,12 @@ $www->submit_form(
	$content = $www->content;
	$content =~ s/\xa0/ /gs;
	$content = decode('iso-8859-1', $content);
}

if ($test_dump) {
	print $content;
	exit 0
}

if (check_ambiguous($content)) {
	exit 1;
+11 −1
Original line number Diff line number Diff line
@@ -2,10 +2,11 @@
use strict;
use warnings;
use 5.010;
use Test::Command tests => 51;
use Test::Command tests => 57;

my $efa     = 'bin/efa';
my $testarg = "E HBf MH HBf";
my $test_parse = "--test-parse $testarg";

my $re_usage = qr{Insufficient to/from arguments, see \S*efa --help for usage};
my $re_version = qr{\S*efa version \S+};
@@ -93,3 +94,12 @@ for my $opt (qw/-v --version/) {
	$cmd->stdout_like($re_version);
	$cmd->stderr_is_eq('');
}


for my $file (qw/e_hbf_mh_hbf e_hbf_du_hbf.ice/) {
	$cmd = Test::Command->new(cmd => "$efa $test_parse < test/dump_$file");

	$cmd->exit_is_num(0);
	$cmd->stdout_is_file("test/parse_$file");
	$cmd->stderr_is_eq('');
}
+545 −0

File added.

Preview size limit exceeded, changes collapsed.

test/dump_e_hbf_mh_hbf

0 → 100644
+525 −0

File added.

Preview size limit exceeded, changes collapsed.

+14 −0
Original line number Diff line number Diff line
17:15 ab  Essen Hauptbahnhof: Gleis 7    S-Bahn S1            Solingen Hbf
17:33 an  Duisburg Hbf: Gleis 5         

------

# 2 Min. später, Plan: ab 17:32
17:34 ab  Essen Hauptbahnhof: Gleis 2    R-Bahn RE6           Düsseldorf Hbf
17:46 an  Duisburg Hbf: Gleis 5         

------

17:41 ab  Essen Hauptbahnhof: Gleis 2    IC 2150 InterCity    Düsseldorf Hbf
17:53 an  Duisburg Hbf: Gleis 2         
Loading