File: 20_fix.t

package info (click to toggle)
libcatmandu-importer-getjson-perl 0.52-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 345; sh: 6; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 2,153 bytes parent folder | download | duplicates (4)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use strict;
use Test::More;

use Catmandu::Fix::get_json;
sub get_dry { Catmandu::Fix::get_json->new(@_, dry => 1) }

is_deeply get_dry("http://example.com/json")
    ->fix({}),
	{url => "http://example.com/json"}, 'plain URL';

is_deeply get_dry("http://example.com/json")
    ->fix({foo => "bar"}),
	{url => "http://example.com/json"}, 'plain URL, override';

is_deeply get_dry("http://example.com/json", path => "tmp.test")
    ->fix({foo => "bar"}),
	{foo => "bar", tmp => {test => {url => "http://example.com/json"}}},
    'plain URL, path';

is_deeply get_dry("http://example.com/{name}.json", vars => 'path')
    ->fix({path => { name => 'foo', foo => 'bar' }}),
    { url => "http://example.com/foo.json" },
    'URL template with variables';

is_deeply get_dry("http://example.com/{name}.json", vars => 'path')
    ->fix({path => "http://example.org/1" }),
    { }, 'URL template n/a variables';

is_deeply get_dry("http://example.com/", vars => 'path')
    ->fix({path => { name => 'foo' }}),
    { url => "http://example.com/?name=foo" },
    'URL with query variables';

is_deeply get_dry("http://example.com/some", vars => 'path')
    ->fix({path => "/path" }),
    { url => 'http://example.com/some/path' },
    'URL with path';

is_deeply get_dry("http://example.com/{name}.json", vars => 'path')
    ->fix({path => "/path" }),
    { url => 'http://example.com/%7Bname%7D.json/path' },
    'URL template with path';

is_deeply get_dry("my")
    ->fix({my => "http://example.org/" }),
    { my => { url => "http://example.org/" } },
    'URL from field';

is_deeply get_dry("my", vars => 'q', path => '')
    ->fix({ my => "http://example.org/", q => '/path' }),
    { url => "http://example.org/path" },
    'URL from field, with path';

is_deeply get_dry("my", vars => 'q', path => '')
    ->fix({ my => "http://example.org/", q => { some => 42 } }),
    { url => "http://example.org/?some=42" },
    'URL from field, with vars';

is_deeply get_dry("my", vars => 'q', path => '')
    ->fix({ my => "http://example.org/{some}", q => { some => 42 } }),
    { url => "http://example.org/42" },
    'URL template from field';

done_testing;