aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-25 21:19:44 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-25 21:19:44 +0000
commit3694ba8427a47f2b2ff5eefa2da315f11c224049 (patch)
tree11a8c2b520ec3757ee636388111059abfde4efe1
parentcfc3ab0786b9e3b82e22f20bfab466edd7e861b4 (diff)
downloadpaludis-3694ba8427a47f2b2ff5eefa2da315f11c224049.tar.gz
paludis-3694ba8427a47f2b2ff5eefa2da315f11c224049.tar.xz
Extend dep atom support, add PortageDepParser support to ruby
-rw-r--r--paludis/dep_atom.cc7
-rw-r--r--paludis/dep_atom.hh7
-rw-r--r--ruby/Makefile.am10
-rw-r--r--ruby/dep_atom.cc173
-rw-r--r--ruby/dep_atom_TEST.rb98
-rw-r--r--ruby/paludis_ruby.cc5
-rw-r--r--ruby/portage_dep_parser.cc89
-rw-r--r--ruby/portage_dep_parser_TEST.rb74
8 files changed, 445 insertions, 18 deletions
diff --git a/paludis/dep_atom.cc b/paludis/dep_atom.cc
index 16b8d30..ec820bc 100644
--- a/paludis/dep_atom.cc
+++ b/paludis/dep_atom.cc
@@ -267,6 +267,13 @@ PackageDepAtom::~PackageDepAtom()
}
std::ostream &
+paludis::operator<< (std::ostream & s, const PlainTextDepAtom & a)
+{
+ s << a.text();
+ return s;
+}
+
+std::ostream &
paludis::operator<< (std::ostream & s, const PackageDepAtom & a)
{
if (a.version_spec_ptr())
diff --git a/paludis/dep_atom.hh b/paludis/dep_atom.hh
index b6aaf5c..d44e344 100644
--- a/paludis/dep_atom.hh
+++ b/paludis/dep_atom.hh
@@ -462,6 +462,13 @@ namespace paludis
};
/**
+ * A PlainTextDepAtom can be written to an ostream.
+ *
+ * \ingroup grpdepatoms
+ */
+ std::ostream & operator<< (std::ostream &, const PlainTextDepAtom &);
+
+ /**
* Thrown if an invalid package dep atom specification is encountered.
*
* \ingroup grpexceptions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index e4c6079..ccbcf53 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -24,7 +24,8 @@ IF_RUBY_TESTS = \
dep_atom_TEST.rb \
package_database_TEST.rb \
repository_TEST.rb \
- version_metadata_TEST.rb
+ version_metadata_TEST.rb \
+ portage_dep_parser_TEST.rb
IF_RUBY_SOURCES = \
paludis_ruby.cc paludis_ruby.hh \
@@ -36,7 +37,8 @@ IF_RUBY_SOURCES = \
log.cc \
package_database.cc \
repository.cc \
- version_metadata.cc
+ version_metadata.cc \
+ portage_dep_parser.cc
EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
environment_TEST_setup.sh environment_TEST_cleanup.sh \
@@ -70,6 +72,7 @@ OUR_OBJECTS = \
version_spec.o \
repository.o \
version_metadata.o \
+ portage_dep_parser.o \
paludis_ruby.o
TESTS = $(IF_RUBY_TESTS)
@@ -112,6 +115,9 @@ log.o : log.cc paludis_ruby.hh
repository.o : repository.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/repository.cc
+portage_dep_parser.o : portage_dep_parser.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/portage_dep_parser.cc
+
.libs/Paludis.so : $(OUR_OBJECTS)
mkdir -p .libs
$(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
diff --git a/ruby/dep_atom.cc b/ruby/dep_atom.cc
index 3affd33..ec66dc5 100644
--- a/ruby/dep_atom.cc
+++ b/ruby/dep_atom.cc
@@ -29,29 +29,43 @@ using namespace paludis::ruby;
namespace
{
static VALUE c_dep_atom;
+ static VALUE c_composite_dep_atom;
static VALUE c_package_dep_atom;
+ static VALUE c_plain_text_dep_atom;
+ static VALUE c_all_dep_atom;
+ static VALUE c_any_dep_atom;
+ static VALUE c_use_dep_atom;
+ static VALUE c_block_dep_atom;
+ static VALUE c_string_dep_atom;
VALUE
- dep_atom_init(VALUE self)
+ dep_atom_init_0(VALUE self)
{
return self;
}
VALUE
- package_dep_atom_init(VALUE self, VALUE)
+ dep_atom_init_1(VALUE self, VALUE)
{
return self;
}
VALUE
- package_dep_atom_new(VALUE self, VALUE s)
+ dep_atom_init_2(VALUE self, VALUE, VALUE)
{
- PackageDepAtom::ConstPointer * ptr(0);
+ return self;
+ }
+
+ VALUE
+ use_dep_atom_new(VALUE self, VALUE pkg, VALUE inverse)
+ {
+ UseDepAtom::ConstPointer * ptr(0);
try
{
- ptr = new PackageDepAtom::ConstPointer(new PackageDepAtom(STR2CSTR(s)));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<PackageDepAtom::ConstPointer>::free, ptr));
- rb_obj_call_init(tdata, 1, &s);
+ ptr = new UseDepAtom::ConstPointer(new UseDepAtom(
+ UseFlagName(STR2CSTR(pkg)), Qfalse != inverse && Qnil != inverse));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<UseDepAtom::ConstPointer>::free, ptr));
+ rb_obj_call_init(tdata, 2, &pkg);
return tdata;
}
catch (const std::exception & e)
@@ -61,15 +75,101 @@ namespace
}
}
+ VALUE
+ block_dep_atom_new(VALUE self, VALUE atom)
+ {
+ BlockDepAtom::ConstPointer * ptr(0);
+ try
+ {
+ PackageDepAtom::ConstPointer pkg(value_to_package_dep_atom(atom));
+ ptr = new BlockDepAtom::ConstPointer(new BlockDepAtom(pkg));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<BlockDepAtom::ConstPointer>::free, ptr));
+ rb_obj_call_init(tdata, 1, &atom);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ block_dep_atom_blocked_atom(VALUE self)
+ {
+ BlockDepAtom::ConstPointer * p;
+ Data_Get_Struct(self, BlockDepAtom::ConstPointer, p);
+ return dep_atom_to_value((*p)->blocked_atom());
+ }
+
+ template <typename A_>
+ struct DepAtomThings
+ {
+ static VALUE
+ dep_atom_new_1(VALUE self, VALUE s)
+ {
+ typename A_::ConstPointer * ptr(0);
+ try
+ {
+ ptr = new typename A_::ConstPointer(new A_(STR2CSTR(s)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<typename A_::ConstPointer>::free, ptr));
+ rb_obj_call_init(tdata, 1, &s);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+ };
+
+ VALUE
+ composite_dep_atom_each(VALUE self)
+ {
+ CompositeDepAtom::Pointer * m_ptr;
+ Data_Get_Struct(self, CompositeDepAtom::Pointer, m_ptr);
+ for (CompositeDepAtom::Iterator i((*m_ptr)->begin()), i_end((*m_ptr)->end()) ; i != i_end ; ++i)
+ rb_yield(dep_atom_to_value(*i));
+ return self;
+ }
+
void do_register_dep_atom()
{
c_dep_atom = rb_define_class_under(master_class(), "DepAtom", rb_cObject);
rb_funcall(c_dep_atom, rb_intern("private_class_method"), 1, rb_str_new2("new"));
- c_package_dep_atom = rb_define_class_under(master_class(), "PackageDepAtom", c_dep_atom);
- rb_define_singleton_method(c_package_dep_atom, "new", RUBY_FUNC_CAST(&package_dep_atom_new), 1);
- rb_define_method(c_package_dep_atom, "initialize", RUBY_FUNC_CAST(&package_dep_atom_init), 1);
+ c_composite_dep_atom = rb_define_class_under(master_class(), "CompositeDepAtom", c_dep_atom);
+ rb_funcall(c_composite_dep_atom, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_composite_dep_atom, "each", RUBY_FUNC_CAST(&composite_dep_atom_each), 0);
+ rb_include_module(c_composite_dep_atom, rb_mEnumerable);
+
+ c_all_dep_atom = rb_define_class_under(master_class(), "AllDepAtom", c_composite_dep_atom);
+ rb_funcall(c_all_dep_atom, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_any_dep_atom = rb_define_class_under(master_class(), "AnyDepAtom", c_composite_dep_atom);
+ rb_funcall(c_any_dep_atom, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_use_dep_atom = rb_define_class_under(master_class(), "UseDepAtom", c_composite_dep_atom);
+ rb_funcall(c_use_dep_atom, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_string_dep_atom = rb_define_class_under(master_class(), "StringDepAtom", c_dep_atom);
+ rb_funcall(c_string_dep_atom, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_package_dep_atom = rb_define_class_under(master_class(), "PackageDepAtom", c_string_dep_atom);
+ rb_define_singleton_method(c_package_dep_atom, "new", RUBY_FUNC_CAST(&DepAtomThings<PackageDepAtom>::dep_atom_new_1), 1);
+ rb_define_method(c_package_dep_atom, "initialize", RUBY_FUNC_CAST(&dep_atom_init_1), 1);
rb_define_method(c_package_dep_atom, "to_s", RUBY_FUNC_CAST(&Common<PackageDepAtom::ConstPointer>::to_s_via_ptr), 0);
+
+ c_plain_text_dep_atom = rb_define_class_under(master_class(), "PlainTextDepAtom", c_string_dep_atom);
+ rb_define_singleton_method(c_plain_text_dep_atom, "new", RUBY_FUNC_CAST(&DepAtomThings<PlainTextDepAtom>::dep_atom_new_1), 1);
+ rb_define_method(c_plain_text_dep_atom, "initialize", RUBY_FUNC_CAST(&dep_atom_init_1), 1);
+ rb_define_method(c_plain_text_dep_atom, "to_s", RUBY_FUNC_CAST(&Common<PlainTextDepAtom::ConstPointer>::to_s_via_ptr), 0);
+
+ c_block_dep_atom = rb_define_class_under(master_class(), "BlockDepAtom", c_string_dep_atom);
+ rb_define_singleton_method(c_block_dep_atom, "new", RUBY_FUNC_CAST(&block_dep_atom_new), 1);
+ rb_define_method(c_block_dep_atom, "initialize", RUBY_FUNC_CAST(&dep_atom_init_1), 1);
+ rb_define_method(c_block_dep_atom, "blocked_atom", RUBY_FUNC_CAST(&block_dep_atom_blocked_atom), 0);
}
}
@@ -89,11 +189,60 @@ paludis::ruby::value_to_package_dep_atom(VALUE v)
VALUE
paludis::ruby::dep_atom_to_value(DepAtom::ConstPointer m)
{
+ struct V :
+ DepAtomVisitorTypes::ConstVisitor
+ {
+ VALUE value;
+ DepAtom::ConstPointer mm;
+
+ V(DepAtom::ConstPointer _m) :
+ mm(_m)
+ {
+ }
+
+ void visit(const AllDepAtom *)
+ {
+ value = Data_Wrap_Struct(c_all_dep_atom, 0, &Common<AllDepAtom::ConstPointer>::free,
+ new AllDepAtom::ConstPointer(mm));
+ }
+
+ void visit(const AnyDepAtom *)
+ {
+ value = Data_Wrap_Struct(c_any_dep_atom, 0, &Common<AnyDepAtom::ConstPointer>::free,
+ new AnyDepAtom::ConstPointer(mm));
+ }
+
+ void visit(const UseDepAtom *)
+ {
+ value = Data_Wrap_Struct(c_use_dep_atom, 0, &Common<UseDepAtom::ConstPointer>::free,
+ new UseDepAtom::ConstPointer(mm));
+ }
+
+ void visit(const PlainTextDepAtom *)
+ {
+ value = Data_Wrap_Struct(c_plain_text_dep_atom, 0, &Common<PlainTextDepAtom::ConstPointer>::free,
+ new PlainTextDepAtom::ConstPointer(mm));
+ }
+
+ void visit(const PackageDepAtom *)
+ {
+ value = Data_Wrap_Struct(c_package_dep_atom, 0, &Common<PackageDepAtom::ConstPointer>::free,
+ new PackageDepAtom::ConstPointer(mm));
+ }
+
+ void visit(const BlockDepAtom *)
+ {
+ value = Data_Wrap_Struct(c_block_dep_atom, 0, &Common<BlockDepAtom::ConstPointer>::free,
+ new BlockDepAtom::ConstPointer(mm));
+ }
+ };
+
DepAtom::ConstPointer * m_ptr(0);
try
{
- m_ptr = new DepAtom::ConstPointer(m);
- return Data_Wrap_Struct(c_dep_atom, 0, &Common<DepAtom::ConstPointer>::free, m_ptr);
+ V v(m);
+ m->accept(&v);
+ return v.value;
}
catch (const std::exception & e)
{
diff --git a/ruby/dep_atom_TEST.rb b/ruby/dep_atom_TEST.rb
index fc1da26..d9de8b0 100644
--- a/ruby/dep_atom_TEST.rb
+++ b/ruby/dep_atom_TEST.rb
@@ -22,7 +22,24 @@ require 'test/unit'
require 'Paludis'
class Paludis
- class TestCase_VersionSpec < Test::Unit::TestCase
+ class TestCase_DepAtom < Test::Unit::TestCase
+ def test_create_error
+ assert_raise NoMethodError do
+ v = DepAtom.new
+ end
+ assert_raise NoMethodError do
+ v = StringDepAtom.new
+ end
+ assert_raise NoMethodError do
+ v = AnyDepAtom.new
+ end
+ assert_raise NoMethodError do
+ v = AllDepAtom.new
+ end
+ end
+ end
+
+ class TestCase_PackageDepAtom < Test::Unit::TestCase
def test_create
v = PackageDepAtom.new(">=foo/bar-1")
end
@@ -34,15 +51,88 @@ class Paludis
assert_raise PackageDepAtomError do
v = PackageDepAtom.new("=sys-apps/foo")
end
- assert_raise NoMethodError do
- v = DepAtom.new
- end
end
def test_to_s
assert_equal ">=foo/bar-1", PackageDepAtom.new(">=foo/bar-1").to_s
end
end
+
+ class TestCase_PlainTextDepAtom < Test::Unit::TestCase
+ def test_create
+ v = PlainTextDepAtom.new("monkey")
+ end
+
+ def test_create_error
+ assert_raise TypeError do
+ v = PlainTextDepAtom.new(0)
+ end
+ end
+
+ def test_to_s
+ assert_equal "monkey", PlainTextDepAtom.new("monkey").to_s
+ end
+ end
+
+ class TestCase_BlockDepAtom < Test::Unit::TestCase
+ def test_create
+ v = BlockDepAtom.new(PackageDepAtom.new(">=foo/bar-1"))
+ w = BlockDepAtom.new("<=foo/bar-2")
+ end
+
+ def test_create_error
+ assert_raise TypeError do
+ v = BlockDepAtom.new(0)
+ end
+ assert_raise PackageDepAtomError do
+ v = BlockDepAtom.new("=foo/bar")
+ end
+ end
+
+ def test_blocked_atom
+ assert_equal "foo/bar", BlockDepAtom.new("foo/bar").blocked_atom.to_s
+ assert_equal "foo/baz", BlockDepAtom.new(PackageDepAtom.new("foo/baz")).blocked_atom.to_s
+ end
+ end
+
+ class TestCase_Composites < Test::Unit::TestCase
+ def test_composites
+ atom = PortageDepParser::parse("|| ( foo/bar foo/baz ) foo/monkey")
+ assert_kind_of CompositeDepAtom, atom
+ assert_kind_of AllDepAtom, atom
+
+ assert_equal 2, atom.to_a.length
+
+ atom.each_with_index do | a, i |
+ case i
+ when 0:
+ assert_kind_of AnyDepAtom, a
+ assert_equal 2, a.to_a.length
+ a.each_with_index do | b, j |
+ case j
+ when 0:
+ assert_kind_of PackageDepAtom, b
+ assert_equal "foo/bar", b.to_s
+
+ when 1:
+ assert_kind_of PackageDepAtom, b
+ assert_equal "foo/baz", b.to_s
+
+ else
+ throw "Too many items"
+ end
+ end
+
+ when 1:
+ assert_kind_of PackageDepAtom, a
+ assert_equal "foo/monkey", a.to_s
+
+ else
+ throw "Too many items"
+ end
+ end
+ end
+ end
end
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index c2fc841..7d61ab0 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -45,6 +45,7 @@ namespace
static VALUE c_package_database_lookup_error;
static VALUE c_no_such_package_error;
static VALUE c_no_such_repository_error;
+ static VALUE c_dep_string_error;
}
RegisterRubyClass::RegisterRubyClass() :
@@ -86,6 +87,9 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
rb_raise(c_package_database_lookup_error, dynamic_cast<const paludis::PackageDatabaseLookupError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::PackageDatabaseError *>(&ee))
rb_raise(c_package_database_error, dynamic_cast<const paludis::PackageDatabaseError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::DepStringError *>(&ee))
+ rb_raise(c_dep_string_error, dynamic_cast<const paludis::DepStringError *>(&ee)->message().c_str());
+
else if (0 != dynamic_cast<const paludis::Exception *>(&ee))
rb_raise(rb_eRuntimeError, "Caught paludis::Exception: %s (%s)",
dynamic_cast<const paludis::Exception *>(&ee)->message().c_str(), ee.what());
@@ -134,6 +138,7 @@ extern "C"
c_package_database_lookup_error = rb_define_class_under(c_master_class, "PackageDatabaseLookupError", c_package_database_error);
c_no_such_package_error = rb_define_class_under(c_master_class, "NoSuchPackageError", c_package_database_lookup_error);
c_no_such_repository_error = rb_define_class_under(c_master_class, "NoSuchRepositoryError", c_package_database_lookup_error);
+ c_dep_string_error = rb_define_class_under(c_master_class, "DepStringError", rb_eRuntimeError);
rb_define_const(c_master_class, "Version", rb_str_new2((stringify(PALUDIS_VERSION_MAJOR) + "."
+ stringify(PALUDIS_VERSION_MINOR) + "." + stringify(PALUDIS_VERSION_MICRO)).c_str()));
diff --git a/ruby/portage_dep_parser.cc b/ruby/portage_dep_parser.cc
new file mode 100644
index 0000000..fd8ff16
--- /dev/null
+++ b/ruby/portage_dep_parser.cc
@@ -0,0 +1,89 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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
+ */
+
+#include <paludis_ruby.hh>
+#include <paludis/portage_dep_parser.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_portage_dep_parser;
+
+ VALUE
+ portage_dep_parser_parse(int argc, VALUE * args, VALUE)
+ {
+ try
+ {
+ if (1 == argc)
+ return dep_atom_to_value(PortageDepParser::parse(STR2CSTR(args[0])));
+ else if (3 == argc)
+ {
+ bool b(! (args[2] == Qnil || args[2] == Qfalse));
+
+ switch (NUM2INT(args[1]))
+ {
+ case 17:
+ if (b)
+ return dep_atom_to_value(PortageDepParser::parse(STR2CSTR(args[0]),
+ PortageDepParserPolicy<PackageDepAtom, true>::get_instance()));
+ else
+ return dep_atom_to_value(PortageDepParser::parse(STR2CSTR(args[0]),
+ PortageDepParserPolicy<PackageDepAtom, false>::get_instance()));
+ case 23:
+ if (b)
+ return dep_atom_to_value(PortageDepParser::parse(STR2CSTR(args[0]),
+ PortageDepParserPolicy<PlainTextDepAtom, true>::get_instance()));
+ else
+ return dep_atom_to_value(PortageDepParser::parse(STR2CSTR(args[0]),
+ PortageDepParserPolicy<PlainTextDepAtom, false>::get_instance()));
+ }
+
+ rb_raise(rb_eArgError, "Bad value '%d' for PortageDepParser::parse parameter 2", NUM2INT(args[1]));
+ }
+ else
+ rb_raise(rb_eArgError, "PortageDepParser::parse expects one or three arguments, but got %d", argc);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_portage_dep_parser()
+ {
+ rb_require("singleton");
+
+ c_portage_dep_parser = rb_define_class_under(master_class(), "PortageDepParser", rb_cObject);
+ rb_funcall(c_portage_dep_parser, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_singleton_method(c_portage_dep_parser, "parse",
+ RUBY_FUNC_CAST(&portage_dep_parser_parse), -1);
+
+ rb_define_const(c_portage_dep_parser, "PackageDepAtom", INT2FIX(17));
+ rb_define_const(c_portage_dep_parser, "PlainTextDepAtom", INT2FIX(23));
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_portage_dep_parser PALUDIS_ATTRIBUTE((used))
+ (&do_register_portage_dep_parser);
+
diff --git a/ruby/portage_dep_parser_TEST.rb b/ruby/portage_dep_parser_TEST.rb
new file mode 100644
index 0000000..7593205
--- /dev/null
+++ b/ruby/portage_dep_parser_TEST.rb
@@ -0,0 +1,74 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.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
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+class Paludis
+ class TestCase_PortageDepParser < Test::Unit::TestCase
+ def test_one_arg
+ atom = PortageDepParser::parse("foo/monkey")
+ assert_kind_of AllDepAtom, atom
+ assert_equal 1, atom.to_a.length
+ assert_equal "foo/monkey", atom.to_a[0].to_s
+ assert_kind_of PackageDepAtom, atom.to_a[0]
+ end
+
+ def test_many_args
+ atom = PortageDepParser::parse("foo/monkey", PortageDepParser::PlainTextDepAtom, false)
+ assert_kind_of AllDepAtom, atom
+ assert_equal 1, atom.to_a.length
+ assert_equal "foo/monkey", atom.to_a[0].to_s
+ assert_kind_of PlainTextDepAtom, atom.to_a[0]
+
+ atom = PortageDepParser::parse("foo/monkey", PortageDepParser::PlainTextDepAtom, true)
+ assert_kind_of AllDepAtom, atom
+ assert_equal 1, atom.to_a.length
+ assert_equal "foo/monkey", atom.to_a[0].to_s
+ assert_kind_of PlainTextDepAtom, atom.to_a[0]
+
+ atom = PortageDepParser::parse("foo/monkey", PortageDepParser::PackageDepAtom, false)
+ assert_kind_of AllDepAtom, atom
+ assert_equal 1, atom.to_a.length
+ assert_equal "foo/monkey", atom.to_a[0].to_s
+ assert_kind_of PackageDepAtom, atom.to_a[0]
+
+ atom = PortageDepParser::parse("foo/monkey", PortageDepParser::PackageDepAtom, true)
+ assert_kind_of AllDepAtom, atom
+ assert_equal 1, atom.to_a.length
+ assert_equal "foo/monkey", atom.to_a[0].to_s
+ assert_kind_of PackageDepAtom, atom.to_a[0]
+
+ assert_raise DepStringError do
+ PortageDepParser::parse("|| ( foo/bar )", PortageDepParser::PackageDepAtom, false)
+ end
+
+ PortageDepParser::parse("|| ( foo/bar )", PortageDepParser::PackageDepAtom, true)
+
+ assert_raise DepStringError do
+ PortageDepParser::parse("|| ( foo/bar )", PortageDepParser::PlainTextDepAtom, false)
+ end
+
+ PortageDepParser::parse("|| ( foo/bar )", PortageDepParser::PlainTextDepAtom, true)
+ end
+ end
+end
+
+