File: utils-parse-arguments.t

package info (click to toggle)
libnet-amazon-s3-perl 0.991-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,620 kB
  • sloc: perl: 9,906; makefile: 20
file content (96 lines) | stat: -rw-r--r-- 3,562 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!perl

use strict;
use warnings;

use FindBin;

BEGIN { require "$FindBin::Bin/test-helper-common.pl" }

use Scalar::Util;
use Net::Amazon::S3;

plan tests => 5;

sub act;

subtest "parse_arguments() " => sub {
	local *act = sub { Net::Amazon::S3::Utils->parse_arguments (@_) };

	cmp_deeply "_parse_arguments() should recognize required positional arguments" => (
		got    => { act (['bucket-arg', 'key-arg'], [qw[ bucket key ]]) },
		expect => { bucket => 'bucket-arg', key => 'key-arg' },
	);

	cmp_deeply "_parse_arguments() should recognize required positional argument specified as named argument" => (
		got    => { act (['key-arg', bucket => 'bucket-arg'], [qw[ bucket key ]]) },
		expect => { bucket => 'bucket-arg', key => 'key-arg' },
	);

	cmp_deeply "_parse_arguments() should recognize required positional argument specified as named arguments" => (
		got    => { act ([key => 'key-arg', bucket => 'bucket-arg'], [qw[ bucket key ]]) },
		expect => { bucket => 'bucket-arg', key => 'key-arg' },
	);

	cmp_deeply "_parse_arguments() should recognize required positional argument specified via configuration hash" => (
		got    => { act (['key-arg', { bucket => 'bucket-arg' }], [qw[ bucket key ]]) },
		expect => { bucket => 'bucket-arg', key => 'key-arg' },
	);

	cmp_deeply "_parse_arguments() should recognize required positional arguments specified via configuration hash" => (
		got    => { act ([{ key => 'key-arg', bucket => 'bucket-arg' }], [qw[ bucket key ]]) },
		expect => { bucket => 'bucket-arg', key => 'key-arg' },
	);

	cmp_deeply "_parse_arguments() should recognize combination of named arguments and configuration hash" => (
		got    => { act ([ key => 'key-arg', { bucket => 'bucket-arg' }], [qw[ bucket key ]]) },
		expect => { bucket => 'bucket-arg', key => 'key-arg' },
	);

	cmp_deeply "_parse_arguments() should recognize alias of required positional argument" => (
		got    => { act (['key-arg', { name => 'bucket-arg' }], [qw[ bucket key ]], { name => 'bucket' }) },
		expect => { bucket => 'bucket-arg', key => 'key-arg' },
	);
};

subtest "parse_arguments_with_bucket()" => sub {
	local *act = sub { Net::Amazon::S3::Utils->parse_arguments_with_bucket (@_) };

	cmp_deeply "should accept bucket as positional argument" => (
		got    => { act (['bucket-arg', optional => 'optional-arg']) },
		expect => { bucket => 'bucket-arg', optional => 'optional-arg' },
	);

	cmp_deeply "should accept bucket as named argument" => (
		got    => { act ([bucket => 'bucket-arg', optional => 'optional-arg']) },
		expect => { bucket => 'bucket-arg', optional => 'optional-arg' },
	);

	cmp_deeply "should accept bucket's alias" => (
		got    => { act ([name => 'bucket-arg', optional => 'optional-arg']) },
		expect => { bucket => 'bucket-arg', optional => 'optional-arg' },
	);
};

subtest "parse_arguments_with_bucket_and_object()" => sub {
	local *act = sub { Net::Amazon::S3::Utils->parse_arguments_with_bucket_and_object (@_) };

	cmp_deeply "should accept bucket and key as positional arguments" => (
		got    => { act (['bucket-arg', 'key-arg', optional => 'optional-arg']) },
		expect => { bucket => 'bucket-arg', key => 'key-arg', optional => 'optional-arg' },
	);
};

subtest "parse_arguments_with_object()" => sub {
	local *act = sub { Net::Amazon::S3::Utils->parse_arguments_with_object (@_) };

	cmp_deeply "should accept key as positional arguments" => (
		got    => { act (['key-arg', optional => 'optional-arg']) },
		expect => { key => 'key-arg', optional => 'optional-arg' },
	);
};

had_no_warnings;

done_testing;