File: internals.t

package info (click to toggle)
librt-extension-commandbymail-perl 3.00-1.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 316 kB
  • sloc: perl: 3,818; makefile: 3
file content (138 lines) | stat: -rw-r--r-- 5,477 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use strict;
use warnings;

use RT::Extension::CommandByMail::Test tests => undef, nodb => 1;

use_ok('RT::Extension::CommandByMail');

diag( "test _ParseAdditiveCommand") if $ENV{'TEST_VERBOSE'};
{
    my %res = RT::Extension::CommandByMail::_ParseAdditiveCommand({}, 0, 'Foo');
    is_deeply( \%res, {}, 'empty' );

    my $cmd = { foo => 'qwe' };
    %res = RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo');
    is_deeply(\%res, { Set => ['qwe'] }, 'simple set');

    $cmd = { foo => ['qwe', 'asd'] };
    %res = RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo');
    is_deeply(\%res, { Set => ['qwe', 'asd'] }, 'simple set with array ref');

    $cmd = { foos => 'qwe' };
    %res = RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 1, 'Foo');
    is_deeply(\%res, { Set => ['qwe'] }, 'simple set with plural form');

    $cmd = { foos => 'qwe' };
    %res = RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo');
    is_deeply(\%res, { }, 'single form shouldnt eat plural forms');

    $cmd = { foo => 'qwe', foos => 'qwe' };
    %res = RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 1, 'Foo');
    is_deeply(\%res, { Set => ['qwe', 'qwe'] }, 'set with plural and single form at the same time');

    $cmd = { foo => 'qwe', addfoo  => 'asd' };
    %res = RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo');
    is_deeply(\%res, { Set => ['qwe'], Add => ['asd'] }, 'set+add');

    $cmd = { foo => ['qwe'], addfoo  => ['asd'], delfoo => ['zxc'] };
    %res = RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo');
    is_deeply(\%res, { Set => ['qwe'], Add => ['asd'], Del => ['zxc'] }, 'set+add+del');
}

diag( "test _CompileAdditiveForCreate") if $ENV{'TEST_VERBOSE'};
{
    my @res = RT::Extension::CommandByMail::_CompileAdditiveForCreate(
        RT::Extension::CommandByMail::_ParseAdditiveCommand({}, 0, 'Foo')
    );
    is_deeply(\@res, [], 'empty');

    my $cmd = { foo => 'qwe' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForCreate(
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, ['qwe'], 'simple set');

    $cmd = { foo => 'qwe', addfoo => 'asd' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForCreate(
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, ['qwe', 'asd'], 'set+add');

    $cmd = { foo => 'qwe' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForCreate(
        Default => 'def',
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, ['qwe'], 'set+default: set overrides defaults');

    $cmd = { addfoo => 'qwe' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForCreate(
        Default => 'def',
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, ['def', 'qwe'], 'add+default: add adds to defaults');

    $cmd = { addfoo => 'qwe', delfoo => 'def' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForCreate(
        Default => 'def',
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, ['qwe'], 'add+default+del: delete default');
}

diag( "test _CompileAdditiveForUpdate") if $ENV{'TEST_VERBOSE'};
{
    my @res = RT::Extension::CommandByMail::_CompileAdditiveForUpdate(
        RT::Extension::CommandByMail::_ParseAdditiveCommand({}, 0, 'Foo')
    );
    is_deeply(\@res, [[], []], 'empty');

    my $cmd = { foo => 'qwe' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForUpdate(
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, [['qwe'],[]], 'simple set');

    $cmd = { foo => 'qwe', addfoo => 'asd' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForUpdate(
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, [['qwe', 'asd'],[]], 'set+add');

    $cmd = { foo => 'qwe' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForUpdate(
        Default => 'def',
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, [['qwe'],['def']], 'set+default: set overrides defaults');

    $cmd = { addfoo => 'qwe' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForUpdate(
        Default => 'def',
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, [['qwe'],[]], 'add+default: add adds to defaults');

    $cmd = { addfoo => 'def' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForUpdate(
        Default => 'def',
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, [[],[]], 'add current: do nothing');

    $cmd = { addfoo => 'qwe', delfoo => 'def' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForUpdate(
        Default => 'def',
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, [['qwe'],['def']], 'add+default+del: delete default');

    $cmd = { delfoo => 'qwe' };
    @res = RT::Extension::CommandByMail::_CompileAdditiveForUpdate(
        Default => 'def',
        RT::Extension::CommandByMail::_ParseAdditiveCommand($cmd, 0, 'Foo')
    );
    is_deeply(\@res, [[],[]], 'del not current: do nothing');
}

done_testing();