test_protect_hashchar_at_line_beginning.t 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 => 6; }
  8. use Texinfo::Parser qw(parse_texi_text);
  9. use Texinfo::Common qw(protect_hashchar_at_line_beginning);
  10. use Texinfo::Convert::Texinfo;
  11. use Data::Dumper;
  12. ok(1);
  13. sub run_test($$$;$)
  14. {
  15. my $in = shift;
  16. my $out = shift;
  17. my $name = shift;
  18. my $error_message = shift;
  19. my $parser = Texinfo::Parser::parser();
  20. my $tree = $parser->parse_texi_text($in, 1);
  21. my $corrected_tree =
  22. $parser->Texinfo::Common::protect_hashchar_at_line_beginning($tree);
  23. if (defined($error_message)) {
  24. my ($errors, $errors_count) = $parser->errors();
  25. if (!$error_message) {
  26. if ($errors and scalar(@$errors)) {
  27. print STDERR " --error-> $errors->[0]->{'error_line'}";
  28. } else {
  29. print STDERR "No message\n";
  30. }
  31. } else {
  32. if ($errors and scalar(@$errors)) {
  33. is($error_message, $errors->[0]->{'error_line'}, "error message: $name");
  34. } else {
  35. ok(0, "error message: $name");
  36. }
  37. }
  38. }
  39. my $texi_result = Texinfo::Convert::Texinfo::convert($corrected_tree);
  40. if (!defined($out)) {
  41. print STDERR " --> $name:\n$texi_result";
  42. } else {
  43. is ($texi_result, $out, $name);
  44. }
  45. }
  46. run_test ('# line 4 "ggggg"
  47. and
  48. # line 5 "fff"
  49. # 46
  50. # 3 4
  51. # line 4 "bbb"
  52. # 7 "aaaa"
  53. ', '@hashchar{} line 4 "ggggg"
  54. and
  55. @hashchar{} line 5 "fff"
  56. @hashchar{} 46
  57. # 3 4
  58. @hashchar{} line 4 "bbb"
  59. @hashchar{} 7 "aaaa"
  60. ', 'two paragraphs');
  61. run_test ('
  62. @example
  63. # line 5 "fff"
  64. aaa
  65. b
  66. # line 4 "bbb"
  67. # 7 "aaaa"
  68. @end example
  69. ', '
  70. @example
  71. @hashchar{} line 5 "fff"
  72. aaa
  73. b
  74. @hashchar{} line 4 "bbb"
  75. @hashchar{} 7 "aaaa"
  76. @end example
  77. ', 'in example');
  78. run_test ('
  79. @table @asis
  80. @item truc
  81. # line 4 "bbb"
  82. @end table
  83. @itemize
  84. # 7 "aaaa"
  85. @item # line 5 "fff"
  86. # 6 "ff"
  87. @end itemize
  88. ', '
  89. @table @asis
  90. @item truc
  91. @hashchar{} line 4 "bbb"
  92. @end table
  93. @itemize
  94. @hashchar{} 7 "aaaa"
  95. @item @hashchar{} line 5 "fff"
  96. @hashchar{} 6 "ff"
  97. @end itemize
  98. ', 'in block commands');
  99. run_test('
  100. @macro mymacro {}
  101. # line 20 "ff"
  102. @end macro
  103. ', '
  104. @macro mymacro {}
  105. # line 20 "ff"
  106. @end macro
  107. ', 'in raw command', ':2: warning: could not protect hash character in @macro
  108. ');
  109. #{
  110. # local $Data::Dumper::Purity = 1;
  111. # local $Data::Dumper::Indent = 1;
  112. #
  113. # print STDERR Data::Dumper->Dump([$tree]);
  114. #}