Permalink
Browse files

Updated for conformance with current Rakudo nom.

All tests pass, but there are some runtime uninitialised value warnings which have yet to be eliminated.
  • Loading branch information...
1 parent f0ee0c0 commit 3f5926f0d25f77f79ec7c34475aa67262f578efe @mathw committed Mar 9, 2012
Showing with 25 additions and 27 deletions.
  1. +1 −1 lib/Form.pm
  2. +1 −2 lib/Form/Actions.pm
  3. +3 −2 lib/Form/Field.pm
  4. +7 −12 lib/Form/TextFormatting.pm
  5. +4 −0 lib/Form/Types.pm
  6. +8 −10 t/04-parseactions.t
  7. +1 −0 t/05-fieldformat.t
View
2 lib/Form.pm
@@ -5,7 +5,7 @@ use Form::Grammar;
use Form::Actions;
use Form::Field;
-sub form(*@args is Scalar --> Str) is export {
+sub form(*@args --> Str) is export {
my @lines;
my $result = '';
View
3 lib/Form/Actions.pm
@@ -1,12 +1,11 @@
use Form::Field;
+use Form::Types;
=begin pod
=head3 FormActions
Class containing action methods to be associated with Form grammar defined in Form::Grammar.
-TODO: Convert from {*} #= key to the New Way (this is no longer in the spec)
-
=end pod
class Form::Actions {
View
5 lib/Form/Field.pm
@@ -2,6 +2,7 @@ module Form::Field;
use Form::TextFormatting;
use Form::NumberFormatting;
+use Form::Types;
# RAKUDO: Field is now a class, because overriding multis doesn't
# work correctly from roles
@@ -78,8 +79,8 @@ our class Form::Field::Text is Form::Field::Field {
}
our class Form::Field::Numeric is Form::Field::Field {
- has Num $.ints-width;
- has Num $.fracs-width;
+ has Int $.ints-width;
+ has Int $.fracs-width;
multi method format(Real $data)
{
View
19 lib/Form/TextFormatting.pm
@@ -1,6 +1,5 @@
module Form::TextFormatting;
-
=begin pod
=head1 Form::TextFormatting
@@ -9,9 +8,6 @@ Utility functions for formatting text in Form.pm.
=end pod
-enum Justify <left right centre full>;
-enum Alignment <top middle bottom>;
-
sub chop-first-word(Str $source is rw) returns Str {
if $source ~~ / ^^ (\S+) \s* (.*) $$ / {
my $word = ~$/[0];
@@ -63,15 +59,17 @@ our sub unjustified-wrap(Str $text, Int $width) {
my $rem = $text;
my $line;
- my @array = gather loop {
+ # RAKUDO: bug in headless loop with gather as of 2012-03-09 requires
+ # the use of while True instead. This should say 'gather loop {'
+ my @array = gather { while True {
($line, $rem) = fit-in-width($rem, $width);
# we have to force a copy here or take will end up with the same value
# every single time! This might be a rakudo issue, or a spec issue
# or just expected behaviour
my $t = $line;
take $t;
$rem or last;
- };
+ } };
return @array;
}
@@ -109,7 +107,7 @@ our sub centre-justify(Str $line, Int $width, Str $space = ' ') returns Str {
return $line.substr(0, $width);
}
-our sub full-justify(Str $line, Int $width, Str $space = ' ') returns Str {
+our sub full-justify(Str $line, Int $width, Str $space = ' ') {
# TODO need a justify algorithm
# for now, do something entirely unsatisfactory
if $line.chars < $width {
@@ -126,17 +124,14 @@ our sub full-justify(Str $line, Int $width, Str $space = ' ') returns Str {
{
@spaces[$act-space++] ~= $space;
- # RAKUDO no reduce meta-op yet
- #$spaces-width = [+] @spaces.map({ .chars });
- $spaces-width = @spaces.map({.chars}).reduce(&infix:<+>);
+ $spaces-width = [+] @spaces.map({ .chars });
$act-space >= @spaces.elems and $act-space = 0;
}
@spaces.push('');
- #return [~] (@words Z @spaces);
- return (@words Z @spaces).reduce: &infix:<~>;
+ return (@words Z @spaces).join;
}
return $line.substr(0, $width);
View
4 lib/Form/Types.pm
@@ -0,0 +1,4 @@
+module Form::Types;
+
+enum Justify is export <left right centre full>;
+enum Alignment is export <top middle bottom>;
View
18 t/04-parseactions.t
@@ -2,11 +2,12 @@
use v6;
use Test;
-plan 32;
+plan 38;
use Form::Grammar;
use Form::Actions;
use Form::Field;
+use Form::Types;
my $actions = Form::Actions.new;
ok($actions, "Form::Actions constructs");
@@ -21,9 +22,8 @@ ok($field ~~ Form::Field::Text, "Parse returned Form::Field::Textresult object (
ok($field.block, "Parsed left block field block state is true");
ok($field.width == 5, "Parsed left block field width is correct");
-# RAKUDO: enable these after Rakudo lets us talk to enums in another module
-#ok($field.alignment == Form::TextFormatting::Alignment::top, "Parsed left block field alignment is top");
-#ok($field.justify == Form::TextFormatting::Justify::left, "Parsed left block field justification is left");
+ok($field.alignment == Alignment::top, "Parsed left block field alignment is top");
+ok($field.justify == Justify::left, "Parsed left block field justification is left");
my $r-result = Form::Grammar.parse('{>>>>>>}', :actions($actions));
ok($r-result, "Parse right line field with actions succeeds");
@@ -32,22 +32,20 @@ my $r-field = $r-result.ast[0];
ok($r-field ~~ Form::Field::Text, "Parse returned a Form::Field::Textresult object");
ok(!$r-field.block, "Parsed right line field object is not a block");
ok($r-field.width == 8, "Parsed right line field width is correct");
-#ok($field.alignment == Form::TextFormatting::Alignment::top, "Parsed right line field alignment is top");
-#ok($field.justify == Form::TextFormatting::Justify::right, "Parsed right line field justification is left");
+ok($r-field.alignment == Alignment::top, "Parsed right line field alignment is top");
+ok($r-field.justify == Justify::right, "Parsed right line field justification is right ({$field.justify})");
$r-result = Form::Grammar.parse('{><}', :actions($actions));
ok($r-result, "Parse centred line field with actions succeeds");
ok($r-result.ast[0] ~~ Form::Field::Text, "Parse centred line field result object is Text");
ok($r-result.ast[0].width == 4, "Parsed centred line field has correct width");
-# RAKUDO: enable when we can use enums from another module
-#ok($r-result.ast[0].justify == Form::TextFormatting::Justify::centre, "Parsed centred line field justification is centre");
+ok($r-result.ast[0].justify == Justify::centre, "Parsed centred line field justification is centre");
$r-result = Form::Grammar.parse('{[[]}', :actions($actions));
ok($r-result, "Parse justified line field with actions succeeds");
ok($r-result.ast[0] ~~ Form::Field::Text, "Parse justified line field result object is Text");
ok($r-result.ast[0].width == 5, "Parsed justified line field has correct width");
-# RAKUDO: enable when we can use enums from another module
-#ok($r-result.ast[0].justify == Form::TextFormatting::Justify::full, "Parsed centred line field justification is centre");
+ok($r-result.ast[0].justify == Justify::full, "Parsed justified line field justification is full");
View
1 t/05-fieldformat.t
@@ -5,6 +5,7 @@ use Test;
plan 22;
use Form::Field;
+use Form::Types;
my $right-text-field = Form::Field::Text.new(
:block(Bool::False),

0 comments on commit 3f5926f

Please sign in to comment.