lyx_mirror/development/autotests/beginEndStructureCheck.pl
Kornel Benko d0d45d4043 Cmake export tests: Add structue test for exported lyx files
We test here, if any \end_{somethig} matches \begin_{something}.
Exeptions are \end_index and \end_branch ATM, they should
match \index and \branch respectively.

Also added new testfile.
2015-12-27 14:33:11 +01:00

42 lines
842 B
Perl
Executable File

#! /usr/bin/env perl
# -*- mode: perl; -*-
use strict;
my @stack = ();
my $depth = 0;
my $input = $ARGV[0];
my $line = 0;
if (open(FI, $input)) {
while (my $l = <FI>) {
chomp($l);
$line++;
if ($l =~ /^\s*\\begin_([a-z]+)/) {
$stack[$depth] = $1;
$depth++;
}
elsif ($l =~ /^\s*\\(index|branch)\s/) {
# does not start with e.g. \begin_index, but ends with \end_index!!
$stack[$depth] = $1;
$depth++;
}
elsif ($l =~ /^\s*\\end_([a-z]+)/) {
my $expect = $1;
if ($depth > 0) {
if ($stack[$depth-1] eq $expect) {
$depth--;
}
else {
print "expected \\end_$stack[$depth-1], got \\end_$expect instead at $input:$line\n";
exit(-1);
}
}
else {
print "got \\end_$expect, but depth is already 0 at $input:$line\n";
exit(-2);
}
}
}
}
exit(0);