Lithuanian: fix docstrings and remove duplicate code.
[docutils.git] / prest / tbin / extract_tests
blob28967337bb4f98125d0f07841d8f86cca956b1bd
1 #!/usr/local/bin/perl
3 # Pulls the tests out of a python test file.
4 # Usage: make_tests test_xxx.py
6 die "Must specify a file name" if $ARGV[0] eq '';
8 if (-f 'ExtractTests.pm') {
9 eval "use ExtractTests";
10 die $@ if $@;
13 $ARGV[0] =~ /test_(.*)\.py/;
14 $outfile_base = "$1";
15 $counter = "00";
16 $suffix = ".dom";
17 $string = "";
18 while (<>) {
19 next if 1 .. /generateTests/;
20 next if /^\#/ && ! $in_string;
21 if ($in_string) {
22 if (/^\"\"\"(?: \% (.*?)\s*|\]?,\s*(?:\#.*)?)$/) {
23 my $vars = $VARS{"$counter$suffix"} || $1;
24 $vars =~ s/\]?,$//;
25 $vars =~ s/\b(\w+)\b/defined $DEFS{$1} ? "q($DEFS{$1})" : $1/ge;
26 my @args = eval($vars);
27 # string =~ s/\\\n//g;
28 printf FILE $string,@args;
29 close FILE;
30 $in_string = 0;
31 $string = "";
32 next;
34 s/\\n\\$//;# if $suffix eq ".rst";
35 s/\\([\\\'\"])/$1/g unless $string_type =~ /r/;
36 s/\"\"\"\s*\+\s*\"\"\"//g;
37 $string .= $_;
39 elsif (/^\[?\(?([ru])?\"\"\"(.*)?$/) {
40 $in_string = 1;
41 $string_type = $1;
42 $suffix = $suffix eq ".dom" ? ".rst" : ".dom";
43 $counter++ if $suffix eq ".rst";
44 $file = "$outfile_base$counter$suffix";
45 open(FILE, ">$file") or die "Cannot write to $file";
46 $string = "$2\n";
47 $string =~ s/\\\n//g;
48 next;