test_fill_gaps_in_sectioning.t 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. use strict;
  2. BEGIN {
  3. require Texinfo::ModulePath;
  4. Texinfo::ModulePath::init(undef, undef, 'updirs' => 2);
  5. }
  6. use Test::More;
  7. BEGIN { plan tests => 8; }
  8. use Texinfo::Transformations;
  9. use Texinfo::Parser qw(parse_texi_text);
  10. use Texinfo::Convert::Texinfo;
  11. ok(1, "modules loading");
  12. my $tree = parse_texi_text(undef, '@raisesections
  13. @section truc
  14. ');
  15. my $section = $tree->{'contents'}->[1];
  16. my @correct_level_offset_commands
  17. = Texinfo::Transformations::_correct_level($section, $tree->{'contents'}->[0]);
  18. # 2 because there is also an empty line
  19. ok (scalar(@correct_level_offset_commands) == 2,"one lowersection");
  20. ok ($correct_level_offset_commands[0]->{'cmdname'} eq 'lowersection' ,
  21. "command is lowersection");
  22. $tree = parse_texi_text(undef, '@lowersections
  23. @lowersections
  24. @chapter truc
  25. ');
  26. $section = $tree->{'contents'}->[1];
  27. @correct_level_offset_commands
  28. = Texinfo::Transformations::_correct_level($section, $tree->{'contents'}->[0], -1);
  29. ok (scalar(@correct_level_offset_commands) == 4,"two lowersection");
  30. ok ($correct_level_offset_commands[0]->{'cmdname'} eq 'lowersection' ,
  31. "command is lowersection");
  32. sub test_correction($$$)
  33. {
  34. my $in = shift;
  35. my $out = shift;
  36. my $name = shift;
  37. my $tree = parse_texi_text(undef, $in);
  38. my ($corrected_content, $added_sections)
  39. = Texinfo::Transformations::fill_gaps_in_sectioning($tree);
  40. $tree->{'contents'} = $corrected_content;
  41. {
  42. local $Data::Dumper::Purity = 1;
  43. #local $Data::Dumper::Maxdepth = 2;
  44. local $Data::Dumper::Indent = 1;
  45. #print STDERR Data::Dumper->Dump([$tree]);
  46. #print STDERR Data::Dumper->Dump([$corrected_content]);
  47. }
  48. my $texi_result = Texinfo::Convert::Texinfo::convert({'contents' => $corrected_content});
  49. if (!defined($out)) {
  50. print STDERR " --> $name:\n$texi_result";
  51. } else {
  52. is($texi_result, $out, $name);
  53. }
  54. }
  55. test_correction('@chapter chap
  56. @subsection sub
  57. ','@chapter chap
  58. @unnumberedsec @asis{}
  59. @subsection sub
  60. ', 'simple completed tree');
  61. my $raisesections_lowersection_no_correction_text = '@raisesections
  62. @section sec
  63. @lowersections
  64. @lowersections
  65. @chapter chap
  66. ';
  67. test_correction($raisesections_lowersection_no_correction_text,
  68. $raisesections_lowersection_no_correction_text,
  69. 'raisesections and lowersection, no correction');
  70. test_correction('@raisesections
  71. @section sec
  72. @lowersections
  73. @lowersections
  74. @lowersections
  75. @chapter chap
  76. ', '@raisesections
  77. @section sec
  78. @lowersections
  79. @lowersections
  80. @lowersections
  81. @raisesection
  82. @raisesection
  83. @unnumberedsec @asis{}
  84. @lowersection
  85. @lowersection
  86. @chapter chap
  87. ', 'raisesections lowersection with correction');