aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-07-02 22:11:58 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-07-02 22:11:58 +0000
commite66949024802ca11a21ae92c2120b2cc50ef59d7 (patch)
treeb3fc187e0cca9cd91d901f640a154ce17486ff2f
parent7e19e2f4726970ca3effcce44af30cc236a5f6a5 (diff)
downloadpaludis-e66949024802ca11a21ae92c2120b2cc50ef59d7.tar.gz
paludis-e66949024802ca11a21ae92c2120b2cc50ef59d7.tar.xz
(ruby) Add metadata to PackageID.
-rw-r--r--ruby/package_id.cc404
-rw-r--r--ruby/package_id_TEST.rb259
-rwxr-xr-xruby/package_id_TEST_setup.sh16
3 files changed, 644 insertions, 35 deletions
diff --git a/ruby/package_id.cc b/ruby/package_id.cc
index 5f7db3b..b7b9ac9 100644
--- a/ruby/package_id.cc
+++ b/ruby/package_id.cc
@@ -18,7 +18,10 @@
*/
#include <paludis_ruby.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
#include <paludis/package_id.hh>
+#include <paludis/metadata_key.hh>
#include <ruby.h>
using namespace paludis;
@@ -30,6 +33,116 @@ namespace
{
static VALUE c_package_id;
static VALUE c_package_id_canonical_form;
+ static VALUE c_metadata_key;
+ static VALUE c_metadata_package_id_key;
+ static VALUE c_metadata_string_key;
+ static VALUE c_metadata_time_key;
+ static VALUE c_metadata_contents_key;
+ static VALUE c_metadata_keyword_name_collection_key;
+ static VALUE c_metadata_use_flag_name_collection_key;
+ static VALUE c_metadata_iuse_flag_collection_key;
+ static VALUE c_metadata_inherited_collection_key;
+ static VALUE c_metadata_key_type;
+
+ struct V :
+ ConstVisitor<MetadataKeyVisitorTypes>
+ {
+ VALUE value;
+ tr1::shared_ptr<const MetadataKey> mm;
+
+ V(tr1::shared_ptr<const MetadataKey> _m) :
+ mm(_m)
+ {
+ }
+
+ void visit(const MetadataPackageIDKey &)
+ {
+ value = Data_Wrap_Struct(c_metadata_package_id_key, 0, &Common<tr1::shared_ptr<const MetadataPackageIDKey> >::free,
+ new tr1::shared_ptr<const MetadataPackageIDKey>(tr1::static_pointer_cast<const MetadataPackageIDKey>(mm)));
+ }
+
+ void visit(const MetadataStringKey &)
+ {
+ value = Data_Wrap_Struct(c_metadata_string_key, 0, &Common<tr1::shared_ptr<const MetadataStringKey> >::free,
+ new tr1::shared_ptr<const MetadataStringKey>(tr1::static_pointer_cast<const MetadataStringKey>(mm)));
+ }
+
+ void visit(const MetadataTimeKey &)
+ {
+ value = Data_Wrap_Struct(c_metadata_time_key, 0, &Common<tr1::shared_ptr<const MetadataTimeKey> >::free,
+ new tr1::shared_ptr<const MetadataTimeKey>(tr1::static_pointer_cast<const MetadataTimeKey>(mm)));
+ }
+
+ void visit(const MetadataContentsKey &)
+ {
+ value = Data_Wrap_Struct(c_metadata_contents_key, 0, &Common<tr1::shared_ptr<const MetadataContentsKey> >::free,
+ new tr1::shared_ptr<const MetadataContentsKey>(tr1::static_pointer_cast<const MetadataContentsKey>(mm)));
+ }
+
+ void visit(const MetadataCollectionKey<KeywordNameCollection> &)
+ {
+ value = Data_Wrap_Struct(c_metadata_keyword_name_collection_key, 0, &Common<tr1::shared_ptr<const MetadataCollectionKey<KeywordNameCollection> > >::free,
+ new tr1::shared_ptr<const MetadataCollectionKey<KeywordNameCollection> >(tr1::static_pointer_cast<const MetadataCollectionKey<KeywordNameCollection> >(mm)));
+ }
+
+ void visit(const MetadataCollectionKey<UseFlagNameCollection> &)
+ {
+ value = Data_Wrap_Struct(c_metadata_use_flag_name_collection_key, 0, &Common<tr1::shared_ptr<const MetadataCollectionKey<UseFlagNameCollection> > >::free,
+ new tr1::shared_ptr<const MetadataCollectionKey<UseFlagNameCollection> >(tr1::static_pointer_cast<const MetadataCollectionKey<UseFlagNameCollection> >(mm)));
+ }
+
+ void visit(const MetadataCollectionKey<IUseFlagCollection> &)
+ {
+ value = Data_Wrap_Struct(c_metadata_iuse_flag_collection_key, 0, &Common<tr1::shared_ptr<const MetadataCollectionKey<IUseFlagCollection> > >::free,
+ new tr1::shared_ptr<const MetadataCollectionKey<IUseFlagCollection> >(tr1::static_pointer_cast<const MetadataCollectionKey<IUseFlagCollection> >(mm)));
+ }
+
+ void visit(const MetadataCollectionKey<InheritedCollection> &)
+ {
+ value = Data_Wrap_Struct(c_metadata_inherited_collection_key, 0, &Common<tr1::shared_ptr<const MetadataCollectionKey<InheritedCollection> > >::free,
+ new tr1::shared_ptr<const MetadataCollectionKey<InheritedCollection> >(tr1::static_pointer_cast<const MetadataCollectionKey<InheritedCollection> >(mm)));
+ }
+
+ void visit(const MetadataSpecTreeKey<LicenseSpecTree> &)
+ {
+ value = Qnil;
+ }
+
+ void visit(const MetadataSpecTreeKey<ProvideSpecTree> &)
+ {
+ value = Qnil;
+ }
+
+ void visit(const MetadataSpecTreeKey<DependencySpecTree> &)
+ {
+ value = Qnil;
+ }
+
+ void visit(const MetadataSpecTreeKey<RestrictSpecTree> &)
+ {
+ value = Qnil;
+ }
+
+ void visit(const MetadataSpecTreeKey<URISpecTree> &)
+ {
+ value = Qnil;
+ }
+ };
+
+ VALUE
+ metadata_key_to_value(tr1::shared_ptr<const MetadataKey> m)
+ {
+ try
+ {
+ V v(m);
+ m->accept(v);
+ return v.value;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
/*
* call-seq:
@@ -54,21 +167,37 @@ namespace
* Our slot
*/
/*
- * Document-method: description
+ * Document-method: name
*
* call-seq:
* name -> String
*
* Our name
*/
- template <typename T_, const T_ (PackageID::* m_) () const>
+ /*
+ * Document-method: raw_name
+ *
+ * call-seq:
+ * raw_name -> String
+ *
+ * Our raw name
+ */
+ /*
+ * Document-method: human_name
+ *
+ * call-seq:
+ * human_name -> String
+ *
+ * Our human name
+ */
+ template <typename T_, typename S_, const T_ (S_::* m_) () const>
struct BaseValue
{
static VALUE
fetch(VALUE self)
{
- tr1::shared_ptr<const PackageID> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ tr1::shared_ptr<const S_> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const S_>, self_ptr);
return rb_str_new2(stringify(((**self_ptr).*m_)()).c_str());
}
};
@@ -117,6 +246,104 @@ namespace
return repository_to_value((*self_ptr)->repository());
}
+ /*
+ * Document-method: keywords_key
+ *
+ * call-seq:
+ * keywords_key -> MetadataCollectionKey
+ *
+ * Our keywords
+ */
+ /*
+ * Document-method: use_key
+ *
+ * call-seq:
+ * use_key -> MetadataCollectionKey
+ *
+ * Our use flags
+ */
+ /*
+ * Document-method: iuse_key
+ *
+ * call-seq:
+ * iuse_key -> MetadataCollectionKey
+ *
+ * Our iuse flags
+ */
+ /*
+ * Document-method: inherited_key
+ *
+ * call-seq:
+ * inherited_key -> MetadataCollectionKey
+ *
+ * Our inherited
+ */
+ /*
+ * Document-method: short_description_key
+ *
+ * call-seq:
+ * short_description_key -> MetadataStringKey
+ *
+ * Our short description
+ */
+ /*
+ * Document-method: long_description_key
+ *
+ * call-seq:
+ * long_description_key -> MetadataStringKey
+ *
+ * Our long description
+ */
+ /*
+ * Document-method: contents_key
+ *
+ * call-seq:
+ * contents_key -> MetadataContentsKey
+ *
+ * Our Contents
+ */
+ /*
+ * Document-method: installed_time_key
+ *
+ * call-seq:
+ * installed_time_key -> MetadataTimeKey
+ *
+ * Our installed time
+ */
+ /*
+ * Document-method: source_origin_key
+ *
+ * call-seq:
+ * source_origin_key -> MetadataStringKey
+ *
+ * Our source origin repository
+ */
+ /*
+ * Document-method: binary_origin_key
+ *
+ * call-seq:
+ * binary_origin_key -> MetadataStringKey
+ *
+ * Our binary origin repository
+ */
+ template <typename T_, const tr1::shared_ptr<const T_> (PackageID::* m_) () const>
+ struct KeyValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ tr1::shared_ptr<const PackageID> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ tr1::shared_ptr<const MetadataKey> ptr = (((**self_ptr).*m_)());
+
+ if (ptr)
+ {
+ return metadata_key_to_value(((**self_ptr).*m_)());
+ }
+ return Qnil;
+ }
+ };
+
VALUE
package_id_equal(VALUE self, VALUE other)
{
@@ -125,6 +352,71 @@ namespace
return (**self_ptr == *value_to_package_id(other));
}
+ /*
+ * call-seq:
+ * type -> MetadataKeyType
+ *
+ * Our significance to a user.
+ */
+ VALUE
+ metadata_key_type(VALUE self) {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return INT2FIX((*self_ptr)->type());
+ }
+
+ /*
+ * call-seq:
+ * value
+ *
+ * Our Value.
+ * */
+ VALUE
+ metadata_package_id_key_value(VALUE self) {
+ tr1::shared_ptr<const MetadataPackageIDKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataPackageIDKey>, self_ptr);
+ return package_id_to_value((*self_ptr)->value());
+ }
+
+ VALUE
+ metadata_string_key_value(VALUE self) {
+ tr1::shared_ptr<const MetadataStringKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataStringKey>, self_ptr);
+ return rb_str_new2((*self_ptr)->value().c_str());
+ }
+
+ VALUE
+ metadata_time_key_value(VALUE self) {
+ tr1::shared_ptr<const MetadataTimeKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataTimeKey>, self_ptr);
+ return rb_time_new((*self_ptr)->value(),0);
+ }
+
+ VALUE
+ metadata_contents_key_value(VALUE self) {
+ tr1::shared_ptr<const MetadataContentsKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataContentsKey>, self_ptr);
+ if ((*self_ptr)->value())
+ return contents_to_value((*self_ptr)->value());
+ return Qnil;
+ }
+
+ template <typename T_>
+ struct CollectionValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ tr1::shared_ptr<const MetadataCollectionKey<T_> > * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataCollectionKey<T_> >, self_ptr);
+ tr1::shared_ptr<const T_> c = (*self_ptr)->value();
+ VALUE result (rb_ary_new());
+ for (typename T_::Iterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
+ rb_ary_push(result, rb_str_new2(stringify(*i).c_str()));
+ return result;
+ }
+ };
+
void do_register_package_id()
{
/*
@@ -135,17 +427,27 @@ namespace
c_package_id = rb_define_class_under(paludis_module(), "PackageID", rb_cObject);
rb_funcall(c_package_id, rb_intern("private_class_method"), 1, rb_str_new2("new"));
rb_define_method(c_package_id, "canonical_form", RUBY_FUNC_CAST(&package_id_canonical_form), 1);
- rb_define_method(c_package_id, "name", RUBY_FUNC_CAST((&BaseValue<QualifiedPackageName,&PackageID::name>::fetch)), 0);
+ rb_define_method(c_package_id, "name", RUBY_FUNC_CAST((&BaseValue<QualifiedPackageName,PackageID,&PackageID::name>::fetch)), 0);
rb_define_method(c_package_id, "version", RUBY_FUNC_CAST(&package_id_version), 0);
- rb_define_method(c_package_id, "slot", RUBY_FUNC_CAST((&BaseValue<SlotName,&PackageID::slot>::fetch)), 0);
+ rb_define_method(c_package_id, "slot", RUBY_FUNC_CAST((&BaseValue<SlotName,PackageID,&PackageID::slot>::fetch)), 0);
rb_define_method(c_package_id, "repository", RUBY_FUNC_CAST(&package_id_repository), 0);
rb_define_method(c_package_id, "eapi", RUBY_FUNC_CAST(&package_id_eapi), 0);
rb_define_method(c_package_id, "==", RUBY_FUNC_CAST(&package_id_equal), 1);
+ rb_define_method(c_package_id, "keywords_key", RUBY_FUNC_CAST((&KeyValue<MetadataCollectionKey<KeywordNameCollection>,&PackageID::keywords_key>::fetch)), 0);
+ rb_define_method(c_package_id, "use_key", RUBY_FUNC_CAST((&KeyValue<MetadataCollectionKey<UseFlagNameCollection>,&PackageID::use_key>::fetch)), 0);
+ rb_define_method(c_package_id, "iuse_key", RUBY_FUNC_CAST((&KeyValue<MetadataCollectionKey<IUseFlagCollection>,&PackageID::iuse_key>::fetch)), 0);
+ rb_define_method(c_package_id, "inherited_key", RUBY_FUNC_CAST((&KeyValue<MetadataCollectionKey<InheritedCollection>,&PackageID::inherited_key>::fetch)), 0);
+ rb_define_method(c_package_id, "short_description_key", RUBY_FUNC_CAST((&KeyValue<MetadataStringKey,&PackageID::short_description_key>::fetch)), 0);
+ rb_define_method(c_package_id, "long_description_key", RUBY_FUNC_CAST((&KeyValue<MetadataStringKey,&PackageID::long_description_key>::fetch)), 0);
+ rb_define_method(c_package_id, "contents_key", RUBY_FUNC_CAST((&KeyValue<MetadataContentsKey,&PackageID::contents_key>::fetch)), 0);
+ rb_define_method(c_package_id, "installed_time_key", RUBY_FUNC_CAST((&KeyValue<MetadataTimeKey,&PackageID::installed_time_key>::fetch)), 0);
+ rb_define_method(c_package_id, "source_origin_key", RUBY_FUNC_CAST((&KeyValue<MetadataStringKey,&PackageID::source_origin_key>::fetch)), 0);
+ rb_define_method(c_package_id, "binary_origin_key", RUBY_FUNC_CAST((&KeyValue<MetadataStringKey,&PackageID::binary_origin_key>::fetch)), 0);
/*
* Document-module: Paludis::PackageIDCanonicalForm
*
- * How to order query results.
+ * How to generate PackageID.canonical_form
*/
c_package_id_canonical_form = rb_define_module_under(paludis_module(), "PackageIDCanonicalForm");
for (PackageIDCanonicalForm l(static_cast<PackageIDCanonicalForm>(0)), l_end(last_idcf) ; l != l_end ;
@@ -153,6 +455,93 @@ namespace
rb_define_const(c_package_id_canonical_form, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
// cc_enum_special<paludis/package_id-se.hh, PackageIDCanonicalForm, c_package_id_canonical_form>
+
+ /*
+ * Document-class: Paludis::MetadataKey
+ *
+ * Base metadata class
+ */
+ c_metadata_key = rb_define_class_under(paludis_module(), "MetadataKey", rb_cObject);
+ rb_funcall(c_metadata_key, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_metadata_key, "raw_name", RUBY_FUNC_CAST((&BaseValue<std::string,MetadataKey,&MetadataKey::raw_name>::fetch)), 0);
+ rb_define_method(c_metadata_key, "human_name", RUBY_FUNC_CAST((&BaseValue<std::string,MetadataKey,&MetadataKey::human_name>::fetch)), 0);
+ rb_define_method(c_metadata_key, "type", RUBY_FUNC_CAST(&metadata_key_type), 0);
+
+ /*
+ * Document-class: Paludis::MetadataKey
+ *
+ * Base metadata class
+ */
+ c_metadata_package_id_key = rb_define_class_under(paludis_module(), "MetadataPackageIDKey", c_metadata_key);
+ rb_define_method(c_metadata_package_id_key, "value", RUBY_FUNC_CAST(&metadata_package_id_key_value), 0);
+
+ /*
+ * Document-class: Paludis::MetadataStringKey
+ *
+ * Metadata class for Strings
+ */
+ c_metadata_string_key = rb_define_class_under(paludis_module(), "MetadataStringKey", c_metadata_key);
+ rb_define_method(c_metadata_string_key, "value", RUBY_FUNC_CAST(&metadata_string_key_value), 0);
+
+ /*
+ * Document-class: Paludis::MetadataTimeKey
+ *
+ * Metadata class for Time
+ */
+ c_metadata_time_key = rb_define_class_under(paludis_module(), "MetadataTimeKey", c_metadata_key);
+ rb_define_method(c_metadata_time_key, "value", RUBY_FUNC_CAST(&metadata_time_key_value), 0);
+
+ /*
+ * Document-class: Paludis::MetadataContentsKey
+ *
+ * Metadata class for Contents
+ */
+ c_metadata_contents_key = rb_define_class_under(paludis_module(), "MetadataContentsKey", c_metadata_key);
+ rb_define_method(c_metadata_contents_key, "value", RUBY_FUNC_CAST(&metadata_contents_key_value), 0);
+
+ /*
+ * Document-class: Paludis::MetadataKeywordNameCollectionKey
+ *
+ * Metadata class for Use flag names
+ */
+ c_metadata_keyword_name_collection_key = rb_define_class_under(paludis_module(), "MetadataKeywordNameCollectionKey", c_metadata_key);
+ rb_define_method(c_metadata_keyword_name_collection_key, "value", RUBY_FUNC_CAST((&CollectionValue<KeywordNameCollection>::fetch)), 0);
+
+ /*
+ * Document-class: Paludis::MetadataUseFlagNameCollectionKey
+ *
+ * Metadata class for Use flag names
+ */
+ c_metadata_use_flag_name_collection_key = rb_define_class_under(paludis_module(), "MetadataUseFlagNameCollectionKey", c_metadata_key);
+ rb_define_method(c_metadata_use_flag_name_collection_key, "value", RUBY_FUNC_CAST((&CollectionValue<UseFlagNameCollection>::fetch)), 0);
+
+ /*
+ * Document-class: Paludis::MetadataIUseFlagCollectionKey
+ *
+ * Metadata class for IUse flags
+ */
+ c_metadata_iuse_flag_collection_key = rb_define_class_under(paludis_module(), "MetadataIUseFlagCollectionKey", c_metadata_key);
+ rb_define_method(c_metadata_iuse_flag_collection_key, "value", RUBY_FUNC_CAST((&CollectionValue<IUseFlagCollection>::fetch)), 0);
+
+ /*
+ * Document-class: Paludis::MetadataInheritedCollectionKey
+ *
+ * Metadata class for Inherited
+ */
+ c_metadata_inherited_collection_key = rb_define_class_under(paludis_module(), "MetadataInheritedCollectionKey", c_metadata_key);
+ rb_define_method(c_metadata_inherited_collection_key, "value", RUBY_FUNC_CAST((&CollectionValue<InheritedCollection>::fetch)), 0);
+
+ /*
+ * Document-module: Paludis::MetadataKeyType
+ *
+ * The significance of a MetadataKey to a user.
+ */
+ c_metadata_key_type = rb_define_module_under(paludis_module(), "MetadataKeyType");
+ for (MetadataKeyType l(static_cast<MetadataKeyType>(0)), l_end(last_mkt) ; l != l_end ;
+ l = static_cast<MetadataKeyType>(static_cast<int>(l) + 1))
+ rb_define_const(c_metadata_key_type, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
+
+ // cc_enum_special<paludis/metadata_key-se.hh, MetadataKeyType, c_metadata_key_type>
}
}
@@ -190,4 +579,3 @@ paludis::ruby::value_to_package_id(VALUE v)
RegisterRubyClass::Register paludis_ruby_register_package_id PALUDIS_ATTRIBUTE((used))
(&do_register_package_id);
-
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index 0adfb87..7909ebd 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -2,7 +2,7 @@
# vim: set sw=4 sts=4 et tw=80 :
#
-# Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+# Copyright (c) 2007 Richard Brown <rbrown@gentoo.org>
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
@@ -24,13 +24,7 @@ require 'Paludis'
Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
module Paludis
- class TestCase_PackageID < Test::Unit::TestCase
- def test_no_create
- assert_raise NoMethodError do
- p = PackageID.new
- end
- end
-
+ module TestStuff
def env
unless @env
@env = NoConfigEnvironment.new("package_id_TEST_dir/testrepo/", '/var/empty')
@@ -45,26 +39,249 @@ module Paludis
@env_vdb
end
- def pid
+ def pid_testrepo
env.package_database.fetch_repository("testrepo").package_ids("foo/bar").first
end
+ def pid_installed
+ env_vdb.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one").first
+ end
+ end
+
+ class TestCase_MetadataKey < Test::Unit::TestCase
+ include TestStuff
+
+ def classes
+ [MetadataStringKey, MetadataContentsKey, MetadataTimeKey, MetadataUseFlagNameCollectionKey, MetadataKeywordNameCollectionKey, MetadataIUseFlagCollectionKey, MetadataInheritedCollectionKey]
+ end
+
+ def all_classes
+ classes.unshift MetadataKey
+ end
+
+ def mk
+ pid_testrepo.short_description_key
+ end
+
+ def test_no_create
+ all_classes.each do |x|
+ assert_raise NoMethodError do
+ x.new
+ end
+ end
+ end
+
+ def test_raw_name
+ assert_respond_to mk, :raw_name
+ assert_kind_of String, mk.raw_name
+ assert_equal 'DESCRIPTION', mk.raw_name
+ end
+
+ def test_human_name
+ assert_respond_to mk, :human_name
+ assert_kind_of String, mk.human_name
+ assert_equal 'Description', mk.human_name
+ end
+
+ def test_type
+ assert_respond_to mk, :type
+ assert_kind_of Fixnum, mk.type
+ end
+
+ def test_value
+ assert_respond_to mk, :value
+ assert_kind_of String, mk.value
+ end
+ end
+
+
+ class TestCase_PackageID < Test::Unit::TestCase
+ include TestStuff
+ def test_no_create
+ assert_raise NoMethodError do
+ p = PackageID.new
+ end
+ end
+
def test_members
- assert_equal 'foo/bar', pid.name
- assert_kind_of VersionSpec, pid.version
- assert_equal VersionSpec.new('1.0'), pid.version
- assert_equal '0', pid.slot
- assert_kind_of Repository, pid.repository
- assert_equal 'testrepo', pid.repository.name
- assert_kind_of EAPI, pid.eapi
- assert_equal '0', pid.eapi.name
- assert_equal pid, pid
+ [:name, :version, :slot, :repository, :eapi, :==, :keywords_key,
+ :use_key, :iuse_key, :inherited_key, :short_description_key,
+ :long_description_key, :contents_key, :installed_time_key,
+ :source_origin_key, :binary_origin_key].each do |method|
+
+ assert_respond_to pid_testrepo, method
+ end
end
def test_canonical_form
- assert_equal 'foo/bar-1.0::testrepo', pid.canonical_form(PackageIDCanonicalForm::Full)
- assert_equal '1.0', pid.canonical_form(PackageIDCanonicalForm::Version)
- assert_equal 'foo/bar::testrepo', pid.canonical_form(PackageIDCanonicalForm::NoVersion)
+ assert_equal 'foo/bar-1.0::testrepo', pid_testrepo.canonical_form(PackageIDCanonicalForm::Full)
+ assert_equal '1.0', pid_testrepo.canonical_form(PackageIDCanonicalForm::Version)
+ assert_equal 'foo/bar::testrepo', pid_testrepo.canonical_form(PackageIDCanonicalForm::NoVersion)
+ end
+
+ def test_=
+ assert_equal pid_testrepo, pid_testrepo
+ end
+ end
+
+ class TestCase_ERepo < Test::Unit::TestCase
+ include TestStuff
+ def test_name
+ assert_kind_of String, pid_testrepo.name
+ assert_equal 'foo/bar', pid_testrepo.name
+ end
+
+ def test_version
+ assert_kind_of VersionSpec, pid_testrepo.version
+ assert_equal VersionSpec.new('1.0'), pid_testrepo.version
+ end
+
+ def test_repository
+ assert_kind_of Repository, pid_testrepo.repository
+ assert_equal 'testrepo', pid_testrepo.repository.name
+ end
+
+ def test_eapi
+ assert_kind_of EAPI, pid_testrepo.eapi
+ assert_equal '0', pid_testrepo.eapi.name
+ end
+
+ def test_slot
+ assert_kind_of String, pid_testrepo.slot
+ assert_equal '0', pid_testrepo.slot
+ end
+
+ def test_short_description
+ assert_kind_of MetadataStringKey, pid_testrepo.short_description_key
+ assert_equal 'Test package', pid_testrepo.short_description_key.value
+ end
+
+ def test_long_description
+ #only gems has this atm
+ assert_nil pid_testrepo.long_description_key
+ end
+
+ def test_contents_key
+ assert_nil pid_testrepo.contents_key
+ end
+
+ def test_installed_time_key
+ assert_nil pid_testrepo.installed_time_key
+ end
+
+ def test_source_origin_key
+ assert_nil pid_testrepo.source_origin_key
+ end
+
+ def test_binary_origin_key
+ assert_nil pid_testrepo.binary_origin_key
+ end
+
+ def test_keywords_key
+ assert_kind_of MetadataKeywordNameCollectionKey, pid_testrepo.keywords_key
+ assert_kind_of Array, pid_testrepo.keywords_key.value
+ assert_equal ['test'], pid_testrepo.keywords_key.value
+ end
+
+ def test_use_key
+ assert_nil pid_testrepo.use_key
+ #assert_kind_of MetadataUseFlagNameCollectionKey, pid_testrepo.use_key
+ #assert_kind_of Array, pid_testrepo.use_key.value
+ #assert_equal ['test'], pid_testrepo.use_key.value
+ end
+
+ def test_iuse_key
+ assert_kind_of MetadataIUseFlagCollectionKey, pid_testrepo.iuse_key
+ assert_kind_of Array, pid_testrepo.iuse_key.value
+ assert_equal ['testflag'], pid_testrepo.iuse_key.value
+ end
+
+ def test_inherited_key
+ assert_nil pid_testrepo.inherited_key
+ #assert_kind_of MetadataInheritCollectionKey, pid_testrepo.inherited_key
+ #assert_kind_of Array, pid_testrepo.iuse_key.value
+ #assert_equal ['testflag'], pid_testrepo.iuse_key.value
+ end
+ end
+
+ class TestCase_VDBRepo < Test::Unit::TestCase
+ include TestStuff
+ def test_name
+ pid_installed = env_vdb.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one").first
+ end
+ def test_name
+ assert_kind_of String, pid_installed.name
+ assert_equal 'cat-one/pkg-one', pid_installed.name
+ end
+
+ def test_version
+ assert_kind_of VersionSpec, pid_installed.version
+ assert_equal VersionSpec.new('1'), pid_installed.version
+ end
+
+ def test_repository
+ assert_kind_of Repository, pid_installed.repository
+ assert_equal 'installed', pid_installed.repository.name
+ end
+
+ def test_eapi
+ assert_kind_of EAPI, pid_installed.eapi
+ assert_equal '0', pid_installed.eapi.name
+ end
+
+ def test_slot
+ assert_kind_of String, pid_installed.slot
+ assert_equal 'test_slot', pid_installed.slot
+ end
+
+ def test_short_description
+ assert_kind_of MetadataStringKey, pid_installed.short_description_key
+ assert_equal 'a description', pid_installed.short_description_key.value
+ end
+
+ def test_long_description
+ assert_nil pid_installed.long_description_key
+ end
+
+ def test_contents_key
+ assert_kind_of MetadataContentsKey, pid_installed.contents_key
+ assert_kind_of Contents, pid_installed.contents_key.value
+ end
+
+ def test_installed_time_key
+ assert_kind_of MetadataTimeKey, pid_installed.installed_time_key
+ assert_kind_of Time, pid_installed.installed_time_key.value
+ end
+
+ def test_source_origin_key
+ assert_kind_of MetadataStringKey, pid_installed.source_origin_key
+ assert_equal 'origin_test', pid_installed.source_origin_key.value
+ end
+
+ def test_binary_origin_key
+ assert_nil pid_installed.binary_origin_key
+ end
+
+ def test_keywords_key
+ assert_nil pid_installed.keywords_key
+ end
+
+ def test_use_key
+ assert_kind_of MetadataUseFlagNameCollectionKey, pid_installed.use_key
+ assert_kind_of Array, pid_installed.use_key.value
+ assert_equal ['test', 'test_use'], pid_installed.use_key.value
+ end
+
+ def test_iuse_key
+ assert_kind_of MetadataIUseFlagCollectionKey, pid_installed.iuse_key
+ assert_kind_of Array, pid_installed.iuse_key.value
+ assert_equal ['test', 'test_iuse'], pid_installed.iuse_key.value
+ end
+
+ def test_inherited_key
+ assert_kind_of MetadataInheritedCollectionKey, pid_installed.inherited_key
+ assert_kind_of Array, pid_installed.inherited_key.value
+ assert_equal ['test_inherited'], pid_installed.inherited_key.value
end
end
end
diff --git a/ruby/package_id_TEST_setup.sh b/ruby/package_id_TEST_setup.sh
index fdd9ea4..05efdec 100755
--- a/ruby/package_id_TEST_setup.sh
+++ b/ruby/package_id_TEST_setup.sh
@@ -24,7 +24,7 @@ DESCRIPTION="Test package"
HOMEPAGE="http://paludis.pioto.org/"
SRC_URI="http://example.com/${P}.tar.bz2"
SLOT="0"
-IUSE=""
+IUSE="testflag"
LICENSE="GPL-2"
KEYWORDS="test"
RESTRICT="monkey"
@@ -36,10 +36,14 @@ cd ..
mkdir -p installed/cat-one/pkg-{one,two}-1 || exit 1
-touch installed/cat-one/pkg-one-1/CONTENTS
-touch installed/cat-one/pkg-two-1/CONTENTS
+echo "cat-one" > installed/cat-one/pkg-one-1/CATEGORY
+touch installed/cat-one/pkg-one-1/CONTENTS
+echo "0" > installed/cat-one/pkg-one-1/EAPI
+echo "a description" > installed/cat-one/pkg-one-1/DESCRIPTION
+echo "test_inherited" > installed/cat-one/pkg-one-1/INHERITED
+echo "test_iuse test" > installed/cat-one/pkg-one-1/IUSE
+echo "test" > installed/cat-one/pkg-one-1/KEYWORDS
echo "origin_test" > installed/cat-one/pkg-one-1/REPOSITORY
-echo "0" > installed/cat-one/pkg-one-1/SLOT
-echo "0" > installed/cat-one/pkg-two-1/SLOT
-
+echo "test_slot" > installed/cat-one/pkg-one-1/SLOT
+echo "test test_use" > installed/cat-one/pkg-one-1/USE