Created
August 31, 2018 16:23
-
-
Save tbrowder/38eb8c9b9e45a994aefb93ce3e94bbe0 to your computer and use it in GitHub Desktop.
S26 :numbered-alias'#'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
use v6; | |
use Test; | |
plan 46; | |
my $o; | |
my $p = -1; | |
# These tests validate a new specification for S26's abbreviated | |
# blocks (which are not able to have an explicit config entry) to | |
# allow a number or hash sign ('#') to be entered on the '=typename' | |
# line which will be treated the same as a :numbered config key for | |
# other block types. | |
# | |
# The hash entry is subject to the following requirements (which are | |
# slightly modified from the original S26 specification): | |
# | |
# 1. The hash must be the first whitespace-delineated word in the block data. | |
# 2. The hash must occur on the same line as the '=typename' for it to | |
# trigger the implicit :numbered config key. | |
# | |
# Requirement 2 is stricter than the original S26 which allowed the | |
# hash to be on the first data line which can be on the line following | |
# the '=typename' line. This specification does not allow that | |
# option. | |
# | |
# Rationale: | |
# | |
# 1. Some abbreviated blocks, such as the =table and =code types, | |
# require stricter handling of all data lines, and the tighter rule | |
# will ease coding and maintenance. | |
# | |
# 2. The use of a '#' as the first word on the second line of an abbreviated | |
# block seems unlikely to be a choice authors would make since the number sign | |
# would detract from any data layout, particularly for =table and =code | |
# blocks. | |
# | |
# Caveat: If any future need for the number sign on the second line is | |
# found to be valid, the restriction can always be lifted. | |
#=== abbreviated blocks | |
# cannot have any explicit | |
# config info, but they can have a shortcut | |
# method for the :numbered key using a '#' as | |
# the first whitespace-delimited word in its | |
# contents | |
=para # one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Block::Para'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
isa-ok $o.contents[0], 'Str'; | |
is $o.contents[0], 'one two', 'para contents ok'; | |
=item # one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Item'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
isa-ok $o.contents[0], 'Pod::Block::Para'; | |
is $o.contents[0].contents[0], 'one two', 'para contents ok'; | |
is $o.level, 1, 'default level 1'; | |
=head2 # one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Heading'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
isa-ok $o.contents[0], 'Pod::Block::Para'; | |
is $o.contents[0].contents[0], 'one two', 'para contents ok'; | |
is $o.level, 2, 'level 2'; | |
if 0 { | |
say "======================="; | |
say $o; | |
say "======================="; | |
} | |
=Foo # | |
one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Block::Named'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
is $o.name, 'Foo', 'name Foo ok'; | |
is $o.contents[0].contents[0], 'one two', 'para contents ok'; | |
if 0 { | |
say "======================="; | |
say $o; | |
say "======================="; | |
} | |
=Foo # one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Block::Named'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
is $o.name, 'Foo', 'name Foo ok'; | |
is $o.contents[0].contents[0], 'one two', 'para contents ok'; | |
=defn # | |
one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Defn'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
is $o.term, 'one', 'term ok'; | |
is $o.contents[0].contents[0], 'two', 'para contents ok'; | |
=defn # one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Defn'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
is $o.term, 'one', 'term ok'; | |
is $o.contents[0].contents[0], 'two', 'para contents ok'; | |
=begin code | |
one | |
two | |
=end code | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Block::Code'; | |
is $o.contents[0], ' one', ' one'; | |
is $o.contents[2], ' two', ' two'; | |
if 0 { | |
for $o.contents { | |
say "line: '$_'"; | |
} | |
} | |
if 0 { | |
say "======================="; | |
say $o; | |
say "======================="; | |
} | |
=code # one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Block::Code'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
is $o.contents[0], ' one', ' one'; | |
is $o.contents[2], ' two', ' two'; | |
if 0 { | |
say "======================="; | |
say $o; | |
say "======================="; | |
} | |
=table # | |
one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Block::Table'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
is $o.contents[0][0], 'one', 'row 0, col 0 ok'; | |
is $o.contents[1][0], 'two', 'row 1, col 0 ok'; | |
if 0 { | |
say "======================="; | |
say $o; | |
say "======================="; | |
} | |
=for para :numbered | |
one | |
two | |
$o = $=pod[++$p]; | |
isa-ok $o, 'Pod::Block::Named'; | |
ok $o.config<numbered>:exists, 'is :numbered'; | |
is $o.name, 'para', 'name ok'; | |
isa-ok $o.contents[0], 'Pod::Block::Para'; | |
is $o.contents[0].contents[0], 'one two', 'para contents ok'; | |
if 0 { | |
say "======================="; | |
say $o; | |
say "======================="; | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment