collect_spaces.t 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 => 15; }
  8. use Texinfo::Parser;
  9. use Texinfo::Convert::Converter;
  10. sub _find_first_command($;$);
  11. sub _find_first_command($;$)
  12. {
  13. my $root = shift;
  14. my $command_name = shift;
  15. if (defined($root->{'cmdname'})
  16. and (!defined($command_name) or $command_name eq $root->{'cmdname'})) {
  17. return $root;
  18. }
  19. if ($root->{'args'}) {
  20. foreach my $content (@{$root->{'args'}}) {
  21. my $first_command = _find_first_command($content, $command_name);
  22. return $first_command if (defined($first_command));
  23. }
  24. }
  25. if ($root->{'contents'}) {
  26. foreach my $content (@{$root->{'contents'}}) {
  27. my $first_command = _find_first_command($content, $command_name);
  28. return $first_command if (defined($first_command));
  29. }
  30. }
  31. return undef;
  32. }
  33. sub run_test($$$;$)
  34. {
  35. my $in = shift;
  36. my $out = shift;
  37. my $name = shift;
  38. my $command_name = shift;
  39. my $tree = Texinfo::Parser::parse_texi_text (undef, $in);
  40. my $root = _find_first_command($tree, $command_name);
  41. #print STDERR Texinfo::Common::_print_current($root);
  42. my $result = "$root->{'cmdname'}";
  43. foreach my $arg (@{$root->{'args'}}) {
  44. my @arg_spaces
  45. = Texinfo::Convert::Converter::_collect_leading_trailing_spaces_arg(undef,
  46. $arg);
  47. @arg_spaces = map {if (defined($_)) {$_} else {''}} @arg_spaces;
  48. $result .= '|' . join(',', @arg_spaces);
  49. }
  50. $result .= "|";
  51. if (!defined($out)) {
  52. print STDERR "$name:\n$result\n";
  53. } else {
  54. is ($result, $out, $name);
  55. }
  56. }
  57. # no type for spaces in style commands
  58. run_test ('@code{ av }', 'code||', 'style command');
  59. run_test ('@code{ }', 'code||', 'empty style command');
  60. # item in itemize has not arg, only contents
  61. run_test ('@itemize
  62. @item
  63. in item
  64. @end itemize
  65. ', 'item|', 'space end line in item', 'item');
  66. run_test ('@itemize
  67. @item in item
  68. @end itemize
  69. ', 'item|', 'space in item', 'item');
  70. run_test ('@image{ a ,b,c , d,e }', 'image| , ||, | |, |', 'image');
  71. run_test ("\@node a ,b,c , d \n", 'node| , ||, | ,
  72. |', 'node');
  73. run_test ('@image{ a ,b
  74. ,c , d,e }', 'image| , |,
  75. |, | |, |', 'image with end of line');
  76. run_test ('@image{ a ,b
  77. ,c , d,e }', 'image| , |,
  78. |, | |, |', 'image with space end of line');
  79. run_test ('@image{ a ,b
  80. ,c , d,e }', 'image| , |, |, | |, |', 'image with space end of line space');
  81. run_test ('@table @asis
  82. @item iem arg
  83. T
  84. @end table', 'item| ,
  85. |', 'table item', 'item');
  86. run_test ('@table @asis
  87. @item
  88. T
  89. @end table', 'item|
  90. |', 'space empty table item', 'item');
  91. run_test ('@table @asis
  92. @item
  93. T
  94. @end table', 'item|
  95. |', 'empty table item', 'item');
  96. run_test ('@multitable {a} {b}
  97. @end multitable', 'multitable| |', 'multitable');
  98. run_test ('@multitable @columnfractions 0.3 0.4 0.2
  99. @end multitable', 'columnfractions| ,
  100. |', 'multitable columnfractions', 'columnfractions');
  101. run_test ('@quotation gg
  102. Q
  103. @end quotation', 'quotation| ,
  104. |', 'quotation');