lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] git commit: Perl bindings for new CFCParcel methods
Date Mon, 17 Mar 2014 20:30:24 GMT
Repository: lucy-clownfish
Updated Branches:
  refs/heads/explicit-dependencies-wip2 b7189acf0 -> c3585a3d1


Perl bindings for new CFCParcel methods


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/c3585a3d
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c3585a3d
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c3585a3d

Branch: refs/heads/explicit-dependencies-wip2
Commit: c3585a3d1f985507c1cea77b01e712e62958265b
Parents: b7189ac
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Mon Mar 17 21:28:34 2014 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Mar 17 21:28:34 2014 +0100

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC.xs | 63 +++++++++++++++++-----
 compiler/perl/t/403-parcel.t       | 93 ++++++++++++++++++++++++++++++++-
 2 files changed, 143 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c3585a3d/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs
index fe23b86..daa2b35 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -1135,6 +1135,35 @@ PPCODE:
     CFCParcel_add_inherited_parcel(self, inherited);
 
 void
+check_prereqs(self)
+    CFCParcel *self;
+PPCODE:
+    CFCParcel_check_prereqs(self);
+
+int
+has_prereq(self, parcel)
+    CFCParcel *self;
+    CFCParcel *parcel;
+CODE:
+    RETVAL = CFCParcel_has_prereq(self, parcel);
+OUTPUT: RETVAL
+
+void
+add_struct_sym(self, struct_sym)
+    CFCParcel  *self;
+    const char *struct_sym;
+PPCODE:
+    CFCParcel_add_struct_sym(self, struct_sym);
+
+CFCParcel*
+lookup_struct_sym(self, struct_sym)
+    CFCParcel  *self;
+    const char *struct_sym;
+CODE:
+    RETVAL = CFCParcel_lookup_struct_sym(self, struct_sym);
+OUTPUT: RETVAL
+
+void
 reap_singletons(...)
 PPCODE:
     CHY_UNUSED_VAR(items);
@@ -1144,15 +1173,17 @@ void
 _set_or_get(self, ...)
     CFCParcel *self;
 ALIAS:
-    get_name   = 2
-    get_cnick  = 4
-    get_prefix = 6
-    get_Prefix = 8
-    get_PREFIX = 10
-    get_version = 12
-    included    = 14
-    prereq_parcels    = 16
-    inherited_parcels = 18
+    get_name          = 2
+    get_cnick         = 4
+    get_prefix        = 6
+    get_Prefix        = 8
+    get_PREFIX        = 10
+    get_version       = 12
+    get_prereqs       = 14
+    included          = 16
+    required          = 18
+    prereq_parcels    = 20
+    inherited_parcels = 22
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
@@ -1186,16 +1217,24 @@ PPCODE:
                 retval = S_cfcbase_to_perlref(value);
             }
             break;
-        case 14:
+        case 14: {
+                CFCPrereq **prereqs = CFCParcel_get_prereqs(self);
+                retval = S_array_of_cfcbase_to_av((CFCBase**)prereqs);
+            }
+            break;
+        case 16:
             retval = newSViv(CFCParcel_included(self));
             break;
