New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Revision.t in branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/EXTERNAL/fcm/t/Fcm/Keyword/Loader/Config – NEMO

source: branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/EXTERNAL/fcm/t/Fcm/Keyword/Loader/Config/Revision.t @ 5984

Last change on this file since 5984 was 5984, checked in by timgraham, 8 years ago

Clear svn keywords to allow use with fcm make

File size: 2.2 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Fcm::Config;
7use Fcm::Keyword::Entries;
8use Test::More qw{no_plan};
9
10my %VALUE_OF = (
11    bar => {
12        'bar3'    => 3,
13        'bar3.1'  => 31,
14        'bar3.14' => 314,
15    },
16    baz => {
17        'bear'   => 4,
18        'bee'    => 6,
19        'spider' => 8,
20    },
21);
22
23main();
24
25sub main {
26    my $class = 'Fcm::Keyword::Loader::Config::Revision';
27    use_ok($class);
28    test_constructor($class);
29    test_load_to($class);
30}
31
32################################################################################
33# Tests simple usage of the constructor
34sub test_constructor {
35    my ($class) = @_;
36    my $prefix = "constructor";
37    my $loader = $class->new({namespace => 'namespace'});
38    isa_ok($loader, $class);
39    is($loader->get_namespace(), 'namespace', "$prefix: get_namespace()");
40    is($loader->get_source(), 'Fcm::Config', "$prefix: get_source()");
41}
42
43################################################################################
44# Tests loading to an Fcm::Keyword::Entries object
45sub test_load_to {
46    my ($class) = @_;
47    my $prefix = 'load to';
48    my $config = Fcm::Config->instance();
49    for my $key (keys(%VALUE_OF)) {
50        for my $rev_key (keys(%{$VALUE_OF{$key}})) {
51            my $value = $VALUE_OF{$key}{$rev_key};
52            $config->setting(['URL_REVISION', uc($key), uc($rev_key)], $value);
53        }
54        my $entries = Fcm::Keyword::Entries->new();
55        my $loader = $class->new({namespace => $key});
56        isnt($loader->load_to($entries), 0, "$prefix: number loaded");
57        for my $rev_key (keys(%{$VALUE_OF{$key}})) {
58            my $entry = $entries->get_entry_by_key($rev_key);
59            my $value = $VALUE_OF{$key}{$rev_key};
60            if ($entry) {
61                is(
62                    $entry->get_key(),
63                    uc($rev_key),
64                    "$prefix: by key: $rev_key",
65                );
66                is($entry->get_value(), $value, "$prefix: by value: $rev_key");
67                is(
68                    $entries->get_entry_by_value($value),
69                    $entry,
70                    "$prefix: by key: $key: object",
71                );
72            }
73            else {
74                fail("$prefix: by key: $rev_key");
75            }
76        }
77    }
78}
79
80__END__
Note: See TracBrowser for help on using the repository browser.