paragraph.t 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. use strict;
  2. use Test::More;
  3. use File::Spec;
  4. use File::Basename;
  5. BEGIN {
  6. plan tests => 119;
  7. my ($real_command_name, $command_directory, $command_suffix)
  8. = fileparse($0, '.t');
  9. my $updir = File::Spec->updir();
  10. my $up = File::Spec->catdir($command_directory, $updir);
  11. push @INC, $up;
  12. if (!defined($ENV{'top_srcdir'})) {
  13. $ENV{'top_srcdir'} = File::Spec->catdir($up, $updir);
  14. }
  15. require Texinfo::ModulePath;
  16. Texinfo::ModulePath::init();
  17. }; # end BEGIN
  18. use Texinfo::Convert::Paragraph;
  19. use Texinfo::Convert::Line;
  20. use Texinfo::Convert::UnFilled;
  21. ok(1, "modules loading"); # If we made it this far, we're ok.
  22. sub test_para($$$;$)
  23. {
  24. my $args = shift;
  25. my $reference = shift;
  26. my $name = shift;
  27. my $conf = shift;
  28. my $result = '';
  29. #$conf = {'DEBUG' => 1} if (!defined($conf));
  30. $conf = {} if (!defined($conf));
  31. my $para = Texinfo::Convert::Paragraph->new($conf);
  32. foreach my $arg (@$args) {
  33. $result .= add_text($para, $arg);
  34. }
  35. $result .= Texinfo::Convert::Paragraph::end($para);
  36. if (defined($reference)) {
  37. is ($result, $reference, $name);
  38. } else {
  39. print STDERR "$result\n";
  40. }
  41. }
  42. test_para(['word'], "word\n", 'word');
  43. test_para(['word other'], "word other\n", 'two_words');
  44. test_para(['word other'], "word other\n", 'two_words two spaces');
  45. test_para(['word ', ' other'], "word other\n", 'two_words feed, space inside');
  46. test_para(['word '], "word\n", 'trailing spaces');
  47. test_para([' word'], "word\n", 'leading spaces');
  48. test_para([' ', ' word'], "word\n", 'double leading spaces');
  49. test_para(["word\n", "a"], "word a\n", 'trailing end of line and word');
  50. test_para(['word', "\n", "a"], "word a\n", 'appended end of line and word');
  51. test_para(['word other'], "word\nother\n", 'two_words_max', {'max' => 2});
  52. test_para(['word other'], "word\nother\n", 'two_words_max_less_one', {'max' => 3});
  53. test_para(['word other'], "word\nother\n", 'two_words_max_exact', {'max' => 4});
  54. test_para(['word other'], "word\nother\n", 'two_words_max_plus_one', {'max' => 5});
  55. test_para(['word other'], "word\nother\n", 'two_words_max_plus_two', {'max' => 6});
  56. test_para(['word o'], "word\no\n", 'word_letter_max_exact', {'max' => 5});
  57. test_para(['word o'], "word o\n", 'word_letter_max_plus_two', {'max' => 6});
  58. test_para(['word other'], "word other\n", 'two_words_two_spaces');
  59. test_para(['word. other'], "word. other\n", 'two_words_dot');
  60. #test_para(['word. other'], "word. other\n", 'two_words_dot_one_space');
  61. test_para(['word. other'], "word. other\n", 'two_words_dot_one_space');
  62. test_para(['word.) other'], "word.) other\n", 'two_words_dot_paren_one_space');
  63. test_para(['word.). other'], "word.). other\n", 'two_words_dot_paren_dot');
  64. test_para(['word.. other'], "word.. other\n", 'two_words_dot_dot');
  65. test_para(['worD. other'], "worD. other\n", 'two_words_dot_upper');
  66. test_para(['worD.) other'], "worD.) other\n", 'two_words_dot_paren_upper');
  67. test_para(['worD). other'], "worD). other\n", 'two_words_paren_dot_upper');
  68. test_para(["word.\n", "\n", "\n", 'other',], "word. other\n", 'three_newlines');
  69. test_para(['word','other'], "wordother\n", 'concatenate');
  70. test_para(['word.', ' A'], "word. A\n", 'punctuation_at_end_fragment');
  71. test_para(['word','other'], "wordother\n", 'concatenate_max', {'max' => 2});
  72. test_para(['word ','other'], "word\nother\n", 'two_elements_max', {'max' => 2});
  73. test_para(['word',' other'], "word\nother\n", 'two_elements_space_max', {'max' => 2});
  74. test_para(["\x{7b2c}\x{4e00} ",'other'], "\x{7b2c}\n\x{4e00}\nother\n", 'east_asian', {'max' => 2});
  75. test_para(['word. other'], "word. other\n", 'two_words_dot_frenchspacing', {'frenchspacing' => 1});
  76. test_para(["aa.)\x{7b2c} b"], "aa.)\x{7b2c} b\n", 'end_sentence_east_asian');
  77. test_para(["aaaa bbbbbbb cccccccc dddddddddddd eeeeeeeeeeee fffffffff ggggggg"],
  78. " aaaa
  79. bbbbbbb
  80. cccccccc
  81. dddddddddddd
  82. eeeeeeeeeeee
  83. fffffffff
  84. ggggggg
  85. ",
  86. 'indent_indent_next', {'max' => 6, 'indent_length' => 3, 'indent_length_next' => 1});
  87. test_para(["aaaa bbbbbbb cccccccc dddddddddddd eeeeeeeeeeee fffffffff ggggggg"],
  88. " aaaa
  89. bbbbbbb
  90. cccccccc
  91. dddddddddddd
  92. eeeeeeeeeeee
  93. fffffffff
  94. ggggggg
  95. ",
  96. 'indent_no_indent_next', {'max' => 12, 'indent_length' => 4, 'indent_length_next' => 0});
  97. test_para(["aaaa bbbbbbb cccccccc dddddddddddd eeeeeeeeeeee fffffffff ggggggg"],
  98. " aaaa
  99. bbbbbbb
  100. cccccccc
  101. dddddddddddd
  102. eeeeeeeeeeee
  103. fffffffff
  104. ggggggg
  105. ",
  106. 'indent_undef_indent_next', {'max' => 12, 'indent_length' => 4});
  107. test_para(["aaaa bbbbbbb cccccccc dddddddddddd eeeeeeeeeeee fffffffff ggggggg"],
  108. "aaaa bbbbbbb
  109. cccccccc
  110. dddddddddddd
  111. eeeeeeeeeeee
  112. fffffffff
  113. ggggggg
  114. ",
  115. 'indent_next_no_indent', {'max' => 12, 'indent_length' => 0, 'indent_length_next' => 3});
  116. test_para(["aaaa bbbbbbb cccccccc dddddddddddd eeeeeeeeeeee fffffffff ggggggg"],
  117. "aaaa bbbbbbb
  118. cccccccc
  119. dddddddddddd
  120. eeeeeeeeeeee
  121. fffffffff
  122. ggggggg
  123. ",
  124. 'indent_next_undef_indent', {'max' => 12, 'indent_length_next' => 3});
  125. test_para(["aaaa"], " aaaa\n", 'indent_and_counter_lower',
  126. {'indent_length' => 8, 'counter' => 6});
  127. test_para(["aaaa"], "aaaa\n", 'indent_zero_and_counter',
  128. {'indent_length' => 0, 'counter' => 6});
  129. test_para(["aaaa"], "aaaa\n", 'indent_and_counter_higher',
  130. {'indent_length' => 3, 'counter' => 6});
  131. test_para(["aaaa bbbbbbb cccccccc dddddddddddd"],
  132. "aaaa bbbbbbb\ncccccccc dddddddddddd\n",
  133. "counter_and_line", {'counter' => 60});
  134. my $para = Texinfo::Convert::Paragraph->new();
  135. my $result = '';
  136. $result .= add_text($para, 'aa.)');
  137. $result .= add_next($para, '_');
  138. $result .= add_text($para, ' after');
  139. $result .= Texinfo::Convert::Paragraph::end($para);
  140. is ($result, "aa.)_ after\n", 'add char after end sentence parentheses');
  141. $para = Texinfo::Convert::Paragraph->new();
  142. $result = '';
  143. $result .= add_text($para, 'b ');
  144. $result .= add_next($para, '_');
  145. $result .= add_text($para, '.');
  146. $result .= add_next($para, '_');
  147. $result .= add_text($para, ' after');
  148. $result .= Texinfo::Convert::Paragraph::end($para);
  149. is ($result, "b _._ after\n", 'add char after end sentence');
  150. $para = Texinfo::Convert::Paragraph->new();
  151. $result = '';
  152. $result .= add_next($para, 'a');
  153. $result .= add_next($para, "\n");
  154. $result .= add_next($para, '_');
  155. $result .= Texinfo::Convert::Paragraph::end($para);
  156. is ($result, "a\n_\n", 'add_next: add char after separate end line');
  157. $para = Texinfo::Convert::Paragraph->new();
  158. $result = '';
  159. $result .= add_next($para, "a\n");
  160. $result .= add_next($para, '_');
  161. $result .= Texinfo::Convert::Paragraph::end($para);
  162. is ($result, "a\n_\n", 'add_next: add char after end line');
  163. $para = Texinfo::Convert::Paragraph->new();
  164. $result = '';
  165. $result .= add_text($para, "A");
  166. $result .= add_next($para, '_');
  167. $result .= add_text($para, ".)");
  168. $result .= add_text($para, " Next");
  169. $result .= Texinfo::Convert::Paragraph::end($para);
  170. is ($result, "A_.) Next\n", 'add_next: period after next, not transparent');
  171. $para = Texinfo::Convert::Paragraph->new();
  172. $result = '';
  173. $result .= add_text($para, "A");
  174. $result .= add_next($para, '_', 1);
  175. $result .= add_text($para, ".)");
  176. $result .= add_text($para, " Next");
  177. $result .= Texinfo::Convert::Paragraph::end($para);
  178. is ($result, "A_.) Next\n", 'add_next: period after next, transparent');
  179. $para = Texinfo::Convert::Paragraph->new();
  180. $result = '';
  181. $result .= add_text($para, "aa.\n");
  182. $result .= set_space_protection($para, undef,undef,undef,1);
  183. $result .= add_next($para, '_');
  184. $result .= add_text($para, "b");
  185. $result .= Texinfo::Convert::Paragraph::end($para);
  186. is ($result, "aa. _b\n", 'add char after space protection end sentence space');
  187. $para = Texinfo::Convert::Paragraph->new();
  188. $result = '';
  189. $result .= set_space_protection($para, undef,undef,undef,1);
  190. $result .= add_text($para, "b");
  191. $result .= set_space_protection($para, undef,undef,undef,0);
  192. $result .= add_text($para, ". after");
  193. $result .= Texinfo::Convert::Paragraph::end($para);
  194. is ($result, "b. after\n", 'punctuation after end space protection');
  195. $para = Texinfo::Convert::Paragraph->new();
  196. $result = '';
  197. $result .= set_space_protection($para, undef,undef,undef,1);
  198. $result .= add_text($para, "b.");
  199. $result .= set_space_protection($para, undef,undef,undef,0);
  200. $result .= add_text($para, " follow");
  201. $result .= Texinfo::Convert::Paragraph::end($para);
  202. is ($result, "b. follow\n", 'punctuation before end space protection');
  203. $para = Texinfo::Convert::Paragraph->new();
  204. $result = '';
  205. $result .= set_space_protection($para, undef,undef,undef,1);
  206. $result .= add_text($para, "b.");
  207. $result .= set_space_protection($para, undef,undef,undef,0);
  208. $result .= add_text($para, " follow");
  209. $result .= Texinfo::Convert::Paragraph::end($para);
  210. is ($result, "b. follow\n", 'punctuation before end space protection 2 space');
  211. $para = Texinfo::Convert::Paragraph->new();
  212. $result = '';
  213. $result .= set_space_protection($para, undef,undef,undef,1);
  214. $result .= add_text($para, "b. ");
  215. $result .= set_space_protection($para, undef,undef,undef,0);
  216. $result .= add_text($para, " follow");
  217. $result .= Texinfo::Convert::Paragraph::end($para);
  218. is ($result, "b. follow\n", 'punctuation space before end space protection');
  219. $para = Texinfo::Convert::Paragraph->new();
  220. $result = '';
  221. $result .= add_text($para, "In w:\n");
  222. $result .= set_space_protection($para, 1,1);
  223. $result .= add_text($para, "Out of code -- out-of-code. ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
  224. $result .= Texinfo::Convert::Paragraph::end($para);
  225. is ($result, "In w: Out of code -- out-of-code. ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\n", 'space protection after end sentence');
  226. $para = Texinfo::Convert::Paragraph->new();
  227. $result = '';
  228. $result .= add_text($para, "In w:\n");
  229. $result .= set_space_protection($para, 1,1);
  230. $result .= add_text($para, "Out of code -- out-of-code.");
  231. $result .= set_space_protection($para, undef,undef,undef,1);
  232. $result .= add_text($para, "in code");
  233. $result .= Texinfo::Convert::Paragraph::end($para);
  234. is ($result, "In w: Out of code -- out-of-code.in code\n", 'set frenchspacing after space protection');
  235. $para = Texinfo::Convert::Paragraph->new();
  236. $result = '';
  237. $result .= add_text($para, "a ");
  238. $result .= add_next($para, '...', 1);
  239. $result .= add_text($para, "c");
  240. $result .= Texinfo::Convert::Paragraph::end($para);
  241. is ($result, "a ...c\n", 'add end sentence and text');
  242. $para = Texinfo::Convert::Paragraph->new();
  243. $result = '';
  244. $result .= end_line($para);
  245. $result .= add_text($para, ' after');
  246. $result .= Texinfo::Convert::Paragraph::end($para);
  247. is ($result, "\nafter\n", 'space after end_line');
  248. #print STDERR "$result";
  249. $para = Texinfo::Convert::Paragraph->new();
  250. $result = '';
  251. $result .= add_text($para, 'aa.)');
  252. $result .= add_pending_word($para);
  253. is ($result, 'aa.)', 'call add_pending_word');
  254. $result = end_line($para);
  255. is ($result, "\n", 'call end_line after add_pending_word');
  256. $result = Texinfo::Convert::Paragraph::end($para);
  257. is ($result, '', 'call end after end_line');
  258. $para = Texinfo::Convert::Paragraph->new();
  259. $result = '';
  260. $result .= add_text($para, 'aa.)');
  261. $result .= add_pending_word($para);
  262. $result .= add_text($para, ' after');
  263. $result .= Texinfo::Convert::Paragraph::end($para);
  264. is ($result, "aa.) after\n", 'space after sentence and add_pending_word');
  265. $para = Texinfo::Convert::Paragraph->new();
  266. $result = '';
  267. $result .= add_text($para, 'aA');
  268. $result .= add_next($para, '.');
  269. add_end_sentence($para, 1);
  270. $result .= add_text($para, ' after');
  271. $result .= Texinfo::Convert::Paragraph::end($para);
  272. is ($result, "aA. after\n", 'force end sentence after upper case');
  273. $para = Texinfo::Convert::Paragraph->new();
  274. $result = '';
  275. $result .= add_text($para, 'aa');
  276. $result .= add_next($para, '.');
  277. add_end_sentence($para, 1);
  278. $result .= add_text($para, 'b c');
  279. $result .= Texinfo::Convert::Paragraph::end($para);
  280. is ($result, "aa.b c\n", 'force end sentence followed by text');
  281. $para = Texinfo::Convert::Paragraph->new();
  282. $result = '';
  283. $result .= add_text($para, 'aA');
  284. $result .= add_text($para, '.');
  285. $result .= add_text($para, ' after');
  286. $result .= Texinfo::Convert::Paragraph::end($para);
  287. is ($result, "aA. after\n", 'end sentence after upper case');
  288. $para = Texinfo::Convert::Paragraph->new();
  289. $result = '';
  290. $result .= add_text($para, 'aa.)');
  291. $result .= add_text($para, '))');
  292. $result .= add_text($para, ' after');
  293. $result .= Texinfo::Convert::Paragraph::end($para);
  294. is ($result, "aa.))) after\n", 'continue with after_punctuation_characters');
  295. $para = Texinfo::Convert::Paragraph->new();
  296. $result = '';
  297. $result .= add_text($para, 'aa.)');
  298. remove_end_sentence($para, );
  299. $result .= add_text($para, ' after');
  300. $result .= Texinfo::Convert::Paragraph::end($para);
  301. is ($result, "aa.) after\n", 'inhibit end sentence');
  302. $para = Texinfo::Convert::Paragraph->new();
  303. $result = '';
  304. $result .= add_text($para, 'aa.)');
  305. remove_end_sentence($para, );
  306. $result .= add_next($para, '_');
  307. $result .= add_text($para, ' after');
  308. $result .= Texinfo::Convert::Paragraph::end($para);
  309. is ($result, "aa.)_ after\n", 'inhibit end sentence then add next');
  310. $para = Texinfo::Convert::Paragraph->new();
  311. $result = '';
  312. $result .= add_text($para, 'aa.)');
  313. remove_end_sentence($para, );
  314. $result .= add_text($para, 'aa.)');
  315. $result .= add_text($para, ' after');
  316. $result .= Texinfo::Convert::Paragraph::end($para);
  317. is ($result, "aa.)aa.) after\n", 'cancel inhibit end sentence');
  318. $para = Texinfo::Convert::Paragraph->new();
  319. $result = '';
  320. $result .= add_text($para, 'aa.)');
  321. remove_end_sentence($para, );
  322. $result .= add_text($para, '))');
  323. $result .= add_text($para, ' after');
  324. $result .= Texinfo::Convert::Paragraph::end($para);
  325. is ($result, "aa.))) after\n", 'inhibit end sentence and ))');
  326. $para = Texinfo::Convert::Paragraph->new();
  327. $result = '';
  328. set_space_protection($para, undef,1,1);
  329. $result .= add_text($para, ' aa.) bb.');
  330. $result .= Texinfo::Convert::Paragraph::end($para);
  331. is ($result,"aa.) bb.\n", 'leading spaces ignore columns and keep spaces');
  332. $para = Texinfo::Convert::Paragraph->new({'max' => 2});
  333. $result = '';
  334. set_space_protection($para, 1,1);
  335. $result .= add_text($para, 'aa.) bb ');
  336. $result = add_text($para, ' eee ');
  337. $result .= add_text($para, ' .)');
  338. $result .= add_next($para, '_');
  339. $result .= add_text($para, "\n");
  340. $result .= add_text($para, "aa\n");
  341. $result .= add_text($para, ' . gg');
  342. $result .= add_text($para, ". \n");
  343. $result .= add_text($para, "a");
  344. $result .= add_text($para, ' ');
  345. $result .= set_space_protection($para, 0,0);
  346. $result .= add_text($para, "c ");
  347. is ($result, "aa.) bb eee .)_ aa . gg. a c\n", "protected spaces many inputs");
  348. Texinfo::Convert::Paragraph::end($para);
  349. $para = Texinfo::Convert::Paragraph->new({'max' => 10});
  350. $result = '';
  351. $result .= add_next($para, "AAAAAAA");
  352. $result .= add_text($para, "GGG GGG");
  353. $result .= Texinfo::Convert::Paragraph::end($para);
  354. is ($result, "AAAAAAAGGG\nGGG\n", 'line split check');
  355. $para = Texinfo::Convert::Paragraph->new({'max' => 10});
  356. $result = '';
  357. $result .= add_next($para, "AAAAAAA\n");
  358. $result .= add_text($para, "GGG GGG");
  359. $result .= Texinfo::Convert::Paragraph::end($para);
  360. is ($result, "AAAAAAA\nGGG GGG\n", 'end line reset counter');
  361. $para = Texinfo::Convert::Paragraph->new({'indent_length' => 3});
  362. $result = '';
  363. $result .= set_space_protection($para, 1,1);
  364. $result .= add_text($para, " a\n");
  365. $result .= set_space_protection($para, 0,0);
  366. $result .= Texinfo::Convert::Paragraph::end($para);
  367. is ($result, " a \n", 'end space protection by end line');
  368. $para = Texinfo::Convert::Paragraph->new();
  369. $result = '';
  370. $result .= set_space_protection($para, 1,1);
  371. $result .= add_text($para, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbb bbbbb bbb b b b b b b b b b bb .\n");
  372. $result .= add_text($para, "ccc dddd");
  373. $result .= set_space_protection($para, 0,0);
  374. $result .= add_text($para, "gg.\n");
  375. $result .= Texinfo::Convert::Paragraph::end($para);
  376. is ($result, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbb bbbbb bbb b b b b b b b b b bb . ccc ddddgg.\n", 'long text followed by text protected');
  377. $para = Texinfo::Convert::Paragraph->new();
  378. $result = '';
  379. $result .= add_text($para, 'aa');
  380. $result .= set_space_protection($para, 1,1);
  381. $result .= add_text($para, ' f f');
  382. $result .= set_space_protection($para, 0,0);
  383. $result .= add_text($para, "ggg\n");
  384. is ($result, 'aa f fggg', 'protected space within words');
  385. Texinfo::Convert::Paragraph::end($para);
  386. $para = Texinfo::Convert::Paragraph->new();
  387. $result = '';
  388. $result = add_text($para, 'aa');
  389. $result .= set_space_protection($para, 1,1);
  390. $result .= add_text($para, ' f f ');
  391. $result .= set_space_protection($para, 0,0);
  392. $result .= add_text($para, "ggg\n");
  393. is ($result, 'aa f f ggg', 'protected space and space within words');
  394. Texinfo::Convert::Paragraph::end($para);
  395. $para = Texinfo::Convert::Paragraph->new();
  396. $result = '';
  397. $result = add_text($para, 'aa ');
  398. $result .= set_space_protection($para, 1,1);
  399. $result .= add_text($para, ' f f ');
  400. $result .= set_space_protection($para, 0,0);
  401. $result .= add_text($para, "ggg\n");
  402. is ($result, 'aa f f ggg', 'text space protected space and space within words');
  403. Texinfo::Convert::Paragraph::end($para);
  404. $para = Texinfo::Convert::Paragraph->new();
  405. $result = '';
  406. $result = add_text($para, 'aa ');
  407. $result .= set_space_protection($para, 1,1);
  408. $result .= add_text($para, ' f f ');
  409. $result .= set_space_protection($para, 0,0);
  410. $result .= add_text($para, " ggg\n");
  411. is ($result, 'aa f f ggg', 'text space protected space and space after');
  412. Texinfo::Convert::Paragraph::end($para);
  413. $para = Texinfo::Convert::Paragraph->new();
  414. $result = '';
  415. $result = add_text($para, 'aa ');
  416. $result .= set_space_protection($para, 1,1);
  417. $result .= set_space_protection($para, 0,0);
  418. $result .= add_text($para, " ggg\n");
  419. is ($result, 'aa ggg', 'empty protected 2 space');
  420. Texinfo::Convert::Paragraph::end($para);
  421. $para = Texinfo::Convert::Paragraph->new();
  422. $result = '';
  423. $result = add_text($para, 'aa ');
  424. $result .= set_space_protection($para, 1,1);
  425. set_space_protection($para, 0,0);
  426. $result .= add_text($para, "ggg\n");
  427. is ($result, 'aa ggg', 'empty protected 1 before space');
  428. Texinfo::Convert::Paragraph::end($para);
  429. $para = Texinfo::Convert::Paragraph->new();
  430. $result = '';
  431. $result = add_text($para, 'aa');
  432. $result .= set_space_protection($para, 1,1);
  433. $result .= set_space_protection($para, 0,0);
  434. $result .= add_text($para, " ggg\n");
  435. is ($result, 'aa ggg', 'empty protected 1 after space');
  436. Texinfo::Convert::Paragraph::end($para);
  437. $para = Texinfo::Convert::Paragraph->new();
  438. $result = '';
  439. $result = add_text($para, 'aa ');
  440. $result .= set_space_protection($para, 1,1);
  441. $result .= add_text($para, ' ');
  442. $result .= set_space_protection($para, 0,0);
  443. $result .= add_text($para, " ggg\n");
  444. is ($result, 'aa ggg', 'space protected space');
  445. Texinfo::Convert::Paragraph::end($para);
  446. sub test_line($$$;$)
  447. {
  448. my $args = shift;
  449. my $reference = shift;
  450. my $name = shift;
  451. my $conf = shift;
  452. my $result = '';
  453. #$conf = {'DEBUG' => 1} if (!defined($conf));
  454. $conf = {} if (!defined($conf));
  455. my $line = Texinfo::Convert::Line->new($conf);
  456. foreach my $arg (@$args) {
  457. $result .= add_text($line, $arg);
  458. }
  459. $result .= Texinfo::Convert::Paragraph::end($line);
  460. is ($result, $reference, "line $name");
  461. #print STDERR "$result\n";
  462. }
  463. test_line(["word\n"], "word\n", 'word');
  464. test_line(['word other'], "word other", 'two_words');
  465. test_line(['word '], 'word ', 'trailing spaces');
  466. test_line(["word \n"], "word\n", 'trailing spaces eol');
  467. test_line([' word'], "word", 'leading spaces');
  468. test_line([' ', ' word'], "word", 'double leading spaces');
  469. test_line(['word other'], "word other", 'two_words_two_spaces');
  470. test_line(['word. other'], "word. other", 'two_words_dot');
  471. test_line(['word. other'], "word. other", 'two_words_dot_one_space');
  472. test_line(['word.) other'], "word.) other", 'two_words_dot_paren_one_space');
  473. test_line(['worD. other'], "worD. other", 'two_words_dot_upper');
  474. test_line(['word','other',"\n"], "wordother\n", 'concatenate');
  475. test_line(["\x{7b2c}\x{4e00} ","other \n"], "\x{7b2c}\x{4e00} other\n", 'east_asian');
  476. test_line(['word. other'], "word. other", 'two_words_dot_frenchspacing', {'frenchspacing' => 1});
  477. test_line(["aa.)\x{7b2c} b"], "aa.)\x{7b2c} b", 'end_sentence_east_asian');
  478. my $line = Texinfo::Convert::Line->new();
  479. $result = '';
  480. $result .= add_text($line, 'aa.)');
  481. $result .= add_next($line, '_');
  482. $result .= add_text($line, ' after');
  483. $result .= Texinfo::Convert::Paragraph::end($line);
  484. is ($result, "aa.)_ after", 'line add char after end sentence');
  485. $para = Texinfo::Convert::Line->new();
  486. $result = '';
  487. $result .= end_line($line);
  488. $result .= add_text($line, ' after');
  489. $result .= Texinfo::Convert::Paragraph::end($line);
  490. is ($result, "\nafter", 'line space after end_line');
  491. #print STDERR "$result";
  492. $line = Texinfo::Convert::Line->new();
  493. $result = '';
  494. $result .= add_text($line, "A");
  495. $result .= add_next($line, '_', 1);
  496. $result .= add_text($line, ".)");
  497. $result .= add_text($line, " Next");
  498. $result .= Texinfo::Convert::Paragraph::end($line);
  499. is ($result, "A_.) Next", 'line add_next: period after next, transparent');
  500. $line = Texinfo::Convert::Line->new();
  501. $result = '';
  502. $result .= add_text($line, 'aa.)');
  503. $result .= add_pending_word($line);
  504. is ($result, 'aa.)', 'line call add_pending_word');
  505. $result = end_line($line);
  506. is ($result, "\n", 'line call end_line after add_pending_word');
  507. $result = Texinfo::Convert::Paragraph::end($line);
  508. is ($result, "", 'line call end after end_line');
  509. $para = Texinfo::Convert::Line->new();
  510. $result = '';
  511. $result .= add_text($line, 'aa.)');
  512. $result .= add_pending_word($line);
  513. $result .= add_text($line, ' after');
  514. $result .= Texinfo::Convert::Paragraph::end($line);
  515. is ($result, "aa.) after", 'line space after sentence and add_pending_word');
  516. $para = Texinfo::Convert::Line->new();
  517. $result = '';
  518. $result .= add_text($line, 'aA');
  519. $result .= add_next($line, '.');
  520. add_end_sentence($line, 1);
  521. $result .= add_text($line, ' after');
  522. $result .= Texinfo::Convert::Paragraph::end($line);
  523. is ($result, "aA. after", 'line force end sentence after upper case');
  524. $line = Texinfo::Convert::Line->new();
  525. $result = '';
  526. $result .= add_text($line, 'aA');
  527. $result .= add_text($line, '.');
  528. $result .= add_text($line, ' after');
  529. $result .= Texinfo::Convert::Paragraph::end($line);
  530. is ($result, "aA. after", 'line end sentence after upper case');
  531. $line = Texinfo::Convert::Line->new();
  532. $result = '';
  533. $result .= add_text($line, 'aa.)');
  534. $result .= add_text($line, '))');
  535. $result .= add_text($line, ' after');
  536. $result .= Texinfo::Convert::Paragraph::end($line);
  537. is ($result, "aa.))) after", 'line continue with after_punctuation_characters');
  538. $line = Texinfo::Convert::Line->new();
  539. $result = '';
  540. $result .= add_text($line, 'aa.)');
  541. remove_end_sentence($line, );
  542. $result .= add_text($line, ' after');
  543. $result .= Texinfo::Convert::Paragraph::end($line);
  544. is ($result, "aa.) after", 'line inhibit end sentence');
  545. $line = Texinfo::Convert::Line->new();
  546. $result = '';
  547. $result .= add_text($line, 'aa.)');
  548. remove_end_sentence($line, );
  549. $result .= add_next($line, '_');
  550. $result .= add_text($line, ' after');
  551. $result .= Texinfo::Convert::Paragraph::end($line);
  552. is ($result, "aa.)_ after", 'line inhibit end sentence then add next');
  553. $line = Texinfo::Convert::Line->new();
  554. $result = '';
  555. $result .= add_text($line, 'aa.)');
  556. remove_end_sentence($line, );
  557. $result .= add_text($line, 'aa.)');
  558. $result .= add_text($line, ' after');
  559. $result .= Texinfo::Convert::Paragraph::end($line);
  560. is ($result, "aa.)aa.) after", 'line cancel inhibit end sentence');
  561. $line = Texinfo::Convert::Line->new();
  562. $result = '';
  563. $result .= add_text($line, 'aa.)');
  564. remove_end_sentence($line, );
  565. $result .= add_text($line, '))');
  566. $result .= add_text($line, ' after');
  567. $result .= Texinfo::Convert::Paragraph::end($line);
  568. is ($result, "aa.))) after", 'line inhibit end sentence and ))');
  569. $line = Texinfo::Convert::Line->new();
  570. $result = '';
  571. set_space_protection($line, 1,1);
  572. $result .= add_text($line, ' aa.)');
  573. $result .= add_text($line, ' ');
  574. $result .= add_text($line, 'then');
  575. $result .= add_text($line, 'fff g');
  576. set_space_protection($line, 0,0);
  577. $result .= Texinfo::Convert::Paragraph::end($line);
  578. is ($result, " aa.) thenfff g", 'line space_protection and spaces');
  579. $line = Texinfo::Convert::Line->new();
  580. $result = '';
  581. $result .= add_text($line, "aa. ");
  582. $result .= set_space_protection($line, undef,undef,undef,1);
  583. $result .= add_next($line, '_');
  584. $result .= add_text($line, "b");
  585. $result .= set_space_protection($line, undef,undef,undef,0);
  586. $result .= add_text($line, ". after");
  587. $result .= Texinfo::Convert::Paragraph::end($line);
  588. is ($result, "aa. _b. after", 'line add char after space protection end sentence space');
  589. $line = Texinfo::Convert::Line->new();
  590. $result = '';
  591. $result .= set_space_protection($line, undef,undef,undef,1);
  592. $result .= add_text($line, "b.");
  593. $result .= set_space_protection($line, undef,undef,undef,0);
  594. $result .= add_text($line, " follow");
  595. $result .= Texinfo::Convert::Paragraph::end($line);
  596. is ($result, "b. follow", 'line punctuation before end space protection 2 space');
  597. $line = Texinfo::Convert::Line->new();
  598. $result = '';
  599. $result .= set_space_protection($line, 1,1);
  600. $result .= add_text($line, "protected. B");
  601. $result .= set_space_protection($line, 0,0);
  602. $result .= add_text($line, " after");
  603. $result .= Texinfo::Convert::Paragraph::end($line);
  604. is ($result, "protected. B after", 'line 2 spaces after end space protection');
  605. $line = Texinfo::Convert::Line->new();
  606. $result = '';
  607. $result .= set_space_protection($line, 1,1);
  608. $result .= add_text($line, "protected");
  609. $result .= set_space_protection($line, 0,0);
  610. $result .= add_text($line, " after");
  611. $result .= Texinfo::Convert::Paragraph::end($line);
  612. is ($result, "protected after", 'line 2 spaces after end space protection with dot');
  613. 1;