Permalink
Browse files

identifier_output_method affects ident output

  • Loading branch information...
1 parent 7a35f8e commit 9766314e3540686dc583bae337c6108dec182b0c @masak committed Sep 19, 2009
Showing with 47 additions and 5 deletions.
  1. +22 −5 lib/Squerl.pm
  2. +25 −0 t/squerl/02-dataset.t
View
@@ -6,7 +6,7 @@ class Squerl::Dataset does Positional {
# RAKUDO: Cannot type this attribute as Bool
has $.quote_identifiers is rw;
has Str $.identifier_input_method is rw;
- has Str $.identifier_output_method;
+ has Str $.identifier_output_method is rw;
multi method new($db, :$quote_identifiers,
:$identifier_input_method, :$identifier_output_method,
@@ -37,13 +37,30 @@ class Squerl::Dataset does Positional {
}
method literal($name is copy) {
- given $!identifier_input_method {
- when 'upcase' | 'uc' { $name .= uc }
- when 'downcase' | 'lc' { $name .= lc }
- when 'reverse' | 'flip' { $name .= flip }
+ $!identifier_input_method
+ = { 'upcase' => 'uc', 'downcase' => 'lc',
+ 'reverse' => 'flip' }.{$!identifier_input_method}
+ // $!identifier_input_method;
+ if $!identifier_input_method {
+ # RAKUDO: Would like to have spaces around the operator:
+ # [perl #69204]
+ $name.="$!identifier_input_method";
}
$!quote_identifiers ?? qq["$name"] !! $name;
}
+
+ method output_identifier($name is copy) {
+ $!identifier_output_method
+ = { 'upcase' => 'uc', 'downcase' => 'lc',
+ 'reverse' => 'flip' }.{$!identifier_output_method}
+ // $!identifier_output_method;
+ if $!identifier_output_method {
+ # RAKUDO: Would like to have spaces around the operator:
+ # [perl #69204]
+ $name.="$!identifier_output_method";
+ }
+ $name;
+ }
}
class Squerl::Database {
View
@@ -104,4 +104,29 @@ $dataset = Squerl::Dataset.new('db');
'identifier_input_method changes literalization of identifiers VI';
}
+{
+ is $dataset.output_identifier('at_b_C'), 'at_b_C',
+ 'identifier_output_method changes identifiers returned from the db I';
+
+ $dataset.identifier_output_method = 'upcase';
+ is $dataset.output_identifier('at_b_C'), 'AT_B_C',
+ 'identifier_output_method changes identifiers returned from the db II';
+ $dataset.identifier_output_method = 'downcase';
+ is $dataset.output_identifier('at_b_C'), 'at_b_c',
+ 'identifier_output_method changes identifiers returned from the db III';
+ $dataset.identifier_output_method = 'reverse';
+ is $dataset.output_identifier('at_b_C'), 'C_b_ta',
+ 'identifier_output_method changes identifiers returned from the db IV';
+
+ $dataset.identifier_output_method = 'uc';
+ is $dataset.output_identifier('at_b_C'), 'AT_B_C',
+ 'identifier_output_method changes identifiers returned from the db V';
+ $dataset.identifier_output_method = 'lc';
+ is $dataset.output_identifier('at_b_C'), 'at_b_c',
+ 'identifier_output_method changes identifiers returned from the db VI';
+ $dataset.identifier_output_method = 'flip';
+ is $dataset.output_identifier('at_b_C'), 'C_b_ta',
+ 'identifier_output_method changes identifiers returned from the db VII';
+}
+
done_testing;

0 comments on commit 9766314

Please sign in to comment.