-        case 16: {
+        case 18:
+            retval = newSViv(CFCParcel_required(self));
+            break;
+        case 20: {
                 CFCParcel **parcels = CFCParcel_prereq_parcels(self);
                 retval = S_array_of_cfcbase_to_av((CFCBase**)parcels);
                 FREEMEM(parcels);
             }
             break;
-        case 18: {
+        case 22: {
                 CFCParcel **parcels = CFCParcel_inherited_parcels(self);
                 retval = S_array_of_cfcbase_to_av((CFCBase**)parcels);
                 FREEMEM(parcels);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c3585a3d/compiler/perl/t/403-parcel.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/403-parcel.t b/compiler/perl/t/403-parcel.t
index fb23b08..de93c21 100644
--- a/compiler/perl/t/403-parcel.t
+++ b/compiler/perl/t/403-parcel.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 21;
+use Test::More tests => 41;
 use File::Spec::Functions qw( catfile );
 
 BEGIN { use_ok('Clownfish::CFC::Model::Prereq') }
@@ -113,3 +113,94 @@ is( $thing->get_prefix, 'crust_', 'get_prefix with parcel' );
 is( $thing->get_Prefix, 'Crust_', 'get_Prefix with parcel' );
 is( $thing->get_PREFIX, 'CRUST_', 'get_PREFIx with parcel' );
 
+Clownfish::CFC::Model::Parcel->reap_singletons();
+
+{
+    my $json = qq|
+        {
+            "name": "Crustacean",
+            "version": "v0.1.0",
+            "prerequisites": {
+                "Clownfish": null,
+                "Arthropod": "v30.104.5"
+            }
+        }
+    |;
+    my $parcel = Clownfish::CFC::Model::Parcel->new_from_json( json => $json );
+
+    my $prereqs = $parcel->get_prereqs;
+    isa_ok( $prereqs, 'ARRAY', 'prereqs' );
+    is( scalar(@$prereqs), 2, 'number of prereqs' );
+
+    my $cfish = $prereqs->[0];
+    isa_ok( $cfish, 'Clownfish::CFC::Model::Prereq', 'prereqs[0]');
+    is( $cfish->get_name, 'Clownfish', 'prereqs[0] name');
+    my $v0 = Clownfish::CFC::Model::Version->new( vstring => 'v0' );
+    is( $cfish->get_version->compare_to($v0), 0, 'prereqs[0] version' );
+
+    my $apod = $prereqs->[1];
+    isa_ok( $apod, 'Clownfish::CFC::Model::Prereq', 'prereqs[1]');
+    is( $apod->get_name, 'Arthropod', 'prereqs[1] name');
+    my $v30_104_5 = Clownfish::CFC::Model::Version->new(
+        vstring => 'v30.104.5',
+    );
+    is( $apod->get_version->compare_to($v30_104_5), 0, 'prereqs[1] version' );
+}
+
+{
+    my $foo = Clownfish::CFC::Model::Parcel->new(
+        name        => 'Foo',
+        is_included => 1,
+    );
+    $foo->register;
+
+    my $cfish_version = Clownfish::CFC::Model::Version->new(
+        vstring => 'v0.8.7',
+    );
+    my $cfish = Clownfish::CFC::Model::Parcel->new(
+        name        => 'Clownfish',
+        version     => $cfish_version,
+        is_included => 1,
+    );
+    $cfish->register;
+
+    my $json = qq|
+        {
+            "name": "Crustacean",
+            "version": "v0.1.0",
+            "prerequisites": {
+                "Clownfish": "v0.8.5",
+            }
+        }
+    |;
+    my $crust = Clownfish::CFC::Model::Parcel->new_from_json( json => $json );
+    $crust->register;
+
+    $crust->check_prereqs;
+    ok( !$foo->required, 'parcel not required' );
+    ok( $cfish->required, 'prereq required' );
+    ok( $crust->required, 'self required' );
+
+    my $prereq_parcels = $crust->prereq_parcels;
+    isa_ok( $prereq_parcels, 'ARRAY', 'prereq_parcels' );
+    is( scalar(@$prereq_parcels), 1, 'number of prereq_parcels' );
+    is( $prereq_parcels->[0]->get_name, 'Clownfish', 'prereq_parcels[0]');
+
+    ok( $crust->has_prereq($cfish), 'has_prereq' );
+    ok( $crust->has_prereq($crust), 'has_prereq self' );
+    ok( !$crust->has_prereq($foo), 'has_prereq false' );
+
+    $cfish->add_struct_sym('Swim');
+    $crust->add_struct_sym('Pinch');
+    $foo->add_struct_sym('Bar');
+    my $found;
+    $found = $crust->lookup_struct_sym('Swim');
+    is( $found->get_name, 'Clownfish', 'lookup_struct_sym prereq' );
+    $found = $crust->lookup_struct_sym('Pinch');
+    is( $found->get_name, 'Crustacean', 'lookup_struct_sym self' );
+    $found = $crust->lookup_struct_sym('Bar');
+    ok( !$found, 'lookup_struct_sym other' );
+
+    Clownfish::CFC::Model::Parcel->reap_singletons();
+}
+


Mime
View raw message