diff --git a/Changes b/Changes index ec2cc0c7..cde81156 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,8 @@ Revision history for Red - Track in-place mutations of Positional, Associative and Json columns when saving. - Snapshot mutable collection values deeply and retain independent old values for dirty tracking. - Refresh snapshots on clean-up and partial refresh without marking unchanged collections dirty. + - Return explicitly bound drivers directly and replace literal name separators without regex matching. + - Retain formatter coercions, repeated separators, Unicode and embedded control characters. - schema: add named CHECK and PostgreSQL EXCLUDE constraints with driver selection - indexes: support access methods, per-key operator classes and partial predicates - pg: add range constructors and native range/regex expression helpers diff --git a/lib/Red/DB.rakumod b/lib/Red/DB.rakumod index 86759567..578a0d34 100644 --- a/lib/Red/DB.rakumod +++ b/lib/Red/DB.rakumod @@ -4,9 +4,8 @@ use X::Red::Exceptions; #| Returns the database connection sub get-RED-DB is export { - with $*RED-DB { - .return - } + my $driver = $*RED-DB; + return $driver if $driver.defined; if %*RED-DEFAULT-DRIVERS.defined and %*RED-DEFAULT-DRIVERS:exists { return %*RED-DEFAULT-DRIVERS } diff --git a/lib/Red/Utils.rakumod b/lib/Red/Utils.rakumod index 04880bdc..29c7db24 100644 --- a/lib/Red/Utils.rakumod +++ b/lib/Red/Utils.rakumod @@ -3,9 +3,9 @@ use Red::AST::Unary; =head2 Red::Utils #| Accepts a string and converts snake case (`foo_bar`) into kebab case (`foo-bar`). -sub snake-to-kebab-case(Str() $_ --> Str) is export { S:g/'_'/-/ } +sub snake-to-kebab-case(Str() $_ --> Str) is export { .subst('_', '-', :g) } #| Accepts a string and converts kebab case (`foo-bar`) into snake case (`foo_bar`). -sub kebab-to-snake-case(Str() $_ --> Str) is export { S:g/'-'/_/ } +sub kebab-to-snake-case(Str() $_ --> Str) is export { .subst('-', '_', :g) } #| Accepts a string and converts camel case (`fooBar`) into snake case (`foo_bar`). sub camel-to-snake-case(Str() $_ --> Str) is export { kebab-to-snake-case lc S:g/(\w)>/$0_/ } #| Accepts a string and converts camel case (`fooBar`) into kebab case (`foo-bar`). @@ -26,4 +26,4 @@ multi compare(Red::AST::So $a, Red::AST $b) { multi compare(Red::AST $a, Red::AST::So $b) { compare $a, $b.value -} \ No newline at end of file +} diff --git a/t/104-name-formatters.rakutest b/t/104-name-formatters.rakutest new file mode 100644 index 00000000..9e625903 --- /dev/null +++ b/t/104-name-formatters.rakutest @@ -0,0 +1,14 @@ +use Test; +use Red::Utils; + +for ['plain', 'plain'], ['a-b-c', 'a_b_c'], ['--a--', '__a__'], ['', ''], + ['ação-número', 'ação_número'], ["a\n-\0b", "a\n_\0b"] -> @pair { + is kebab-to-snake-case(@pair[0]), @pair[1], 'Format kebab separators'; + is snake-to-kebab-case(@pair[1]), @pair[0], 'Format snake separators'; +} +is kebab-to-snake-case('already_snake'), 'already_snake', 'Keep existing underscores'; +is snake-to-kebab-case('already-kebab'), 'already-kebab', 'Keep existing hyphens'; +is kebab-to-snake-case(42), '42', 'Kebab formatter retains Str coercion'; +is snake-to-kebab-case(42), '42', 'Snake formatter retains Str coercion'; + +done-testing;