Branch Coverage

blib/lib/ChordPro/Song.pm
Criterion Covered Total %
branch 446 730 61.1


line true false branch
113 0 169 unless ref $meta eq "HASH"
116 0 169 if $main::options->{'verbose'}
120 0 169 if ($lines->[0] =~ /^##config:\s*json/)
125 0 0 if ($lines->[0] =~ /^# (.*)/) { }
134 0 0 if ($cf)
143 78 0 if (not $main::options->{'nosongconfig'} and $diag->{'file'})
144 0 78 if ($main::options->{'verbose'})
146 0 0 defined $this ? :
149 0 0 $this eq $_ ? :
152 0 78 if ($meta and $meta->{'__config'}) { }
154 0 0 unless -s $cf
155 0 0 if $main::options->{'verbose'}
162 142 14 if $cf eq $diag->{'file'}
163 156 0 unless -s $cf
164 0 0 if $main::options->{'verbose'}
173 0 0 if $main::options->{'verbose'}
176 0 0 if ($tuncheck ne join("|", @{$main::config->{'tuning'};}))
179 0 0 if $res
183 0 0 if ($chords)
185 0 0 if (@$c and $c->[0] eq "append")
192 0 0 if $res
195 0 0 if ($main::options->{'verbose'} > 1)
196 0 0 if $chords
212 0 169 if (%$defs)
219 658 18 unless defined $main::options->{$_}
223 0 169 unless (UNIVERSAL::isa($main::config->{'instrument'}, "HASH"))
234 0 0 if (UNIVERSAL::isa($main::config->{'meta'}{$_}, 'ARRAY')) { }
246 2 167 if ($target) { }
247 2 0 unless ("ChordPro::Chords::Parser"->have_parser($target))
248 2 0 if (my $file = main::rsc_or_file("config/notes/$target.json"))
256 0 2 unless ("ChordPro::Chords::Parser"->have_parser($target))
259 0 2 if $main::options->{'verbose'}
263 0 2 if ($target ne $p->{'system'})
278 169 0 if $meta
286 0 169 if ($main::options->{'meta'})
293 1 168 if ($main::config->{'settings'}{'memorize'}) { }
302 0 1925 if ($skipcnt) { }
327 0 1925 if ($main::config->{'debug'}{'echo'})
331 0 1925 if ($prep->{'all'})
335 0 0 if (/\n/)
343 4 1921 if ($skip_context)
344 2 2 if (/^\s*\{(\w+)\}\s*$/)
346 2 0 if ($dir->{'name'} eq "end_of_$in_context")
354 32 1889 if (/^\s*\{(new_song|ns)\}\s*$/)
355 29 3 if $self->{'body'}
359 55 1834 if (/^#/)
364 1 54 if (/^##(image|asset):\s+(.*)/i)
369 1 54 if ($kw eq "image")
371 0 1 unless ($id)
389 0 1 if ($info->{'error'})
401 0 1 if ($main::config->{'debug'}{'images'})
409 0 54 if ($kw eq "asset")
412 0 0 unless ($id)
416 0 0 unless ($type)
435 0 0 if ($main::config->{'debug'}{'images'})
442 54 0 if (exists $self->{'title'} or $fragment) { }
451 62 1772 if ($in_context eq "tab")
452 49 13 unless (/^\s*\{(?:end_of_tab|eot)\}\s*$/)
458 0 1785 if (exists $main::config->{'delegates'}{$in_context})
461 0 0 if (/^\s*\{(?:end_of_\Q$in_context\E)\}\s*$/) { }
467 0 0 if ($self->{'body'} and @{$self->{'body'};} and $self->{'body'}[-1]{'context'} eq $in_context and $self->{'body'}[-1]{'open'}) { }
477 0 0 if ($xpose or $main::config->{'settings'}{'transpose'})
495 997 788 if (/^\s*\{(.*)\}\s*$/)
497 0 997 if ($prep->{'directive'})
502 1 996 unless $self->directive($dir)
508 0 491 if (/\S/ and not $fragment and not exists $self->{'title'})
515 0 788 if ($in_context eq "tab")
521 39 749 if ($in_context eq "grid")
526 452 297 if (/\S/) { }
297 0 elsif (exists $self->{'title'} or $fragment) { }
527 0 452 if ($prep->{'songline'})
542 0 169 if $in_context
548 0 169 if $main::options->{'verbose'}
551 0 169 if $main::config->{'debug'}{'song'} > 1
553 1 168 if (@labels)
562 0 0 unless $info
565 0 0 if ($xc)
572 2 428 unless is_true($v->{'diagram'} // 1)
574 2 900 $suppress{$_} ? :
577 5 164 if (exists $self->{'settings'}{'diagrams'}) { }
585 0 169 if ($diagrams =~ /^(user|all)$/ and not "ChordPro::Chords::Parser"->get_parser($target, 1)->has_diagrams)
588 0 0 unless $main::options->{'silent'}
592 0 169 if ($diagrams eq 'user') { }
594 0 0 if ($self->{'define'} and @{$self->{'define'};}) { }
597 0 0 $h{$_->{'name'}} ? :
605 591 309 $h{$_}++ ? :
609 0 169 if ($main::config->{'diagrams'}{'sorted'})
618 114 55 if ($diagrams =~ /^(user|all)$/)
626 0 114 if (%warned_chords)
630 0 0 if (@a > 1) { }
641 0 169 if $main::config->{'debug'}{'song'}
642 0 169 if $main::config->{'debug'}{'songfull'}
649 0 1220 if $skip_context
652 1024 196 $lineinfo ? :
654 106 1114 if ($in_context eq "chorus")
666 0 937 unless length $orig
669 3 934 if ($orig =~ /^\*(.+)/)
680 927 7 if ($markup eq $c)
686 0 934 if $c =~ s/^\((.*)\)$/$1/
691 0 934 unless (defined $info)
704 7 927 if ($markup) { }
927 0 elsif ((my $m = $orig) =~ s/\Q$c\E/%{formatted}/) { }
705 6 1 if ($markup =~ s/\>\Q$c\E\%{formatted}\(\Q$c\E\)\(%{formatted})
715 5 922 unless $m eq "%{formatted}"
723 922 12 unless ($info->is_nc or $info->is_note)
725 0 922 if ($main::config->{'instrument'}{'type'} eq 'keyboard') { }
766 156 elsif ($info->{'origin'}) { }
156 0 elsif ($main::running_under_test) { }
0 0 elsif (not $info->is_rootless || $info->has_diagram || !$info->parser->has_diagrams) { }
730 766 0 if $info->has_diagram
741 0 0 unless $warned_chords{$c}++
751 575 1 if $orig eq $line
755 233 343 if (@a <= 1)
756 0 233 $orig ? :
762 113 230 if $a[0] eq ""
763 230 113 unless $a[0] =~ /$re_chords/
772 1008 27 if ($chord =~ s/^\[(.*)\]$/$1/ and $chord ne '^') { }
20 7 elsif ($memchords and $in_context) { }
773 230 778 $chord eq '' ? :
774 21 987 if ($memchords and not $dummy)
775 3 18 if ($memcrdinx == 0)
778 20 1 if ($memorizing)
782 0 20 if $main::config->{'debug'}{'chords'}
790 1 19 if ($memcrdinx == 0 and @$memchords == 0) { }
0 19 elsif ($memcrdinx >= @$memchords) { }
802 0 19 if $main::config->{'debug'}{'chords'}
815 1 342 $orig ? :
823 124 0 unless $no_substitute
825 110 14 unless $res{'chords'}
833 0 39 if $line eq ""
837 0 39 if (not $line =~ /\|/) { }
842 0 39 if ($line =~ /(.*\|\S*)\s([^\|]*)$/)
845 0 0 unless $grid_cells->[2]
848 0 39 if ($line =~ /^([^|]+?)\s*(\|.*)/)
851 0 0 unless $grid_cells->[1]
863 0 663 if (/\
867 0 0 if m[\]
874 0 663 if ($_ eq '|:' or $_ eq '{') { }
0 663 elsif (/^\|(\d+)(>?)$/) { }
0 663 elsif ($_ eq ':|' or $_ eq '}') { }
0 663 elsif ($_ eq ':|:' or $_ eq '}{') { }
149 514 elsif ($_ eq '|') { }
2 512 elsif ($_ eq '||') { }
0 512 elsif ($_ eq '|.') { }
0 512 elsif ($_ eq '%') { }
0 512 elsif ($_ eq '%%') { }
0 512 elsif ($_ eq '/') { }
395 117 elsif ($_ eq '.') { }
879 0 0 if $2
912 116 1 if (@a == 1) { }
919 0 2 $_ eq '/' ? :
0 2 $_ eq '.' || $_ eq '' ? :
929 0 39 if ($nbt > $grid_cells->[0])
1024 57 942 unless ($dirpat)
1040 787 212 if ($d =~ /^(.*?)[: ]\s*(.*)/)
1048 11 988 if ($dir =~ /^($dirpat)-(.+)$/) { }
1058 6 5 if $negate
1059 4 7 unless ($sel)
1060 2 2 if ($dir =~ /^start_of_/) { }
1079 2 995 if $dd->{'omit'} == 1
1082 784 211 if ($arg ne "")
1084 0 784 unless $arg =~ /\S/
1090 76 919 if ($dir =~ /^start_of_(\w+)$/)
1091 0 76 if $in_context
1094 2 74 if ($dd->{'omit'})
1099 26 48 if $in_context eq "chorus"
1101 25 49 if ($in_context eq 'grid') { }
2 47 elsif ($arg and $arg ne '') { }
1102 3 22 if ($arg eq '') { }
22 0 elsif ($arg =~ /^ (?: (\d+) \+)? (\d+) (?: x (\d+) )? (?:\+ (\d+) )? (?:[:\s+] (.*)? )? $/x) { }
0 0 elsif ($arg ne '') { }
1112 0 22 unless $2
1118 0 22 if length($5 || '')
1134 2 0 unless $in_context eq "chorus" and not $main::config->{'settings'}{'choruslabels'}
1137 0 47 if $arg
1143 7 67 if ($main::config->{'settings'}{'memorize'})
1150 74 845 if ($dir =~ /^end_of_(\w+)$/)
1151 0 74 unless $in_context eq $1
1160 30 815 if ($dir =~ /^chorus$/i)
1161 0 30 if ($in_context)
1167 29 1 @chorus ? :
1169 0 29 if (@$chorus and $arg and $arg ne "")
1170 0 0 if ($chorus->[0]{'type'} eq 'set' and $chorus->[0]{'name'} eq 'label') { }
1182 0 0 if $main::config->{'settings'}{'choruslabels'}
1185 17 13 if ($chorus_xpose != (my $xp = $xpose))
1188 16 16 if ($_->{'type'} eq "songline")
1190 15 46 if $_ eq ""
1192 0 46 if $info->is_annotation
1193 46 0 if $xp
1205 29 1 @$chorus ? :
1217 13 802 if ($dir eq "column_break")
1222 16 786 if ($dir eq "new_page" or $dir eq "new_physical_page")
1227 0 786 if ($dir eq "new_song")
1233 124 662 if ($dir =~ /^comment(_italic|_box)?$/)
1237 124 0 unless exists $res{'text'} and $res{'text'} =~ /^[ \t]*$/
1242 3 659 if ($dir eq "image")
1248 1 8 if ($k =~ /^(title)$/i and $v ne '') { }
2 6 elsif ($k =~ /^(border|spread|center)$/i and $v =~ /^(\d+)$/) { }
2 4 elsif ($k =~ /^(width|height)$/i and $v =~ /^(\d+(?:\.\d+)?\%?)$/) { }
0 4 elsif ($k =~ /^(x|y)$/i and $v =~ /^([-+]?\d+(?:\.\d+)?\%?)$/) { }
1 3 elsif ($k =~ /^(scale)$/ and $v =~ /^(\d+(?:\.\d+)?)(%)?$/) { }
0 3 elsif ($k =~ /^(center|border|spread)$/i) { }
0 3 elsif ($k =~ /^(src|uri)$/i and $v ne '') { }
1 2 elsif ($k =~ /^(id)$/i and $v ne '') { }
0 2 elsif ($k =~ /^(anchor)$/i and $v =~ /^(paper|page|column|line)$/) { }
0 2 elsif ($uri) { }
1261 0 1 $2 ? :
1289 2 1 if ($uri and not $uri =~ m[/\\])
1292 2 0 if -s "$_/$uri"
1294 0 0 unless $_
1295 0 0 if -s $_
1302 0 3 if ($uri and $id)
1304 0 0 if (%opts)
1310 0 0 unless ($fd)
1317 0 0 if ($info->{'error'})
1329 0 0 if ($main::config->{'debug'}{'images'})
1337 1 2 if $id
1338 0 3 unless ($uri)
1342 0 3 $uri =~ /\.svg$/ ? :
1348 173 486 if ($dir eq "title")
1354 28 458 if ($dir eq "subtitle")
1362 225 233 if (&any(sub { $_ eq $dir; } , @{$$main::config{"metadata"}{"keys"};}))
1368 263 195 if ($dir eq "meta")
1369 263 0 if ($arg =~ /([^ :]+)[ :]+(.*)/) { }
1372 256 7 if ($main::config->{'metadata'}{'autosplit'})
1379 0 263 if ($key eq "user" or $key eq "instrument")
1386 92 171 if ($key eq "key")
1392 0 92 if ($capo)
1394 0 0 if $decapo
1405 16 155 if ($key eq 'capo') { }
9 292 elsif ($key eq 'duration' and $val) { }
1407 1 15 if exists $m->{'capo'}
1410 16 0 if ($capo and $m->{'key'})
1411 4 12 if ($decapo) { }
1435 0 171 if ($main::config->{'metadata'}{'strict'} and not &any(sub { $_ eq $key; } , @{$$main::config{"metadata"}{"keys"};}))
1439 0 0 if $main::config->{'settings'}{'strict'}
1443 171 0 if defined $val
1448 0 0 if $main::config->{'settings'}{'strict'}
1456 22 173 if ($dir eq "titles" and $arg =~ /^(left|right|center|centre)$/i)
1459 1 21 lc $1 eq 'centre' ? :
1463 19 154 if ($dir eq "columns" and $arg =~ /^(\d+)$/)
1467 19 0 unless (ref $main::config->{'settings'}{'columns'} eq "ARRAY" and $arg == @{$main::config->{'settings'}{'columns'};})
1475 2 152 if ($dir eq "pagetype" or $dir eq "pagesize")
1480 2 150 if ($dir eq "diagrams")
1481 1 1 if ($arg ne '') { }
1483 1 0 if $arg =~ /^(right|bottom|top|below)$/i
1491 3 147 if ($dir eq "no_grid")
1496 53 94 if ($dir eq "transpose")
1499 32 21 if ($arg =~ /^([-+]?\d+)\s*$/) { }
1509 22 10 if ($m->{'key'})
1512 2 20 if $capo
1518 0 32 if $no_transpose
1528 21 0 if (@{$propstack{'transpose'};}) { }
1537 15 6 if ($m->{'key'})
1540 0 15 if $capo and $decapo
1544 12 9 unless (@{$propstack{'transpose'};})
1547 0 21 if $no_transpose
1554 0 94 if (not $main::options->{'reference'} and $d =~ /^([-+])([-\w.]+)$/i)
1555 0 0 if ($2 eq "dumpmeta")
1558 0 0 $1 eq '+' ? :
1565 11 83 if (not $main::options->{'reference'} and $dir =~ /^\+([-\w.]+(?:\.[<>])?)$/)
1586 0 11 if (ref $o eq "HASH" and ref $o->{$lk} eq "ARRAY")
1593 0 11 if ($lk =~ /^\d+$/ || $lk eq '>' || $lk eq '<' and ref $o eq 'ARRAY') { }
1595 0 0 unless (ref $$c eq "ARRAY")
1599 0 0 if ($lk eq '>') { }
0 0 elsif ($lk eq '<') { }
1620 24 59 if ($dir =~ /^(text|chord|tab|grid|diagrams|title|footer|toc)(font|size|colou?r)$/)
1625 8 16 if $prop eq "colour"
1629 0 24 if ($value eq "")
1631 0 0 if (@{$propstack{$name};})
1635 0 0 if (@{$propstack{$name};}) { }
1648 8 16 if ($prop eq "size")
1649 0 8 unless ($value =~ /^\d+(?:\.\d+)?\%?$/)
1654 8 16 if ($prop =~ /^colou?r$/)
1656 0 8 unless ($v = get_color($value))
1662 8 16 $prop eq 'font' ? :
1670 0 24 if ($prop eq "font" and $value =~ /\s(\d+(?:\.\d+)?)$/)
1686 58 1 if ($dir eq "define" or $dir eq "chord")
1693 0 1 if $main::config->{'settings'}{'strict'} and not $d =~ /^x_/
1700 942 49 if ($new_id) { }
1701 10 932 if ($new_id eq 1)
1724 2 68 unless @a
1738 11 151 if ($a eq 'copy' or $a eq 'copyall') { }
2 149 elsif ($a eq 'display' and @a) { }
9 140 elsif ($a eq 'format' and @a) { }
46 94 elsif ($a eq 'base-fret') { }
57 37 elsif ($a eq 'frets') { }
16 21 elsif ($a eq 'fingers') { }
8 13 elsif ($a eq 'keys') { }
13 0 elsif ($a eq 'diagram' and @a > 0) { }
1739 11 0 if (my $i = ChordPro::Chords::known_chord($a[0])) { }
1755 0 2 unless $kv{'display'} eq shift @a
1757 0 2 unless defined $kv{'display'}
1767 46 0 if ($a[0] =~ /^\d+$/) { }
1782 57 0 if (@f == $strings) { }
1783 302 40 $_ =~ /^\d+/ ? :
1799 90 6 if (/^[0-9]+$/) { }
0 6 elsif (/^[A-MO-WYZ]$/) { }
6 0 elsif (/^[-xNX]$/) { }
1813 16 0 if (@f == $strings) { }
1830 8 0 if (@f) { }
1841 0 13 if ($show and not is_true($a[0]))
1859 0 70 if $fail
1867 70 0 if ($info) { }
1874 8 62 if ($show)
1885 59 11 unless defined $_
1890 0 11 if ($kv{'copyall'})
1896 11 129 if defined $kv{$_}
1900 13 57 if (defined $kv{'diagram'})
1902 7 6 if (is_true($v)) { }
1903 6 1 if (is_ttrue($v))
1916 282 138 unless defined $kv{$_}
1922 8 62 $show ? :
1926 8 62 if ($show)
1930 2 6 if (defined $self->{'body'} and $self->{'body'}[-1]{'type'} eq 'diagrams') { }
1945 250 246 unless defined $res->{$_}
1950 0 62 if ($ret)
1955 0 62 unless $info
1957 0 62 if $main::config->{'debug'}{'x1'}
1965 9 0 if ($dur =~ /(?:(?:(\d+):)?(\d+):)?(\d+)/)
1966 0 9 $2 ? :
0 9 $1 ? :
2011 0 1112 if $debug
2014 4 1108 if $capo and $decapo
2020 72 1040 if $def
2023 880 232 if ($info) { }
2025 0 880 if $debug > 1
2026 0 880 if $debug > 1
2032 0 232 if $info and $debug > 1
2036 21 1091 if ($def || $xp || $xc and not $info && $info->is_xpxc)
2043 0 0 unless ($info and $info->is_xpxc or $def and not $xc || $xp)
2050 0 0 $xp ? :
0 0 $xc ? :
0 0 if $xp or $xc or $main::config->{'debug'}{'chords'}
2053 156 956 if ($xp and $info)
2057 0 156 if $debug > 1
2063 1112 0 if ($info)
2065 885 227 if (my $i = ChordPro::Chords::known_chord($info)) { }
0 227 elsif ($main::config->{'instrument'}{'type'} eq 'keyboard' and my $k = ChordPro::Chords::get_keys($info)) { }
2068 0 885 if $debug > 1
2074 0 0 if $debug > 1
2080 0 227 if $debug
2087 20 1092 if ($xc and $info)
2090 14 6 if $self->{'meta'}{'key'}
2091 0 20 if ($xcmov and not defined $key_ord)
2098 0 20 if $debug > 1
2100 8 12 if (my $i = ChordPro::Chords::known_chord($info))
2101 0 8 if $debug > 1
2108 0 1112 unless ($info)
2109 0 0 if (my $i = ChordPro::Chords::known_chord($chord))
2113 0 0 if $debug > 1
2118 0 1112 unless ($info or $def)
2119 0 0 if ($main::config->{'debug'}{'chords'} or not $warned_chords{$chord}++)
2120 0 0 if $debug
2121 0 0 unless $chord =~ /^n\.?c\.?$/i
2126 1112 0 if ($info)
2127 0 0 $unk ? :
0 1112 if $debug > 1
2136 0 0 if $debug
2149 0 13 if $self->{'structure'} eq "structured"
2155 56 195 if ($item->{'type'} eq "empty" and $item->{'context'} eq $def_context)
2159 36 159 if ($item->{'type'} eq "songline" and $item->{'context'} eq "")
2162 49 146 if ($context ne $item->{'context'})
2165 135 60 if ($context) { }
2180 0 0 unless ($full)