Skip to content
This repository
tree: 444b489e68
Fetching contributors…

Cannot retrieve contributors at this time

file 132 lines (95 sloc) 3.574 kb
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
#!/usr/bin/perl -w
#
# This file is part of the Kinetic Rules Engine (KRE)
# Copyright (C) 2007-2011 Kynetx, Inc.
#
# KRE is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
use lib qw(/web/lib/perl);
use strict;

use Test::More;
use Test::LongString;

use APR::URI;
use APR::Pool ();

use Data::Dumper;

# most Kyentx modules require this
use Log::Log4perl qw(get_logger :levels);
Log::Log4perl->easy_init($INFO);
#Log::Log4perl->easy_init($DEBUG);

use Kynetx::Test qw/:all/;
use Kynetx::Environments qw/:all/;


plan tests => 19;


my $e = empty_rule_env();

$e = extend_rule_env(['a','b'],[1,2], $e);

is(lookup_rule_env('a',$e), 1, 'lookup a');
is(lookup_rule_env('b',$e), 2, 'lookup b');
#diag Dumper($e);

is(lookup_rule_env('c',$e), undef, 'lookup c');

my $e1 = extend_rule_env(['a'], [3], $e);
is(lookup_rule_env('a',$e1),3, 'lookup a in e1 after extending');
is(lookup_rule_env('b',$e1),2, 'lookup b in e1 after extending');

my $e2 = extend_rule_env(['a'], [4], $e);
is(lookup_rule_env('a',$e2),4, 'lookup a in e2 after extending');

is(lookup_rule_env('a',$e1),3, 'is a still 3?');
is(lookup_rule_env('a',$e),1, 'is a still 1?');

my $e3 = extend_rule_env('c', [3], $e);

#diag Dumper($e3);
is_deeply(lookup_rule_env('c',$e3),[3], 'lookup an array in e3 after extending');

my $e4 = extend_rule_env(['c'], [[3]], $e);

#diag Dumper($e3);
is_deeply(lookup_rule_env('c',$e4),[3], 'lookup an array in e3 after extending');


my $e5 = extend_rule_env({'a' => 5}, $e);
is(lookup_rule_env('a',$e5),5, 'lookup a in e5 after extending with a hash');

my $e6 = extend_rule_env({'a' => [5]}, $e);
is_deeply(lookup_rule_env('a',$e6),[5], 'lookup an array in e6 after extending with hash');


my $e7 = extend_rule_env({'a' => 5, 'd' => '5'}, $e);
is(lookup_rule_env('a',$e7),5, 'lookup a in e7 after extending with a hash');
is(lookup_rule_env('d',$e7),'5', 'lookup d in e7 after extending with a hash');


my $flat_e = {
           'a' => 1,
           'b' => 2,
'___order' => ['a','b']
         };

is_deeply(flatten_env($e), $flat_e, "Flattening creates correct scope for e");

my $flat_e1 = {
           'a' => 3,
           'b' => 2,
'___order' => ['b','a']
         };

is_deeply(flatten_env($e1), $flat_e1, "Flattening creates correct scope for e1");

my $flat_e2 = {
           'a' => 4,
           'b' => 2,
'___order' => ['b','a']
         };

is_deeply(flatten_env($e2), $flat_e2, "Flattening creates correct scope for e2");
#diag(Dumper(flatten_env($e2)));

my $flat_e3 = {
           'a' => 1,
           'b' => 2,
'c' => [3],
'___order' => ['a','b','c']
         };

is_deeply(flatten_env($e3), $flat_e3, "Flattening creates correct scope for e3");
#diag(Dumper(flatten_env($e3)));

my $flat_e6 = {
           'b' => 2,
'a' => [5],
'___order' => ['b','a']
         };

is_deeply(flatten_env($e6), $flat_e6, "Flattening creates correct scope for e6");
#diag(Dumper(flatten_env($e3)));


1;
Something went wrong with that request. Please try again.