test_brace_count.t 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 => 7; }
  8. use Texinfo::Parser qw(parse_texi_text);
  9. use Texinfo::Common;
  10. ok(1, "modules loading");
  11. my ($before, $after, $braces_count)
  12. = Texinfo::Common::_find_end_brace(" aa (bbb ()ccc)(g))j (gg", 1);
  13. is ($before, " aa (bbb ()ccc)(g))", "before with brace closed");
  14. is ($after, "j (gg", "after with brace closed");
  15. ok ($braces_count == 0, "braces count 0 with brace closed");
  16. my $string_no_close = " kjsdf ( k)lj(";
  17. ($before, $after, $braces_count)
  18. = Texinfo::Common::_find_end_brace($string_no_close, 2);
  19. ok (($braces_count == 3 and $before eq $string_no_close and !defined($after)),
  20. "more braces opened");
  21. my $string_no_brace = " other ";
  22. ($before, $after, $braces_count)
  23. = Texinfo::Common::_find_end_brace($string_no_brace, 1);
  24. ok (($braces_count == 1 and $before eq $string_no_brace and !defined($after)),
  25. "no brace in text");
  26. my $string_open_brace_and_text = " (other ";
  27. ($before, $after, $braces_count)
  28. = Texinfo::Common::_find_end_brace($string_open_brace_and_text, 1);
  29. ok (($braces_count == 2 and $before eq $string_open_brace_and_text
  30. and !defined($after)), "more braces opened and text");
  31. sub run_test($$$$)
  32. {
  33. my $in = shift;
  34. my $initial_brace_count = shift;
  35. my $ref_braces_count = shift;
  36. my $name = shift;
  37. my $tree = parse_texi_text(undef, $in);
  38. my $braces_count
  39. = Texinfo::Common::_count_opened_tree_braces($tree, $initial_brace_count);
  40. if (!defined($ref_braces_count)) {
  41. print STDERR " --> $name ($in): $braces_count\n";
  42. } else {
  43. is ($braces_count, $ref_braces_count, $name);
  44. }
  45. }
  46. # Note: these tests are disabled because the code doesn't look at
  47. # parentheses nested inside commands anymore.
  48. # run_test('@code{(sdffsd)} other @code{(gg} ))', 1, 0, 'brace in code');
  49. # run_test('@code{(sdffsd)) aaa}', 1, 0, 'too much braces');
  50. # run_test(' aaa) @asis{)} @code{( (}', 2, 0, 'more reopened');
  51. # run_test(' aaa) @asis{} @code{( (}', 2, 3, 'still open');