aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-10-25 11:06:24 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2008-10-25 13:12:59 +0100
commit9124291229b1e2c42c16771025c066f7de2fcabc (patch)
tree8fbbcc08c2575c9b9837dba80eb337b2187fce73
parentb7349724b4d22b0f96c690a0ef506a4511f1c54c (diff)
downloadpaludis-9124291229b1e2c42c16771025c066f7de2fcabc.tar.gz
paludis-9124291229b1e2c42c16771025c066f7de2fcabc.tar.xz
(ruby) Add/fix ::* things for PackageDepSpec.
-rw-r--r--ruby/dep_spec.cc97
-rw-r--r--ruby/dep_spec_TEST.rb95
2 files changed, 183 insertions, 9 deletions
diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc
index 350cce1..0e8510a 100644
--- a/ruby/dep_spec.cc
+++ b/ruby/dep_spec.cc
@@ -727,6 +727,98 @@ namespace
/*
* call-seq:
+ * in_repository -> String or Nil
+ *
+ * Fetch the in-repository name.
+ */
+ VALUE
+ package_dep_spec_in_repository_ptr(VALUE self)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ if (0 == std::tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->in_repository_ptr())
+ return Qnil;
+ return rb_str_new2(stringify((*std::tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->in_repository_ptr())).c_str());
+ }
+
+ /*
+ * call-seq:
+ * from_repository -> String or Nil
+ *
+ * Fetch the from-repository name.
+ */
+ VALUE
+ package_dep_spec_from_repository_ptr(VALUE self)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ if (0 == std::tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->from_repository_ptr())
+ return Qnil;
+ return rb_str_new2(stringify((*std::tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->from_repository_ptr())).c_str());
+ }
+
+ /*
+ * call-seq:
+ * installable_to_repository -> Hash or Nil
+ *
+ * Fetch the installable-to-repository requirement.
+ */
+ VALUE
+ package_dep_spec_installable_to_repository(VALUE self)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ std::tr1::shared_ptr<const InstallableToRepository> i2r(std::tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->installable_to_repository_ptr());
+ if (! i2r)
+ return Qnil;
+ VALUE result(rb_hash_new());
+ rb_hash_aset(result, ID2SYM(rb_intern("repository")),
+ rb_str_new2(stringify(i2r->repository()).c_str()));
+ rb_hash_aset(result, ID2SYM(rb_intern("include_masked?")),
+ i2r->include_masked() ? Qtrue : Qfalse);
+ return result;
+ }
+
+ /*
+ * call-seq:
+ * installed_at_path -> String or Nil
+ *
+ * Fetch the installed-at-path requirement.
+ */
+ VALUE
+ package_dep_spec_installed_at_path(VALUE self)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ if (0 == std::tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->installed_at_path_ptr())
+ return Qnil;
+ return rb_str_new2(stringify((*std::tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->installed_at_path_ptr())).c_str());
+ }
+
+ /*
+ * call-seq:
+ * installable_to_path -> Hash or Nil
+ *
+ * Fetch the installable-to-path requirement.
+ */
+ VALUE
+ package_dep_spec_installable_to_path(VALUE self)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ std::tr1::shared_ptr<const InstallableToPath> i2p(std::tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->installable_to_path_ptr());
+ if (! i2p)
+ return Qnil;
+ VALUE result(rb_hash_new());
+ rb_hash_aset(result, ID2SYM(rb_intern("path")),
+ rb_str_new2(stringify(i2p->path()).c_str()));
+ rb_hash_aset(result, ID2SYM(rb_intern("include_masked?")),
+ i2p->include_masked() ? Qtrue : Qfalse);
+ return result;
+ }
+
+ /*
+ * call-seq:
* version_requirements -> Array
*
* Fetch the version requirements. E.g. [ {:operator => '=', :spec => VersionSpec.new('0.1') } ]
@@ -1137,6 +1229,11 @@ namespace
rb_define_method(c_package_dep_spec, "package_name_part", RUBY_FUNC_CAST(&package_dep_spec_package_name_part), 0);
rb_define_method(c_package_dep_spec, "category_name_part", RUBY_FUNC_CAST(&package_dep_spec_category_name_part), 0);
rb_define_method(c_package_dep_spec, "slot_requirement", RUBY_FUNC_CAST(&package_dep_spec_slot_requirement_ptr), 0);
+ rb_define_method(c_package_dep_spec, "in_repository", RUBY_FUNC_CAST(&package_dep_spec_in_repository_ptr), 0);
+ rb_define_method(c_package_dep_spec, "from_repository", RUBY_FUNC_CAST(&package_dep_spec_from_repository_ptr), 0);
+ rb_define_method(c_package_dep_spec, "installable_to_repository", RUBY_FUNC_CAST(&package_dep_spec_installable_to_repository), 0);
+ rb_define_method(c_package_dep_spec, "installed_at_path", RUBY_FUNC_CAST(&package_dep_spec_installed_at_path), 0);
+ rb_define_method(c_package_dep_spec, "installable_to_path", RUBY_FUNC_CAST(&package_dep_spec_installable_to_path), 0);
rb_define_method(c_package_dep_spec, "version_requirements", RUBY_FUNC_CAST(&package_dep_spec_version_requirements_ptr), 0);
rb_define_method(c_package_dep_spec, "version_requirements_mode", RUBY_FUNC_CAST(&package_dep_spec_version_requirements_mode), 0);
#ifdef CIARANM_REMOVED_THIS
diff --git a/ruby/dep_spec_TEST.rb b/ruby/dep_spec_TEST.rb
index d9329af..18ee9a8 100644
--- a/ruby/dep_spec_TEST.rb
+++ b/ruby/dep_spec_TEST.rb
@@ -54,9 +54,24 @@ module Paludis
Paludis::parse_user_package_dep_spec('*/bar', env, [:allow_wildcards])
end
+ def pdc
+ Paludis::parse_user_package_dep_spec('foo/bar::installed?', env, [])
+ end
+
+ def pdd
+ Paludis::parse_user_package_dep_spec('foo/*::/??', env, [:allow_wildcards])
+ end
+
+ def pde
+ Paludis::parse_user_package_dep_spec('foo/bar::testrepo->/mychroot', env, [])
+ end
+
def test_create
pda
pdb
+ pdc
+ pdd
+ pde
end
def test_create_error
@@ -86,11 +101,17 @@ module Paludis
def test_to_s
assert_equal ">=foo/bar-1:100::testrepo[-b][a]", pda.to_s
assert_equal "*/bar", pdb.to_s
+ assert_equal "foo/bar::installed?", pdc.to_s
+ assert_equal "foo/*::/??", pdd.to_s
+ assert_equal "foo/bar::testrepo->/mychroot", pde.to_s
end
def test_text
assert_equal ">=foo/bar-1:100::testrepo[-b][a]", pda.text
assert_equal "*/bar", pdb.text
+ assert_equal "foo/bar::installed?", pdc.text
+ assert_equal "foo/*::/??", pdd.text
+ assert_equal "foo/bar::testrepo->/mychroot", pde.text
end
def test_disambiguate
@@ -113,31 +134,77 @@ module Paludis
assert_equal ":100", pda.slot_requirement.to_s
assert_equal "100", pda.slot_requirement.slot
assert_nil pdb.slot_requirement
+ assert_nil pdc.slot_requirement
+ assert_nil pdd.slot_requirement
+ assert_nil pde.slot_requirement
end
def test_package
assert_equal QualifiedPackageName.new("foo/bar"), pda.package
assert_nil pdb.package
+ assert_equal QualifiedPackageName.new("foo/bar"), pdc.package
+ assert_nil pdd.package
+ assert_equal QualifiedPackageName.new("foo/bar"), pde.package
end
-### def test_from_repository
-### assert_nil pda.from_repository
-### assert_nil pdb.from_repository
-### end
-###
-### def test_in_repository
-### assert_equal "testrepo", pda.in_repository
-### assert_nil pdb.in_repository
-### end
+ def test_from_repository
+ assert_nil pda.from_repository
+ assert_nil pdb.from_repository
+ assert_nil pdc.from_repository
+ assert_nil pdd.from_repository
+ assert_equal "testrepo", pde.from_repository
+ end
+
+ def test_in_repository
+ assert_equal "testrepo", pda.in_repository
+ assert_nil pdb.in_repository
+ assert_nil pdc.in_repository
+ assert_nil pdd.in_repository
+ assert_nil pde.in_repository
+ end
+
+ def test_installable_to_repository
+ assert_nil pda.installable_to_repository
+ assert_nil pdb.installable_to_repository
+ assert_kind_of Hash, pdc.installable_to_repository
+ assert_equal "installed", pdc.installable_to_repository[:repository]
+ assert ! pdc.installable_to_repository[:include_masked?]
+ assert_nil pdd.installable_to_repository
+ assert_nil pde.installable_to_repository
+ end
+
+ def test_installed_at_path
+ assert_nil pda.installed_at_path
+ assert_nil pdb.installed_at_path
+ assert_nil pdc.installed_at_path
+ assert_nil pdd.installed_at_path
+ assert_equal "/mychroot", pde.installed_at_path
+ end
+
+ def test_installable_to_path
+ assert_nil pda.installable_to_path
+ assert_nil pdb.installable_to_path
+ assert_nil pdc.installable_to_path
+ assert_kind_of Hash, pdd.installable_to_path
+ assert_equal "/", pdd.installable_to_path[:path]
+ assert pdd.installable_to_path[:include_masked?]
+ assert_nil pde.installable_to_path
+ end
def test_package_name_part
assert_nil pda.package_name_part
assert_equal "bar", pdb.package_name_part
+ assert_nil pdc.package_name_part
+ assert_nil pdd.package_name_part
+ assert_nil pde.package_name_part
end
def test_category_name_part
assert_nil pda.category_name_part
assert_nil pdb.category_name_part
+ assert_nil pdc.category_name_part
+ assert_equal "foo", pdd.category_name_part
+ assert_nil pde.category_name_part
end
def test_version_requirements
@@ -145,6 +212,10 @@ module Paludis
assert_equal 1, pda.version_requirements.size
assert_equal VersionSpec.new('1'), pda.version_requirements.first[:spec]
assert_equal ">=", pda.version_requirements.first[:operator]
+ assert_equal 0, pdb.version_requirements.size
+ assert_equal 0, pdc.version_requirements.size
+ assert_equal 0, pdd.version_requirements.size
+ assert_equal 0, pde.version_requirements.size
end
def test_version_requirements_mode
@@ -166,11 +237,17 @@ module Paludis
def test_without_additional_requirements
assert_equal ">=foo/bar-1:100::testrepo", pda.without_additional_requirements.to_s
assert_equal "*/bar", pdb.without_additional_requirements.to_s
+ assert_equal "foo/bar::installed?", pdc.without_additional_requirements.to_s
+ assert_equal "foo/*::/??", pdd.without_additional_requirements.to_s
+ assert_equal "foo/bar::testrepo->/mychroot", pde.without_additional_requirements.to_s
end
def test_tag
assert_nil pda.tag
assert_nil pdb.tag
+ assert_nil pdc.tag
+ assert_nil pdd.tag
+ assert_nil pde.tag
my_pda = pda
my_pda.tag = TargetDepTag.new