Debian Codegraph @

t/100-util.t

raw
1 use strict;
2 use warnings;
3 use utf8;
4
5 use Markdown::Perl::Util ':all';
6 use Test2::V0;
7
8 {
9 my @a = (2, 4, 6, 7, 8, 9, 10);
10 is([split_while { $_ % 2 == 0 } @a], [[2, 4, 6], [7, 8, 9, 10]], 'split_while1');
11 is (\@a, [2, 4, 6, 7, 8, 9, 10], 'split_while2');
12 }
13
14 {
15 my @a = (2, 4, 6);
16 is([split_while { $_ % 2 == 0 } @a], [[2, 4, 6], []], 'split_while3');
17 }
18
19 is(remove_prefix_spaces(0, 'test'), 'test', 'remove_prefix_spaces1');
20 is(remove_prefix_spaces(0, ' test'), ' test', 'remove_prefix_spaces2');
21 is(remove_prefix_spaces(0, ' test'), ' test', 'remove_prefix_spaces3');
22 is(remove_prefix_spaces(2, ' test'), ' test', 'remove_prefix_spaces4');
23 is(remove_prefix_spaces(2, ' test'), 'test', 'remove_prefix_spaces5');
24 is(remove_prefix_spaces(2, 'test'), 'test', 'remove_prefix_spaces6');
25 is(remove_prefix_spaces(2, ' test'), ' test', 'remove_prefix_spaces7');
26 is(remove_prefix_spaces(2, "\ttest"), ' test', 'remove_prefix_spaces8');
27 is(remove_prefix_spaces(2, " \ttest"), " test", 'remove_prefix_spaces9');
28 is(remove_prefix_spaces(2, " \ttest"), " test", 'remove_prefix_spaces10');
29 is(remove_prefix_spaces(2, " \ttest"), " test", 'remove_prefix_spaces11');
30 is(remove_prefix_spaces(4, ' test'), 'test', 'remove_prefix_spaces12');
31 is(remove_prefix_spaces(4, ' test'), ' test', 'remove_prefix_spaces13');
32 is(remove_prefix_spaces(8, ' test'), 'test', 'remove_prefix_spaces14');
33 is(remove_prefix_spaces(8, ' test'), ' test', 'remove_prefix_spaces15');
34 is(remove_prefix_spaces(2, " \n"), "\n", 'remove_prefix_spaces16');
35 is(remove_prefix_spaces(2, "\t\ttest"), "\t test", 'remove_prefix_spaces17');
36 is(remove_prefix_spaces(4, "\t\ttest"), "\ttest", 'remove_prefix_spaces18');
37 is(remove_prefix_spaces(4, "\t\ttest", 0), " test", 'remove_prefix_spaces19');
38
39 is(indent_size("abc"), 0, 'indent_size1');
40 is(indent_size(" abc"), 1, 'indent_size2');
41 is(indent_size(" abc"), 4, 'indent_size3');
42 is(indent_size("\tabc"), 4, 'indent_size4');
43 is(indent_size(" \tabc"), 4, 'indent_size5');
44 is(indent_size(" \t abc"), 6, 'indent_size6');
45 is(indent_size(" \t abc"), 9, 'indent_size7');
46 is(indent_size("\t\tabc"), 8, 'indent_size8');
47
48 is(horizontal_size("ab\tcd"), 6, 'horizontal_size1');
49 is(horizontal_size("ab\t\tcd"), 10, 'horizontal_size2');
50 is(horizontal_size("\t\tcd"), 10, 'horizontal_size3');
51 is(horizontal_size("abcd\t"), 8, 'horizontal_size4');
52 is(horizontal_size("ab"), 2, 'horizontal_size5');
53
54 is(indented_one_tab("abc"), F(), 'indented_one_tab0');
55 is(indented_one_tab(" abc"), F(), 'indented_one_tab1');
56 is(indented_one_tab(" abc"), T(), 'indented_one_tab2');
57 is(indented_one_tab("xxx abc"), F(), 'indented_one_tab3');
58 is(indented_one_tab("\tabc"), T(), 'indented_one_tab4');
59 is(indented_one_tab(" \tabc"), T(), 'indented_one_tab5');
60
61 is(indented(2, 'foo'), F(), 'indented1');
62 is(indented(2, ' foo'), F(), 'indented2');
63 is(indented(2, ' foo'), T(), 'indented3');
64 is(indented(2, ' foo'), T(), 'indented4');
65 is(indented(2, "\tfoo"), T(), 'indented5');
66 is(indented(0, "\tfoo"), T(), 'indented6');
67 is(indented(0, "foo"), T(), 'indented7');
68 is(indented(5, "\t\tfoo"), T(), 'indented8');
69 is(indented(5, " foo"), T(), 'indented9');
70 is(indented(5, " foo"), F(), 'indented10');
71
72 is(tabs_to_space("ab\tcd"), 'ab cd', 'tabs_to_space1');
73 is(tabs_to_space("ab\tcd", 2), 'ab cd', 'tabs_to_space2');
74 is(tabs_to_space("ab\t\tcd"), 'ab cd', 'tabs_to_space3');
75 is(tabs_to_space("\t\tab"), ' ab', 'tabs_to_space4');
76 {
77 my $s = "ab\tcd";
78 tabs_to_space($s);
79 is($s, 'ab cd', 'tabs_to_space5');
80 }
81
82
83 done_testing;