File: Catmandu-Fix-move_field.t

package info (click to toggle)
libcatmandu-perl 1.2024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,552 kB
  • sloc: perl: 17,037; makefile: 24; sh: 1
file content (46 lines) | stat: -rw-r--r-- 1,320 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use Test::Exception;

my $pkg;

BEGIN {
    $pkg = 'Catmandu::Fix::move_field';
    use_ok $pkg;
}

is_deeply $pkg->new('old', 'new')->fix({old => 'old'}), {new => 'old'},
    "move field at root";

is_deeply $pkg->new('old', 'deeply.nested.$append.new')->fix({old => 'old'}),
    {deeply => {nested => [{new => 'old'}]}},
    "move field creates intermediate path";

is_deeply $pkg->new('old', 'new.$prepend')
    ->fix({old => 'hello', new => ['world']}), {new => ['hello', 'world']},
    "move field creates intermediate path";

is_deeply $pkg->new('old', 'new.$append')
    ->fix({old => 'hello', new => ['world']}), {new => ['world', 'hello']},
    "move field creates intermediate path";

is_deeply $pkg->new('nested', '.')
    ->fix({nested => {bar => 'baz'}, foo => 'bar'}), {bar => 'baz'},
    "replace root";

is_deeply $pkg->new('nested', '.')->fix({nested => [1, 2, 3], foo => 'bar'}),
    [1, 2, 3], "replace root";

is_deeply $pkg->new("''", 'test')->fix({'' => 'foo'}), {test => 'foo'},
    "move empty field";

is_deeply $pkg->new("test", "''")->fix({test => 'foo'}), {'' => 'foo'},
    "move to empty field";

is_deeply $pkg->new("test", "x.''")->fix({test => 'foo'}),
    {x => {'' => 'foo'}}, "move to nested empty field";

done_testing;