You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by mi...@apache.org on 2010/10/14 10:48:40 UTC
[lucy-commits] svn commit: r1022422 [7/43] - in /incubator/lucy/trunk/import: ./
charmonizer/ charmonizer/src/ charmonizer/src/Charmonizer/
charmonizer/src/Charmonizer/Core/ charmonizer/src/Charmonizer/Probe/
charmonizer/src/Charmonizer/Test/ clownfish/ clownfish/lib...
Added: incubator/lucy/trunk/import/clownfish/t/001-util.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/001-util.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/001-util.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/001-util.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,59 @@
+use strict;
+use warnings;
+
+use Test::More tests => 16;
+use File::stat qw( stat );
+use Clownfish::Util qw(
+ slurp_file
+ current
+ verify_args
+ strip_c_comments
+ a_isa_b
+ write_if_changed
+);
+
+my $foo_txt = 'foo.txt';
+unlink $foo_txt;
+open( my $fh, '>', $foo_txt ) or die "Can't open '$foo_txt': $!";
+print $fh "foo";
+close $fh or die "Can't close '$foo_txt': $!";
+is( slurp_file($foo_txt), "foo", "slurp_file" );
+
+ok( current( $foo_txt, $foo_txt ), "current" );
+ok( !current( $foo_txt, 't' ), "not current" );
+ok( !current( $foo_txt, "nonexistent_file" ),
+ "not current when dest file mising"
+);
+
+my $one_second_ago = time() - 1;
+utime( $one_second_ago, $one_second_ago, $foo_txt )
+ or die "utime failed";
+write_if_changed( $foo_txt, "foo" );
+is( stat($foo_txt)->mtime, $one_second_ago,
+ "write_if_changed does nothing if contents not changed" );
+write_if_changed( $foo_txt, "foofoo" );
+ok( stat($foo_txt)->mtime != $one_second_ago,
+ "write_if_changed writes if contents changed"
+);
+
+unlink $foo_txt;
+
+my $comment = "/* I have nothing to say to you, world. */\n";
+my $no_comment = "\n";
+is( strip_c_comments($comment), $no_comment, "strip_c_comments" );
+
+my %defaults = ( foo => undef );
+sub test_verify_args { return verify_args( \%defaults, @_ ) }
+
+ok( test_verify_args( foo => 'foofoo' ), "args verified" );
+ok( !test_verify_args('foo'), "odd args fail verification" );
+like( $@, qr/odd/, 'set $@ on odd arg failure' );
+ok( !test_verify_args( bar => 'nope' ), "bad param doesn't verify" );
+like( $@, qr/param/, 'set $@ on invalid param failure' );
+
+my $foo = bless {}, 'Foo';
+ok( a_isa_b( $foo, 'Foo' ), "a_isa_b true" );
+ok( !a_isa_b( $foo, 'Bar' ), "a_isa_b false" );
+ok( !a_isa_b( 'Foo', 'Foo' ), "a_isa_b not blessed" );
+ok( !a_isa_b( undef, 'Foo' ), "a_isa_b undef" );
+
Added: incubator/lucy/trunk/import/clownfish/t/050-docucomment.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/050-docucomment.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/050-docucomment.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/050-docucomment.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+
+use Test::More tests => 10;
+
+BEGIN { use_ok('Clownfish::DocuComment') }
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+isa_ok( $parser->docucomment('/** foo. */'), "Clownfish::DocuComment" );
+
+my $text = <<'END_COMMENT';
+/**
+ * Brief description. Long description.
+ *
+ * More long description.
+ *
+ * @param foo A foo.
+ * @param bar A bar.
+ *
+ * @param baz A baz.
+ * @return a return value.
+ */
+END_COMMENT
+
+my $docucomment = Clownfish::DocuComment->parse($text);
+
+like(
+ $docucomment->get_description,
+ qr/^Brief.*long description.\s*\Z/ims,
+ "get_description"
+);
+is( $docucomment->get_brief, "Brief description.", "brief" );
+like( $docucomment->get_long, qr/^Long.*long description.\s*\Z/ims, "long" );
+is_deeply( $docucomment->get_param_names, [qw( foo bar baz )],
+ "param names" );
+is( $docucomment->get_param_docs->[0], "A foo.", '@param terminated by @' );
+is( $docucomment->get_param_docs->[1],
+ "A bar.", '@param terminated by empty line' );
+is( $docucomment->get_param_docs->[2],
+ "A baz.", '@param terminated next element, @return' );
+is( $docucomment->get_retval, "a return value.", "get_retval" );
+
Added: incubator/lucy/trunk/import/clownfish/t/051-symbol.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/051-symbol.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/051-symbol.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/051-symbol.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,67 @@
+use strict;
+use warnings;
+
+package ClownfishyThing;
+use base qw( Clownfish::Symbol );
+
+sub new {
+ return shift->SUPER::new( micro_sym => 'sym', exposure => 'parcel', @_ );
+}
+
+package main;
+use Test::More tests => 44;
+
+for (qw( foo FOO 1Foo Foo_Bar FOOBAR 1FOOBAR )) {
+ eval { my $thing = ClownfishyThing->new( class_name => $_ ) };
+ like( $@, qr/class name/, "Reject invalid class name $_" );
+ my $bogus_middle = "Foo::" . $_ . "::Bar";
+ eval { my $thing = ClownfishyThing->new( class_name => $bogus_middle ) };
+ like( $@, qr/class name/, "Reject invalid class name $bogus_middle" );
+}
+
+my @exposures = qw( public private parcel local );
+for my $exposure (@exposures) {
+ my $thing = ClownfishyThing->new( exposure => $exposure );
+ ok( $thing->$exposure, "exposure $exposure" );
+ my @not_exposures = grep { $_ ne $exposure } @exposures;
+ ok( !$thing->$_, "$exposure means not $_" ) for @not_exposures;
+}
+
+my $foo = ClownfishyThing->new( class_name => 'Foo' );
+my $foo_jr = ClownfishyThing->new( class_name => 'Foo::FooJr' );
+ok( !$foo->equals($foo_jr), "different class_name spoils equals" );
+is( $foo_jr->get_class_name, "Foo::FooJr", "get_class_name" );
+is( $foo_jr->get_class_cnick, "FooJr", "derive class_cnick from class_name" );
+
+my $public_exposure = ClownfishyThing->new( exposure => 'public' );
+my $parcel_exposure = ClownfishyThing->new( exposure => 'parcel' );
+ok( !$public_exposure->equals($parcel_exposure),
+ "different exposure spoils equals"
+);
+
+my $lucifer_parcel = Clownfish::Parcel->singleton( name => 'Lucifer' );
+my $lucifer = ClownfishyThing->new( parcel => 'Lucifer' );
+ok( $lucifer_parcel == $lucifer->get_parcel, "derive parcel" );
+is( $lucifer->get_prefix, "lucifer_", "get_prefix" );
+is( $lucifer->get_Prefix, "Lucifer_", "get_Prefix" );
+is( $lucifer->get_PREFIX, "LUCIFER_", "get_PREFIX" );
+my $luser = ClownfishyThing->new( parcel => 'Luser' );
+ok( !$lucifer->equals($luser), "different parcel spoils equals" );
+
+for ( qw( 1foo * 0 ), "\x{263a}" ) {
+ eval { my $thing = ClownfishyThing->new( micro_sym => $_ ); };
+ like( $@, qr/micro_sym/, "reject bad micro_sym" );
+}
+
+my $ooga = ClownfishyThing->new( micro_sym => 'ooga' );
+my $booga = ClownfishyThing->new( micro_sym => 'booga' );
+ok( !$ooga->equals($booga), "Different micro_sym spoils equals()" );
+
+my $eep = ClownfishyThing->new(
+ parcel => 'Eep',
+ class_name => "Op::Ork",
+ micro_sym => 'ah_ah',
+);
+is( $eep->short_sym, "Ork_ah_ah", "short_sym" );
+is( $eep->full_sym, "eep_Ork_ah_ah", "full_sym" );
+
Added: incubator/lucy/trunk/import/clownfish/t/100-type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/100-type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/100-type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/100-type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+package MyType;
+use base qw( Clownfish::Type );
+
+package main;
+use Test::More tests => 12;
+use Clownfish::Parcel;
+
+my $neato_parcel = Clownfish::Parcel->singleton( name => 'Neato' );
+
+my $type = MyType->new( parcel => 'Neato', specifier => 'mytype_t' );
+is( $type->get_parcel, $neato_parcel,
+ "constructor changes parcel name to Parcel singleton" );
+
+ok( !defined $type->to_c, "to_c()" );
+$type->set_c_string("mytype_t");
+is( $type->to_c, "mytype_t", "set_c_string()" );
+ok( !$type->const, "const() is off by default" );
+is( $type->get_specifier, "mytype_t", "get_specifier()" );
+
+ok( !$type->is_object, "is_object() false by default" );
+ok( !$type->is_integer, "is_integer() false by default" );
+ok( !$type->is_floating, "is_floating() false by default" );
+ok( !$type->is_void, "is_void() false by default" );
+ok( !$type->is_composite, "is_composite() false by default" );
+ok( !$type->is_string_type, "is_string_type() false by default" );
+
+ok( $type->equals( MyType->new ), "equals() depends solely on class" );
+
Added: incubator/lucy/trunk/import/clownfish/t/101-primitive_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/101-primitive_type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/101-primitive_type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/101-primitive_type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+
+package MyPrimitiveType;
+use base qw( Clownfish::Type::Primitive );
+
+package main;
+use Test::More tests => 4;
+
+my $type = MyPrimitiveType->new( specifier => 'hump_t' );
+ok( $type->is_primitive, "is_primitive" );
+
+my $other = MyPrimitiveType->new( specifier => 'hump_t' );
+ok( $type->equals($other), "equals()" );
+
+$other = MyPrimitiveType->new( specifier => 'dump_t' );
+ok( !$type->equals($other), "equals() spoiled by specifier" );
+
+$other = MyPrimitiveType->new( specifier => 'hump_t', const => 1 );
+ok( !$type->equals($other), "equals() spoiled by const" );
+
Added: incubator/lucy/trunk/import/clownfish/t/102-integer_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/102-integer_type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/102-integer_type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/102-integer_type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,62 @@
+use strict;
+use warnings;
+
+use Test::More tests => 59;
+use Clownfish::Type::Integer;
+use Clownfish::Parser;
+
+my $integer_type = Clownfish::Type::Integer->new(
+ specifier => 'int32_t',
+ const => 1,
+);
+ok( $integer_type->const, "const" );
+is( $integer_type->get_specifier, "int32_t" );
+like( $integer_type->to_c, qr/const/, "'const' in C representation" );
+
+my $parser = Clownfish::Parser->new;
+
+my @chy_specifiers = qw(
+ bool_t
+);
+my @c_specifiers = qw(
+ char
+ short
+ int
+ long
+ size_t
+ int8_t
+ int16_t
+ int32_t
+ int64_t
+ uint8_t
+ uint16_t
+ uint32_t
+ uint64_t
+);
+
+for my $chy_specifier (@chy_specifiers) {
+ is( $parser->chy_integer_specifier($chy_specifier),
+ $chy_specifier, "chy_integer_specifier: $chy_specifier" );
+ isa_ok( $parser->chy_integer_type($chy_specifier),
+ "Clownfish::Type::Integer" );
+ isa_ok( $parser->chy_integer_type("const $chy_specifier"),
+ "Clownfish::Type::Integer" );
+ my $bogus = $chy_specifier . "oot_toot";
+ ok( !$parser->chy_integer_specifier($bogus),
+ "chy_integer_specifier guards against partial word matches" );
+}
+
+for my $c_specifier (@c_specifiers) {
+ is( $parser->c_integer_specifier($c_specifier),
+ $c_specifier, "c_integer_specifier: $c_specifier" );
+ isa_ok(
+ $parser->c_integer_type($c_specifier),
+ "Clownfish::Type::Integer"
+ );
+ isa_ok( $parser->c_integer_type("const $c_specifier"),
+ "Clownfish::Type::Integer" );
+ my $bogus = $c_specifier . "y";
+ ok( !$parser->c_integer_specifier($bogus),
+ "c_integer_specifier guards against partial word matches" );
+}
+
Added: incubator/lucy/trunk/import/clownfish/t/103-float_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/103-float_type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/103-float_type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/103-float_type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+
+use Test::More tests => 11;
+use Clownfish::Type::Float;
+use Clownfish::Parser;
+
+my $float_type = Clownfish::Type::Float->new(
+ specifier => 'float',
+ const => 1,
+);
+ok( $float_type->const, "const" );
+is( $float_type->get_specifier, "float" );
+like( $float_type->to_c, qr/const/, "'const' in C representation" );
+
+my $parser = Clownfish::Parser->new;
+
+for my $specifier (qw( float double)) {
+ is( $parser->c_float_specifier($specifier),
+ $specifier, "c_float_specifier: $specifier" );
+ isa_ok( $parser->float_type($specifier), "Clownfish::Type::Float" );
+ isa_ok( $parser->float_type("const $specifier"),
+ "Clownfish::Type::Float" );
+ my $bogus = $specifier . "y";
+ ok( !$parser->c_float_specifier($bogus),
+ "c_float_specifier guards against partial word matches" );
+}
+
Added: incubator/lucy/trunk/import/clownfish/t/104-void_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/104-void_type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/104-void_type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/104-void_type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+
+use Test::More tests => 9;
+use Clownfish::Type::Void;
+use Clownfish::Parser;
+
+my $void_type = Clownfish::Type::Void->new;
+is( $void_type->get_specifier, "void", "specifier defaults to 'void'" );
+is( $void_type->to_c, "void", "to_c" );
+ok( $void_type->is_void, "is_void" );
+
+$void_type = Clownfish::Type::Void->new(
+ specifier => 'void',
+ const => 1,
+);
+ok( $void_type->const, "const" );
+like( $void_type->to_c, qr/const/, "'const' in C representation" );
+
+my $parser = Clownfish::Parser->new;
+
+is( $parser->void_type_specifier('void'), 'void', 'void_type_specifier' );
+isa_ok( $parser->void_type('void'), "Clownfish::Type::Void" );
+isa_ok( $parser->void_type('const void'), "Clownfish::Type::Void" );
+ok( !$parser->void_type_specifier('voidable'),
+ "void_type_specifier guards against partial word matches" );
+
Added: incubator/lucy/trunk/import/clownfish/t/105-object_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/105-object_type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/105-object_type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/105-object_type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,99 @@
+use strict;
+use warnings;
+
+use Test::More tests => 49;
+use Clownfish::Type::Object;
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+
+# Set and leave parcel.
+my $parcel = $parser->parcel_definition('parcel Neato;')
+ or die "failed to process parcel_definition";
+
+for my $bad_specifier (qw( foo fooBar Foo_Bar FOOBAR 1Foo 1FOO )) {
+ ok( !$parser->object_type_specifier($bad_specifier),
+ "reject bad object_type_specifier $bad_specifier"
+ );
+ eval {
+ my $type = Clownfish::Type::Object->new(
+ parcel => 'Neato',
+ specifier => $bad_specifier,
+ );
+ };
+ like( $@, qr/specifier/,
+ "constructor rejects bad specifier $bad_specifier" );
+}
+
+for my $specifier (qw( Foo FooJr FooIII Foo4th )) {
+ is( $parser->object_type_specifier($specifier),
+ $specifier, "object_type_specifier: $specifier" );
+ isa_ok( $parser->object_type("$specifier*"),
+ "Clownfish::Type::Object", "$specifier*" );
+ isa_ok( $parser->object_type("const $specifier*"),
+ "Clownfish::Type::Object", "const $specifier*" );
+ isa_ok( $parser->object_type("incremented $specifier*"),
+ "Clownfish::Type::Object", "incremented $specifier*" );
+ isa_ok( $parser->object_type("decremented $specifier*"),
+ "Clownfish::Type::Object", "decremented $specifier*" );
+}
+
+eval { my $type = Clownfish::Type::Object->new };
+like( $@, qr/specifier/i, "specifier required" );
+
+for ( 0, 2 ) {
+ eval {
+ my $type = Clownfish::Type::Object->new(
+ specifier => 'Foo',
+ indirection => $_,
+ );
+ };
+ like( $@, qr/indirection/i, "invalid indirection of $_" );
+}
+
+my $foo_type = Clownfish::Type::Object->new( specifier => 'Foo' );
+my $another_foo = Clownfish::Type::Object->new( specifier => 'Foo' );
+ok( $foo_type->equals($another_foo), "equals" );
+
+my $bar_type = Clownfish::Type::Object->new( specifier => 'Bar' );
+ok( !$foo_type->equals($bar_type), "different specifier spoils equals" );
+
+my $foreign_foo = Clownfish::Type::Object->new(
+ specifier => 'Foo',
+ parcel => 'Foreign',
+);
+ok( !$foo_type->equals($foreign_foo), "different parcel spoils equals" );
+is( $foreign_foo->get_specifier, "foreign_Foo",
+ "prepend parcel prefix to specifier" );
+
+my $incremented_foo = Clownfish::Type::Object->new(
+ specifier => 'Foo',
+ incremented => 1,
+);
+ok( $incremented_foo->incremented, "incremented" );
+ok( !$foo_type->incremented, "not incremented" );
+ok( !$foo_type->equals($incremented_foo),
+ "different incremented spoils equals"
+);
+
+my $decremented_foo = Clownfish::Type::Object->new(
+ specifier => 'Foo',
+ decremented => 1,
+);
+ok( $decremented_foo->decremented, "decremented" );
+ok( !$foo_type->decremented, "not decremented" );
+ok( !$foo_type->equals($decremented_foo),
+ "different decremented spoils equals"
+);
+
+my $const_foo = Clownfish::Type::Object->new(
+ specifier => 'Foo',
+ const => 1,
+);
+ok( !$foo_type->equals($const_foo), "different const spoils equals" );
+like( $const_foo->to_c, qr/const/, "const included in C representation" );
+
+my $string_type = Clownfish::Type::Object->new( specifier => 'CharBuf', );
+ok( !$foo_type->is_string_type, "Not is_string_type" );
+ok( $string_type->is_string_type, "is_string_type" );
+
Added: incubator/lucy/trunk/import/clownfish/t/106-va_list_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/106-va_list_type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/106-va_list_type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/106-va_list_type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use Clownfish::Type::VAList;
+use Clownfish::Parser;
+
+my $va_list_type = Clownfish::Type::VAList->new;
+is( $va_list_type->get_specifier,
+ "va_list", "specifier defaults to 'va_list'" );
+is( $va_list_type->to_c, "va_list", "to_c" );
+
+my $parser = Clownfish::Parser->new;
+
+is( $parser->va_list_type_specifier('va_list'),
+ 'va_list', 'va_list_type_specifier' );
+isa_ok( $parser->va_list_type('va_list'), "Clownfish::Type::VAList" );
+ok( !$parser->va_list_type_specifier('va_listable'),
+ "va_list_type_specifier guards against partial word matches"
+);
+
Added: incubator/lucy/trunk/import/clownfish/t/107-arbitrary_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/107-arbitrary_type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/107-arbitrary_type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/107-arbitrary_type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,45 @@
+use strict;
+use warnings;
+
+use Test::More tests => 12;
+use Clownfish::Type::Arbitrary;
+use Clownfish::Parser;
+
+my $foo_type = Clownfish::Type::Arbitrary->new(
+ parcel => 'Neato',
+ specifier => "foo_t",
+);
+is( $foo_type->get_specifier, "foo_t", "get_specifier" );
+is( $foo_type->to_c, "foo_t", "to_c" );
+
+my $compare_t_type = Clownfish::Type::Arbitrary->new(
+ parcel => 'Neato',
+ specifier => "Sort_compare_t",
+);
+is( $compare_t_type->get_specifier,
+ "neato_Sort_compare_t", "Prepend prefix to specifier" );
+is( $compare_t_type->to_c, "neato_Sort_compare_t", "to_c" );
+
+my $evil_twin = Clownfish::Type::Arbitrary->new(
+ parcel => 'Neato',
+ specifier => "foo_t",
+);
+ok( $foo_type->equals($evil_twin), "equals" );
+ok( !$foo_type->equals($compare_t_type),
+ "equals spoiled by different specifier"
+);
+
+my $parser = Clownfish::Parser->new;
+
+for my $specifier (qw( foo_t Sort_compare_t )) {
+ is( $parser->arbitrary_type_specifier($specifier),
+ $specifier, 'arbitrary_type_specifier' );
+ isa_ok(
+ $parser->arbitrary_type($specifier),
+ "Clownfish::Type::Arbitrary"
+ );
+ ok( !$parser->arbitrary_type_specifier( $specifier . "_y_p_e" ),
+ "arbitrary_type_specifier guards against partial word matches"
+ );
+}
+
Added: incubator/lucy/trunk/import/clownfish/t/108-composite_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/108-composite_type.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/108-composite_type.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/108-composite_type.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,78 @@
+use strict;
+use warnings;
+
+use Test::More tests => 24;
+use Clownfish::Type::Object;
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+
+is( $parser->type_postfix($_), $_, "postfix: $_" )
+ for ( '[]', '[A_CONSTANT]', '*' );
+is( $parser->type_postfix('[ FOO ]'), '[FOO]', "type_postfix: [ FOO ]" );
+
+my @composite_type_strings = (
+ qw(
+ char*
+ char**
+ char***
+ int32_t*
+ Obj**
+ neato_method_t[]
+ neato_method_t[1]
+ multi_dimensional_t[SOME][A_FEW]
+ ),
+ 'char * * ',
+ 'const Obj**',
+ 'const void*',
+);
+
+for my $input (@composite_type_strings) {
+ isa_ok( $parser->type($input),
+ "Clownfish::Type::Composite", $input );
+}
+
+eval { my $type = Clownfish::Type::Composite->new };
+like( $@, qr/child/i, "child required" );
+
+my $foo_type = Clownfish::Type::Object->new( specifier => 'Foo' );
+my $composite_type = Clownfish::Type::Composite->new(
+ child => $foo_type,
+ indirection => 1,
+);
+is( $composite_type->get_specifier,
+ 'Foo', "get_specifier delegates to child" );
+
+my $other = Clownfish::Type::Composite->new(
+ child => $foo_type,
+ indirection => 1,
+);
+ok( $composite_type->equals($other), "equals" );
+ok( $composite_type->is_composite, "is_composite" );
+
+my $bar_type = Clownfish::Type::Object->new( specifier => 'Bar' );
+my $bar_composite = Clownfish::Type::Composite->new(
+ child => $bar_type,
+ indirection => 1,
+);
+ok( !$composite_type->equals($bar_composite),
+ "equals spoiled by different child"
+);
+
+my $foo_array = $parser->type("foo_t[]")
+ or die "Can't parse foo_t[]";
+is( $foo_array->get_array, '[]', "get_array" );
+unlike( $foo_array->to_c, qr/\[\]/, "array subscripts not included by to_c" );
+
+my $foo_array_array = $parser->type("foo_t[][]")
+ or die "Can't parse foo_t[][]";
+ok( !$foo_array->equals($foo_array_array),
+ "equals spoiled by different array postfixes"
+);
+
+my $foo_star = $parser->type("foo_t*")
+ or die "Can't parse foo_t*";
+my $foo_star_star = $parser->type("foo_t**")
+ or die "Can't parse foo_t**";
+ok( !$foo_star->equals($foo_star_star),
+ "equals spoiled by different levels of indirection" );
Added: incubator/lucy/trunk/import/clownfish/t/200-function.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/200-function.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/200-function.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/200-function.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+
+BEGIN { use_ok('Clownfish::Function') }
+use Clownfish::Parser;
+use Clownfish::Parcel;
+
+my $parser = Clownfish::Parser->new;
+$parser->parcel_definition('parcel Neato;')
+ or die "failed to process parcel_definition";
+
+my %args = (
+ parcel => 'Neato',
+ return_type => $parser->type('Obj*'),
+ class_name => 'Neato::Foo',
+ class_cnick => 'Foo',
+ param_list => $parser->param_list('(int32_t some_num)'),
+ micro_sym => 'return_an_obj',
+);
+
+my $func = Clownfish::Function->new(%args);
+isa_ok( $func, "Clownfish::Function" );
+
+eval { my $death = Clownfish::Function->new( %args, extra_arg => undef ) };
+like( $@, qr/extra_arg/, "Extra arg kills constructor" );
+
+eval { Clownfish::Function->new( %args, micro_sym => 'Uh_Oh' ); };
+like( $@, qr/Uh_Oh/, "invalid micro_sym kills constructor" );
+
+my %sub_args = ( class => 'Neato::Obj', cnick => 'Obj' );
+
+isa_ok(
+ $parser->subroutine_declaration_statement( $_, 0, %sub_args, inert => 1 )
+ ->{declared},
+ "Clownfish::Function",
+ "function declaration: $_"
+ )
+ for (
+ 'inert int running_count(int biscuit);',
+ 'public inert Hash* init_fave_hash(int32_t num_buckets, bool_t o_rly);',
+ );
Added: incubator/lucy/trunk/import/clownfish/t/201-method.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/201-method.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/201-method.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/201-method.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,121 @@
+use strict;
+use warnings;
+
+use Test::More tests => 30;
+
+BEGIN { use_ok('Clownfish::Method') }
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+$parser->parcel_definition('parcel Neato;')
+ or die "failed to process parcel_definition";
+
+my %args = (
+ parcel => 'Neato',
+ return_type => $parser->type('Obj*'),
+ class_name => 'Neato::Foo',
+ class_cnick => 'Foo',
+ param_list => $parser->param_list('(Foo *self, int32_t count = 0)'),
+ macro_sym => 'Return_An_Obj',
+);
+
+my $method = Clownfish::Method->new(%args);
+isa_ok( $method, "Clownfish::Method" );
+
+ok( $method->parcel, "parcel exposure by default" );
+
+eval { my $death = Clownfish::Method->new( %args, extra_arg => undef ) };
+like( $@, qr/extra_arg/, "Extra arg kills constructor" );
+
+eval { Clownfish::Method->new( %args, macro_sym => 'return_an_obj' ); };
+like( $@, qr/macro_sym/, "Invalid macro_sym kills constructor" );
+
+my $dupe = Clownfish::Method->new(%args);
+ok( $method->compatible($dupe), "compatible()" );
+
+my $macro_sym_differs = Clownfish::Method->new( %args, macro_sym => 'Eat' );
+ok( !$method->compatible($macro_sym_differs),
+ "different macro_sym spoils compatible()"
+);
+ok( !$macro_sym_differs->compatible($method), "... reversed" );
+
+my $extra_param = Clownfish::Method->new( %args,
+ param_list =>
+ $parser->param_list('(Foo *self, int32_t count = 0, int b)'), );
+ok( !$method->compatible($macro_sym_differs),
+ "extra param spoils compatible()"
+);
+ok( !$extra_param->compatible($method), "... reversed" );
+
+my $default_differs = Clownfish::Method->new( %args,
+ param_list => $parser->param_list('(Foo *self, int32_t count = 1)'), );
+ok( !$method->compatible($default_differs),
+ "different initial_value spoils compatible()"
+);
+ok( !$default_differs->compatible($method), "... reversed" );
+
+my $missing_default = Clownfish::Method->new( %args,
+ param_list => $parser->param_list('(Foo *self, int32_t count)'), );
+ok( !$method->compatible($missing_default),
+ "missing initial_value spoils compatible()"
+);
+ok( !$missing_default->compatible($method), "... reversed" );
+
+my $param_name_differs = Clownfish::Method->new( %args,
+ param_list => $parser->param_list('(Foo *self, int32_t countess)'), );
+ok( !$method->compatible($param_name_differs),
+ "different param name spoils compatible()"
+);
+ok( !$param_name_differs->compatible($method), "... reversed" );
+
+my $param_type_differs = Clownfish::Method->new( %args,
+ param_list => $parser->param_list('(Foo *self, uint32_t count)'), );
+ok( !$method->compatible($param_type_differs),
+ "different param type spoils compatible()"
+);
+ok( !$param_type_differs->compatible($method), "... reversed" );
+
+my $self_type_differs = Clownfish::Method->new(
+ %args,
+ class_name => 'Neato::Bar',
+ class_cnick => 'Bar',
+ param_list => $parser->param_list('(Bar *self, int32_t count = 0)'),
+);
+ok( $method->compatible($self_type_differs),
+ "different self type still compatible(), since can't test inheritance" );
+ok( $self_type_differs->compatible($method), "... reversed" );
+
+my $not_final = Clownfish::Method->new(%args);
+my $final = $not_final->finalize;
+
+eval { $method->override($final); };
+like( $@, qr/final/i, "Can't override final method" );
+
+delete $not_final->{final};
+delete $final->{final};
+is_deeply( $not_final, $final, "Finalize clones properly" );
+
+for my $meth_meth (qw( short_method_sym full_method_sym full_offset_sym)) {
+ eval { my $blah = $method->$meth_meth; };
+ like( $@, qr/invoker/, "$meth_meth requires invoker" );
+}
+
+my %sub_args = ( class => 'Neato::Obj', cnick => 'Obj' );
+
+isa_ok(
+ $parser->subroutine_declaration_statement( $_, 0, %sub_args )->{declared},
+ "Clownfish::Method",
+ "method declaration: $_"
+ )
+ for (
+ 'public int Do_Foo(Obj *self);',
+ 'parcel Obj* Gimme_An_Obj(Obj *self);',
+ 'void Do_Whatever(Obj *self, uint32_t a_num, float real);',
+ 'private Foo* Fetch_Foo(Obj *self, int num);',
+ );
+
+ok( $parser->subroutine_declaration_statement( $_, 0, %sub_args )->{declared}
+ ->final,
+ "final method: $_"
+) for ( 'public final void The_End(Obj *self);', );
+
Added: incubator/lucy/trunk/import/clownfish/t/202-overridden_method.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/202-overridden_method.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/202-overridden_method.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/202-overridden_method.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+use Clownfish::Method;
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+$parser->parcel_definition('parcel Neato;')
+ or die "failed to process parcel_definition";
+
+my %args = (
+ return_type => $parser->type('Obj*'),
+ class_name => 'Neato::Foo',
+ class_cnick => 'Foo',
+ param_list => $parser->param_list('(Foo *self)'),
+ macro_sym => 'Return_An_Obj',
+ parcel => 'Neato',
+);
+
+my $orig = Clownfish::Method->new(%args);
+my $overrider = Clownfish::Method->new(
+ %args,
+ param_list => $parser->param_list('(FooJr *self)'),
+ class_name => 'Neato::Foo::FooJr',
+ class_cnick => 'FooJr'
+);
+$overrider->override($orig);
+ok( !$overrider->novel );
+
Added: incubator/lucy/trunk/import/clownfish/t/203-final_method.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/203-final_method.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/203-final_method.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/203-final_method.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+$parser->parcel_definition('parcel Neato;')
+ or die "failed to process parcel_definition";
+
+my %args = (
+ return_type => $parser->type('Obj*'),
+ class_name => 'Neato::Foo',
+ class_cnick => 'Foo',
+ param_list => $parser->param_list('(Foo* self)'),
+ macro_sym => 'Return_An_Obj',
+ parcel => 'Neato',
+);
+
+my $not_final_method = Clownfish::Method->new(%args);
+my $final_method = $not_final_method->finalize;
+ok( !$not_final_method->final, "not final by default" );
+ok( $final_method->final, "finalize" );
+
Added: incubator/lucy/trunk/import/clownfish/t/300-variable.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/300-variable.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/300-variable.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/300-variable.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,61 @@
+use strict;
+use warnings;
+
+use Test::More tests => 13;
+use Clownfish::Type;
+use Clownfish::Parser;
+
+BEGIN { use_ok('Clownfish::Variable') }
+
+my $parser = Clownfish::Parser->new;
+$parser->parcel_definition('parcel Neato;')
+ or die "failed to process parcel_definition";
+
+sub new_type { $parser->type(shift) }
+
+eval {
+ my $death = Clownfish::Variable->new(
+ micro_sym => 'foo',
+ type => new_type('int'),
+ extra_arg => undef,
+ );
+};
+like( $@, qr/extra_arg/, "Extra arg kills constructor" );
+
+eval { my $death = Clownfish::Variable->new( micro_sym => 'foo' ) };
+like( $@, qr/type/, "type is required" );
+eval { my $death = Clownfish::Variable->new( type => new_type('int32_t') ) };
+like( $@, qr/micro_sym/, "micro_sym is required" );
+
+my $var = Clownfish::Variable->new(
+ micro_sym => 'foo',
+ type => new_type('float*')
+);
+is( $var->local_c, 'float* foo', "local_c" );
+is( $var->local_declaration, 'float* foo;', "declaration" );
+ok( $var->local, "default to local access" );
+
+$var = Clownfish::Variable->new(
+ micro_sym => 'foo',
+ type => new_type('float[1]')
+);
+is( $var->local_c, 'float foo[1]',
+ "to_c appends array to var name rather than type specifier" );
+
+$var = Clownfish::Variable->new(
+ parcel => 'Neato',
+ micro_sym => 'foo',
+ type => new_type("Foo*"),
+ class_name => 'Crustacean::Lobster::LobsterClaw',
+ class_cnick => 'LobClaw',
+);
+is( $var->global_c, 'neato_Foo* neato_LobClaw_foo', "global_c" );
+
+isa_ok( $parser->var_declaration_statement($_)->{declared},
+ "Clownfish::Variable", "var_declaration_statement: $_" )
+ for (
+ 'parcel int foo;',
+ 'private Obj *obj;',
+ 'public inert int32_t **foo;',
+ 'Dog *fido;'
+ );
Added: incubator/lucy/trunk/import/clownfish/t/301-param_list.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/301-param_list.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/301-param_list.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/301-param_list.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,35 @@
+use strict;
+use warnings;
+
+use Test::More tests => 13;
+
+BEGIN { use_ok('Clownfish::ParamList') }
+use Clownfish::Type;
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+$parser->parcel_definition('parcel Neato;')
+ or die "failed to process parcel_definition";
+
+isa_ok( $parser->param_variable($_),
+ "Clownfish::Variable", "param_variable: $_" )
+ for ( 'uint32_t baz', 'CharBuf *stuff', 'float **ptr', );
+
+my $param_list = $parser->param_list("(Obj *self, int num)");
+isa_ok( $param_list, "Clownfish::ParamList" );
+ok( !$param_list->variadic, "not variadic" );
+is( $param_list->to_c, 'neato_Obj* self, int num', "to_c" );
+is( $param_list->name_list, 'self, num', "name_list" );
+
+$param_list = $parser->param_list("(Obj *self=NULL, int num, ...)");
+ok( $param_list->variadic, "variadic" );
+is_deeply(
+ $param_list->get_initial_values,
+ [ "NULL", undef ],
+ "initial_values"
+);
+is( $param_list->to_c, 'neato_Obj* self, int num, ...', "to_c" );
+is( $param_list->num_vars, 2, "num_vars" );
+isa_ok( $param_list->get_variables->[0],
+ "Clownfish::Variable", "get_variables..." );
+
Added: incubator/lucy/trunk/import/clownfish/t/400-class.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/400-class.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/400-class.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/400-class.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,219 @@
+use strict;
+use warnings;
+
+use Test::More tests => 53;
+use Clownfish::Class;
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+
+my $thing = Clownfish::Variable->new(
+ parcel => 'Neato',
+ class_name => 'Foo',
+ type => $parser->type('Thing*'),
+ micro_sym => 'thing',
+);
+my $widget = Clownfish::Variable->new(
+ class_name => 'Widget',
+ type => $parser->type('Widget*'),
+ micro_sym => 'widget',
+);
+my $tread_water = Clownfish::Function->new(
+ parcel => 'Neato',
+ class_name => 'Foo',
+ return_type => $parser->type('void'),
+ micro_sym => 'tread_water',
+ param_list => $parser->param_list('()'),
+);
+my %foo_create_args = (
+ parcel => 'Neato',
+ class_name => 'Foo',
+ member_vars => [$thing],
+ inert_vars => [$widget],
+ functions => [$tread_water],
+);
+
+my $foo = Clownfish::Class->create(%foo_create_args);
+eval { Clownfish::Class->create(%foo_create_args) };
+like( $@, qr/conflict/i,
+ "Can't call create for the same class more than once" );
+my $should_be_foo = Clownfish::Class->fetch_singleton(
+ parcel => 'Neato',
+ class_name => 'Foo',
+);
+is( $foo, $should_be_foo, "fetch_singleton" );
+
+my $foo_jr = Clownfish::Class->create(
+ parcel => 'Neato',
+ class_name => 'Foo::FooJr',
+ parent_class_name => 'Foo',
+ attributes => { dumpable => 1 },
+);
+
+ok( $foo_jr->has_attribute('dumpable'), 'has_attribute' );
+is( $foo_jr->get_struct_sym, 'FooJr', "struct_sym" );
+is( $foo_jr->full_struct_sym, 'neato_FooJr', "full_struct_sym" );
+
+my $final_foo = Clownfish::Class->create(
+ parcel => 'Neato',
+ class_name => 'Foo::FooJr::FinalFoo',
+ parent_class_name => 'Foo::FooJr',
+ source_class => 'Foo::FooJr',
+ final => 1,
+ attributes => { dumpable => 1 },
+);
+ok( $final_foo->final, "final" );
+is( $final_foo->file_path( '/path/to', '.c', ),
+ '/path/to/Foo/FooJr.c', "file_path" );
+is( $final_foo->include_h, 'Foo/FooJr.h', "inlude_h uses source_class" );
+is( $final_foo->get_parent_class_name, 'Foo::FooJr',
+ "get_parent_class_name" );
+
+my $do_stuff
+ = $parser->subroutine_declaration_statement( 'void Do_Stuff(Foo *self);',
+ 0, class => 'Foo' )->{declared}
+ or die "parsing failure";
+$foo->add_method($do_stuff);
+
+my $inert_do_stuff
+ = $parser->subroutine_declaration_statement(
+ 'void Do_Stuff(InertFoo *self);',
+ 0, class => 'InertFoo' )->{declared}
+ or die "parsing failure";
+my %inert_args = (
+ parcel => 'Neato',
+ class_name => 'InertFoo',
+ inert => 1,
+);
+eval {
+ Clownfish::Class->create( %inert_args, methods => [$inert_do_stuff] );
+};
+like(
+ $@,
+ qr/inert class/i,
+ "Error out on conflict between inert attribute and object method"
+);
+
+$foo->add_child($foo_jr);
+$foo_jr->add_child($final_foo);
+$foo->grow_tree;
+eval { $foo->grow_tree };
+like( $@, qr/grow_tree/, "call grow_tree only once." );
+eval { $foo_jr->add_method($do_stuff) };
+like( $@, qr/grow_tree/, "Forbid add_method after grow_tree." );
+
+is( $foo_jr->get_parent, $foo, "grow_tree, one level" );
+is( $final_foo->get_parent, $foo_jr, "grow_tree, two levels" );
+is( $foo->novel_method("Do_Stuff"), $do_stuff, 'novel_method' );
+is( $foo_jr->method("Do_Stuff"), $do_stuff, "inherited method" );
+ok( !$foo_jr->novel_method("Do_Stuff"), 'inherited method not novel' );
+ok( $final_foo->method("Do_Stuff")->final, "Finalize inherited method" );
+ok( !$foo_jr->method("Do_Stuff")->final, "Don't finalize method in parent" );
+is_deeply( [ $foo->inert_vars ], [$widget], "inert vars" );
+is_deeply( [ $foo->functions ], [$tread_water], "inert funcs" );
+is_deeply( [ $foo->methods ], [$do_stuff], "methods" );
+is_deeply( [ $foo->novel_methods ], [$do_stuff], "novel_methods" );
+is_deeply( [ $foo->novel_member_vars ], [$thing], "novel_member_vars" );
+is_deeply( [ $foo_jr->member_vars ], [$thing], "inherit member vars" );
+is_deeply( [ $foo_jr->functions ], [], "don't inherit inert funcs" );
+is_deeply( [ $foo_jr->novel_member_vars ], [], "novel_member_vars" );
+is_deeply( [ $foo_jr->inert_vars ], [], "don't inherit inert vars" );
+is_deeply( [ $final_foo->novel_methods ], [], "novel_methods" );
+
+like( $foo_jr->get_autocode, qr/load/i, "autogenerate Dump/Load" );
+is_deeply(
+ [ $foo->tree_to_ladder ],
+ [ $foo, $foo_jr, $final_foo ],
+ 'tree_to_ladder'
+);
+
+ok( $parser->class_modifier($_), "class_modifier: $_" )
+ for (qw( abstract inert ));
+
+ok( $parser->class_inheritance($_), "class_inheritance: $_" )
+ for ( 'inherits Foo', 'inherits Foo::FooJr::FooIII' );
+
+my $class_content
+ = 'public class Foo::FooJr cnick FooJr inherits Foo { private int num; }';
+my $class = $parser->class_declaration($class_content);
+isa_ok( $class, "Clownfish::Class", "class_declaration FooJr" );
+ok( ( scalar grep { $_->micro_sym eq 'num' } $class->member_vars ),
+ "parsed private member var" );
+
+$class_content = q|
+ /**
+ * Bow wow.
+ *
+ * Wow wow wow.
+ */
+ public class Animal::Dog inherits Animal : lovable : drooly {
+ public inert Dog* init(Dog *self, CharBuf *name, CharBuf *fave_food);
+ inert uint32_t count();
+ inert uint64_t num_dogs;
+
+ private CharBuf *name;
+ private bool_t likes_to_go_fetch;
+ private void Chase_Tail(Dog *self);
+
+ ChewToy *squishy;
+
+ void Destroy(Dog *self);
+ public CharBuf* Bark(Dog *self);
+ public void Eat(Dog *self);
+ public void Bite(Dog *self, Enemy *enemy);
+ public Thing *Fetch(Dog *self, Thing *thing);
+ public final void Bury(Dog *self, Bone *bone);
+ public Owner *mom;
+ public abstract incremented nullable Thing*
+ Scratch(Dog *self);
+
+ int32_t[1] flexible_array_at_end_of_struct;
+ }
+|;
+
+$class = $parser->class_declaration($class_content);
+isa_ok( $class, "Clownfish::Class", "class_declaration Dog" );
+ok( ( scalar grep { $_->micro_sym eq 'num_dogs' } $class->inert_vars ),
+ "parsed inert var" );
+ok( ( scalar grep { $_->micro_sym eq 'mom' } $class->member_vars ),
+ "parsed public member var" );
+ok( ( scalar grep { $_->micro_sym eq 'squishy' } $class->member_vars ),
+ "parsed parcel member var" );
+ok( ( scalar grep { $_->micro_sym eq 'init' } $class->functions ),
+ "parsed function" );
+ok( ( scalar grep { $_->micro_sym eq 'chase_tail' } $class->methods ),
+ "parsed private method" );
+ok( ( scalar grep { $_->micro_sym eq 'destroy' } $class->methods ),
+ "parsed parcel method" );
+ok( ( scalar grep { $_->micro_sym eq 'bury' } $class->methods ),
+ "parsed public method" );
+ok( ( scalar grep { $_->micro_sym eq 'scratch' } $class->methods ),
+ "parsed public abstract nullable method" );
+for my $method ($class->methods) {
+ if ($method->micro_sym eq 'scratch') {
+ ok( $method->{return_type}->nullable,
+ "public abstract incremented nullable flagged as nullable");
+ }
+}
+is( ( scalar grep { $_->public } $class->methods ),
+ 6, "pass acl to Method constructor" );
+ok( $class->has_attribute('lovable'), "parsed class attribute" );
+ok( $class->has_attribute('drooly'), "parsed second class attribute" );
+
+$class_content = qq|
+ parcel inert class Rigor::Mortis cnick Mort {
+ parcel inert void lie_still();
+ }|;
+$class = $parser->class_declaration($class_content);
+isa_ok( $class, "Clownfish::Class", "inert class_declaration" );
+ok( $class->inert, "inert modifier parsed and passed to constructor" );
+
+$class_content = qq|
+ final class Ultimo {
+ /** Throws an error.
+ */
+ void Say_Never(Ultimo *self);
+ }|;
+$class = $parser->class_declaration($class_content);
+ok( $class->final, "final class_declaration" );
+
Added: incubator/lucy/trunk/import/clownfish/t/401-c_block.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/401-c_block.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/401-c_block.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/401-c_block.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+use Clownfish::CBlock;
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+
+my $block = Clownfish::CBlock->new( contents => 'int foo;' );
+isa_ok( $block, "Clownfish::CBlock" );
+is( $block->get_contents, 'int foo;', "get_contents" );
+eval { Clownfish::CBlock->new };
+like( $@, qr/contents/, "content required" );
+
+$block = $parser->embed_c(qq| __C__\n#define FOO 1\n__END_C__ |);
+
+isa_ok( $block, "Clownfish::CBlock" );
+is( $block->get_contents, "#define FOO 1\n", "parse embed_c" );
+
Added: incubator/lucy/trunk/import/clownfish/t/402-parcel.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/402-parcel.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/402-parcel.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/402-parcel.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+
+BEGIN { use_ok('Clownfish::Parcel') }
+
+package ClownfishyThing;
+use base qw( Clownfish::Symbol );
+
+sub new {
+ return shift->SUPER::new( micro_sym => 'sym', exposure => 'parcel', @_ );
+}
+
+package main;
+
+# Register singleton.
+Clownfish::Parcel->singleton( name => 'Crustacean', cnick => 'Crust', );
+
+my $thing = ClownfishyThing->new;
+is( $thing->get_prefix, '', 'get_prefix with no parcel' );
+is( $thing->get_Prefix, '', 'get_Prefix with no parcel' );
+is( $thing->get_PREFIX, '', 'get_PREFIx with no parcel' );
+
+$thing = ClownfishyThing->new( parcel => 'Crustacean' );
+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' );
+
Added: incubator/lucy/trunk/import/clownfish/t/403-file.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/403-file.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/403-file.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/403-file.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,57 @@
+use strict;
+use warnings;
+
+use Test::More tests => 17;
+
+use Clownfish::File;
+use Clownfish::Parser;
+
+my $parser = Clownfish::Parser->new;
+
+my $parcel_declaration = "parcel Stuff;";
+my $class_content = qq|
+ class Stuff::Thing {
+ Foo *foo;
+ Bar *bar;
+ }
+|;
+my $c_block = "__C__\nint foo;\n__END_C__\n";
+
+my $file = $parser->file( "$parcel_declaration\n$class_content\n$c_block",
+ 0, source_class => 'Stuff::Thing' );
+
+is( $file->get_source_class, "Stuff::Thing", "get_source_class" );
+
+my $guard_name = $file->guard_name;
+is( $guard_name, "H_STUFF_THING", "guard_name" );
+like( $file->guard_start, qr/$guard_name/, "guard_start" );
+like( $file->guard_close, qr/$guard_name/,
+ "guard_close includes guard_name" );
+
+ok( !$file->get_modified, "modified false at start" );
+$file->set_modified(1);
+ok( $file->get_modified, "set_modified, get_modified" );
+
+is( $file->cfh_path('/path/to'), "/path/to/Stuff/Thing.cfh", "cfh_path" );
+is( $file->c_path('/path/to'), "/path/to/Stuff/Thing.c", "c_path" );
+is( $file->h_path('/path/to'), "/path/to/Stuff/Thing.h", "h_path" );
+
+my @classes = $file->classes;
+is( scalar @classes, 1, "classes() filters blocks" );
+my $class = $classes[0];
+my ( $foo, $bar ) = $class->member_vars;
+is( $foo->get_type->get_specifier,
+ 'stuff_Foo', 'file production picked up parcel def' );
+is( $bar->get_type->get_specifier, 'stuff_Bar', 'parcel def is sticky' );
+
+my @blocks = $file->blocks;
+is( scalar @blocks, 3, "all three blocks" );
+isa_ok( $blocks[0], "Clownfish::Parcel" );
+isa_ok( $blocks[1], "Clownfish::Class" );
+isa_ok( $blocks[2], "Clownfish::CBlock" );
+
+$file = $parser->file( $class_content, 0, source_class => 'Stuff::Thing' );
+($class) = $file->classes;
+( $foo, $bar ) = $class->member_vars;
+is( $foo->get_type->get_specifier, 'Foo', 'file production resets parcel' );
+
Added: incubator/lucy/trunk/import/clownfish/t/500-hierarchy.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/500-hierarchy.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/500-hierarchy.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/500-hierarchy.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,76 @@
+use strict;
+use warnings;
+
+use Test::More tests => 18;
+
+use Clownfish::Hierarchy;
+use Clownfish::Util qw( a_isa_b );
+use File::Spec::Functions qw( catfile splitpath );
+use Fcntl;
+use File::Path qw( rmtree mkpath );
+
+my %args = (
+ source => 't/cfsource',
+ dest => 't/cfdest',
+);
+
+# Clean up.
+rmtree( $args{dest} );
+
+eval { my $death = Clownfish::Hierarchy->new( %args, extra_arg => undef ) };
+like( $@, qr/extra_arg/, "Extra arg kills constructor" );
+
+my $hierarchy = Clownfish::Hierarchy->new(%args);
+isa_ok( $hierarchy, "Clownfish::Hierarchy" );
+is( $hierarchy->get_source, $args{source}, "get_source" );
+is( $hierarchy->get_dest, $args{dest}, "get_dest" );
+
+$hierarchy->build;
+
+my @files = $hierarchy->files;
+is( scalar @files, 3, "recursed and found all three files" );
+my %files;
+for my $file (@files) {
+ die "not a File" unless isa_ok( $file, "Clownfish::File" );
+ ok( !$file->get_modified, "start off not modified" );
+ my ($class) = grep { a_isa_b( $_, "Clownfish::Class" ) } $file->blocks;
+ die "no class" unless $class;
+ $files{ $class->get_class_name } = $file;
+}
+my $animal = $files{'Animal'} or die "No Animal";
+my $dog = $files{'Animal::Dog'} or die "No Dog";
+my $util = $files{'Animal::Util'} or die "No Util";
+
+my @classes = $hierarchy->ordered_classes;
+is( scalar @classes, 3, "all classes" );
+for my $class (@classes) {
+ die "not a Class" unless isa_ok( $class, "Clownfish::Class" );
+}
+
+# Generate fake C files, with times set to one second ago.
+my $one_second_ago = time() - 1;
+for my $file (@files) {
+ my $h_path = $file->h_path( $args{dest} );
+ my ( undef, $dir, undef ) = splitpath($h_path);
+ mkpath($dir);
+ sysopen( my $fh, $h_path, O_CREAT | O_EXCL | O_WRONLY )
+ or die "Can't open '$h_path': $!";
+ print $fh "#include <stdio.h>\n"; # fake content.
+ close $fh or die "Can't close '$h_path': $!";
+ utime( $one_second_ago, $one_second_ago, $h_path )
+ or die "utime failed for '$h_path': $!";
+}
+
+my $path_to_animal_cf = $animal->cfh_path( $args{source} );
+utime( undef, undef, $path_to_animal_cf )
+ or die "utime for '$path_to_animal_cf' failed"; # touch
+
+$hierarchy->propagate_modified;
+
+ok( $animal->get_modified, "Animal modified" );
+ok( $dog->get_modified, "Parent's modification propagates to child's file" );
+ok( !$util->get_modified, "modification doesn't propagate to inert class" );
+
+# Clean up.
+rmtree( $args{dest} );
+
Added: incubator/lucy/trunk/import/clownfish/t/600-parser.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/600-parser.t?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/600-parser.t (added)
+++ incubator/lucy/trunk/import/clownfish/t/600-parser.t Thu Oct 14 08:48:04 2010
@@ -0,0 +1,148 @@
+use strict;
+use warnings;
+
+use Test::More tests => 116;
+
+BEGIN { use_ok('Clownfish::Parser') }
+
+my $parser = Clownfish::Parser->new;
+isa_ok( $parser, "Clownfish::Parser" );
+
+isa_ok( $parser->parcel_definition("parcel Fish;"),
+ "Clownfish::Parcel", "parcel_definition" );
+isa_ok( $parser->parcel_definition("parcel Crustacean cnick Crust;"),
+ "Clownfish::Parcel", "parcel_definition with cnick" );
+
+# Set and leave parcel.
+my $parcel = $parser->parcel_definition('parcel Crustacean cnick Crust;')
+ or die "failed to process parcel_definition";
+is( $Clownfish::Parser::parcel, $parcel,
+ "parcel_definition sets internal \$parcel var" );
+
+is( $parser->strip_plain_comments("/*x*/"),
+ " ", "comments replaced by spaces" );
+is( $parser->strip_plain_comments("/**x*/"),
+ "/**x*/", "docu-comment untouched" );
+is( $parser->strip_plain_comments("/*\n*/"), " \n ", "newline preserved" );
+
+for (qw( foo _foo foo_yoo FOO Foo fOO f00 )) {
+ is( $parser->identifier($_), $_, "identifier: $_" );
+}
+
+for (qw( void unsigned float uint32_t int64_t uint8_t bool_t )) {
+ ok( !$parser->identifier($_), "reserved word not an identifier: $_" );
+}
+
+is( $parser->chy_integer_specifier($_), $_, "Charmony integer specifier $_" )
+ for qw( bool_t );
+
+is( $parser->object_type_specifier($_), $_, "object_type_specifier $_" )
+ for qw( ByteBuf Obj ANDScorer );
+
+is( $parser->type_specifier($_), $_, "type_specifier $_" )
+ for qw( uint32_t char int short long float double void ANDScorer );
+
+is( $parser->type_qualifier($_), $_, "type_qualifier $_" ) for qw( const );
+
+is( $parser->exposure_specifier($_), $_, "exposure_specifier $_" )
+ for qw( public private parcel );
+
+is( $parser->type_postfix($_), $_, "postfix: $_" )
+ for ( '[]', '[A_CONSTANT]', '*' );
+is( $parser->type_postfix('[ FOO ]'), '[FOO]', "type_postfix: [ FOO ]" );
+
+isa_ok( $parser->type($_), "Clownfish::Type", "type $_" )
+ for ( 'const char *', 'Obj*', 'i32_t', 'char[]', 'long[1]',
+ 'i64_t[FOO]' );
+
+is( $parser->declarator($_), $_, "declarator: $_" )
+ for ( 'foo', 'bar_bar_bar' );
+
+isa_ok( $parser->param_variable($_),
+ "Clownfish::Variable", "param_variable: $_" )
+ for ( 'uint32_t baz;', 'CharBuf *stuff;', 'float **ptr;', );
+
+isa_ok( $parser->var_declaration_statement($_)->{declared},
+ "Clownfish::Variable", "var_declaration_statement: $_" )
+ for (
+ 'parcel int foo;',
+ 'private Obj *obj;',
+ 'public inert i32_t **foo;',
+ 'Dog *fido;'
+ );
+
+is( $parser->hex_constant($_), $_, "hex_constant: $_" )
+ for (qw( 0x1 0x0a 0xFFFFFFFF ));
+
+is( $parser->integer_constant($_), $_, "integer_constant: $_" )
+ for (qw( 1 -9999 0 10000 ));
+
+is( $parser->float_constant($_), $_, "float_constant: $_" )
+ for (qw( 1.0 -9999.999 0.1 0.0 ));
+
+is( $parser->string_literal($_), $_, "string_literal: $_" )
+ for ( q|"blah"|, q|"blah blah"|, q|"\\"blah\\" \\"blah\\""| );
+
+is( $parser->scalar_constant($_), $_, "scalar_constant: $_" )
+ for ( q|"blah"|, 1, 1.2, "0xFC" );
+
+my @composites = ( 'int[]', "i32_t **", "Foo **", "Foo ***", "const void *" );
+for my $composite (@composites) {
+ my $parsed = $parser->type($composite);
+ isa_ok(
+ $parsed,
+ "Clownfish::Type::Composite",
+ "composite_type: $composite"
+ );
+}
+
+my @object_types = ( 'Obj *', "incremented Foo*", "decremented CharBuf *" );
+for my $object_type (@object_types) {
+ my $parsed = $parser->object_type($object_type);
+ isa_ok( $parsed, "Clownfish::Type::Object",
+ "object_type: $object_type" );
+}
+
+my %param_lists = (
+ '(int foo)' => 1,
+ '(Obj *foo, Foo **foo_ptr)' => 2,
+ '()' => 0,
+);
+while ( my ( $param_list, $num_params ) = each %param_lists ) {
+ my $parsed = $parser->param_list($param_list);
+ isa_ok( $parsed, "Clownfish::ParamList", "param_list: $param_list" );
+}
+ok( $parser->param_list("(int foo, ...)")->variadic, "variadic param list" );
+my $param_list = $parser->param_list(q|(int foo = 0xFF, char *bar ="blah")|);
+is_deeply(
+ $param_list->get_initial_values,
+ [ '0xFF', '"blah"' ],
+ "initial values"
+);
+
+my %sub_args = ( class => 'Stuff::Obj', cnick => 'Obj' );
+
+ok( $parser->declaration_statement( $_, 0, %sub_args, inert => 1 ),
+ "declaration_statment: $_" )
+ for (
+ 'public Foo* Spew_Foo(Obj *self, uint32_t *how_many);',
+ 'private Hash *hash;',
+ );
+
+is( $parser->object_type_specifier($_), $_, "object_type_specifier: $_" )
+ for (qw( Foo FooJr FooIII Foo4th ));
+
+ok( !$parser->object_type_specifier($_), "illegal object_type_specifier: $_" )
+ for (qw( foo fooBar Foo_Bar FOOBAR 1Foo 1FOO ));
+
+is( $parser->class_name($_), $_, "class_name: $_" )
+ for (qw( Foo Foo::FooJr Foo::FooJr::FooIII Foo::FooJr::FooIII::Foo4th ));
+
+ok( !$parser->class_name($_), "illegal class_name: $_" )
+ for (qw( foo fooBar Foo_Bar FOOBAR 1Foo 1FOO ));
+
+is( $parser->cnick(qq|cnick $_|), $_, "cnick: $_" ) for (qw( Foo FF ));
+
+ok( !$parser->cnick(qq|cnick $_|), "Illegal cnick: $_" )
+ for (qw( foo fOO 1Foo ));
+
Added: incubator/lucy/trunk/import/clownfish/t/cfsource/Animal.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/cfsource/Animal.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/cfsource/Animal.cfh (added)
+++ incubator/lucy/trunk/import/clownfish/t/cfsource/Animal.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,3 @@
+parcel Animal;
+
+abstract class Animal { }
Added: incubator/lucy/trunk/import/clownfish/t/cfsource/Animal/Dog.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/cfsource/Animal/Dog.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/cfsource/Animal/Dog.cfh (added)
+++ incubator/lucy/trunk/import/clownfish/t/cfsource/Animal/Dog.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,12 @@
+parcel Animal;
+
+class Animal::Dog inherits Animal {
+ public inert incremented Dog*
+ new();
+
+ public inert Dog*
+ init(Dog *self);
+
+ public void
+ Bark(Dog *self);
+}
Added: incubator/lucy/trunk/import/clownfish/t/cfsource/Animal/Util.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/clownfish/t/cfsource/Animal/Util.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/clownfish/t/cfsource/Animal/Util.cfh (added)
+++ incubator/lucy/trunk/import/clownfish/t/cfsource/Animal/Util.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,7 @@
+parcel Animal;
+
+inert class Animal::Util {
+ inert void
+ groom(Animal *animal);
+}
+
Added: incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.c (added)
+++ incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,72 @@
+#define C_KINO_FILTERSCORER
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KSx/Search/FilterScorer.h"
+
+FilterScorer*
+FilterScorer_new(BitVector *bits, int32_t doc_max)
+{
+ FilterScorer *self = (FilterScorer*)VTable_Make_Obj(FILTERSCORER);
+ return FilterScorer_init(self, bits, doc_max);
+}
+
+FilterScorer*
+FilterScorer_init(FilterScorer *self, BitVector *bits, int32_t doc_max)
+{
+ Matcher_init((Matcher*)self);
+
+ // Init.
+ self->doc_id = 0;
+
+ // Assign.
+ self->bits = (BitVector*)INCREF(bits);
+ self->doc_max = doc_max;
+
+ return self;
+}
+
+void
+FilterScorer_destroy(FilterScorer *self)
+{
+ DECREF(self->bits);
+ SUPER_DESTROY(self, FILTERSCORER);
+}
+
+int32_t
+FilterScorer_next(FilterScorer* self)
+{
+ do {
+ if (++self->doc_id > self->doc_max) {
+ self->doc_id--;
+ return 0;
+ }
+ } while ( !BitVec_Get(self->bits, self->doc_id) );
+ return self->doc_id;
+}
+
+int32_t
+FilterScorer_skip_to(FilterScorer* self, int32_t target)
+{
+ self->doc_id = target - 1;
+ return FilterScorer_next(self);
+}
+
+float
+FilterScorer_score(FilterScorer* self)
+{
+ UNUSED_VAR(self);
+ return 0.0f;
+}
+
+int32_t
+FilterScorer_get_doc_id(FilterScorer* self)
+{
+ return self->doc_id;
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.cfh (added)
+++ incubator/lucy/trunk/import/core/KSx/Search/FilterScorer.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,41 @@
+parcel KinoSearch cnick Kino;
+
+class KSx::Search::FilterScorer inherits KinoSearch::Search::Matcher {
+
+ BitVector *bits;
+ int32_t doc_max;
+ int32_t doc_id;
+
+ /**
+ * @param bits A BitVector with each doc id that should match set to
+ * true.
+ * @param doc_max The largest doc id that could possibly match.
+ */
+ inert incremented FilterScorer*
+ new(BitVector *bits, int32_t doc_max);
+
+ inert FilterScorer*
+ init(FilterScorer *self, BitVector *bits, int32_t doc_max);
+
+ public void
+ Destroy(FilterScorer *self);
+
+ public int32_t
+ Next(FilterScorer* self);
+
+ public int32_t
+ Skip_To(FilterScorer* self, int32_t target);
+
+ public float
+ Score(FilterScorer* self);
+
+ public int32_t
+ Get_Doc_ID(FilterScorer* self);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.c (added)
+++ incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,63 @@
+#define C_KINO_MOCKMATCHER
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KSx/Search/MockMatcher.h"
+
+MockMatcher*
+MockMatcher_new(I32Array *doc_ids, ByteBuf *scores)
+{
+ MockMatcher *self = (MockMatcher*)VTable_Make_Obj(MOCKMATCHER);
+ return MockMatcher_init(self, doc_ids, scores);
+}
+
+MockMatcher*
+MockMatcher_init(MockMatcher *self, I32Array *doc_ids, ByteBuf *scores)
+{
+ Matcher_init((Matcher*)self);
+ self->tick = -1;
+ self->size = I32Arr_Get_Size(doc_ids);
+ self->doc_ids = (I32Array*)INCREF(doc_ids);
+ self->scores = (ByteBuf*)INCREF(scores);
+ return self;
+}
+
+void
+MockMatcher_destroy(MockMatcher *self)
+{
+ DECREF(self->doc_ids);
+ DECREF(self->scores);
+ SUPER_DESTROY(self, MOCKMATCHER);
+}
+
+int32_t
+MockMatcher_next(MockMatcher* self)
+{
+ if (++self->tick >= (int32_t)self->size) {
+ self->tick--;
+ return 0;
+ }
+ return I32Arr_Get(self->doc_ids, self->tick);
+}
+
+float
+MockMatcher_score(MockMatcher* self)
+{
+ if (!self->scores) {
+ THROW(ERR, "Can't call Score() unless scores supplied");
+ }
+ float *raw_scores = (float*)BB_Get_Buf(self->scores);
+ return raw_scores[self->tick];
+}
+
+int32_t
+MockMatcher_get_doc_id(MockMatcher* self)
+{
+ return I32Arr_Get(self->doc_ids, self->tick);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.cfh (added)
+++ incubator/lucy/trunk/import/core/KSx/Search/MockMatcher.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,39 @@
+parcel KinoSearch cnick Kino;
+
+class KSx::Search::MockMatcher inherits KinoSearch::Search::Matcher {
+
+ size_t size;
+ I32Array *doc_ids;
+ ByteBuf *scores;
+ int32_t tick;
+
+ inert incremented MockMatcher*
+ new(I32Array *doc_ids, ByteBuf *scores = NULL);
+
+ /**
+ * @param doc_ids An array of matching doc ids.
+ * @param scores Float scores corresponding to the doc ids array. If not
+ * supplied, calling Score() will throw an exception.
+ */
+ inert incremented MockMatcher*
+ init(MockMatcher *self, I32Array *doc_ids, ByteBuf *scores = NULL);
+
+ public void
+ Destroy(MockMatcher *self);
+
+ public int32_t
+ Next(MockMatcher* self);
+
+ public float
+ Score(MockMatcher* self);
+
+ public int32_t
+ Get_Doc_ID(MockMatcher* self);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.c (added)
+++ incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,418 @@
+#define C_KINO_PROXIMITYQUERY
+#define C_KINO_PROXIMITYCOMPILER
+#include <stdarg.h>
+
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KSx/Search/ProximityQuery.h"
+#include "KinoSearch/Index/DocVector.h"
+#include "KinoSearch/Index/Posting.h"
+#include "KinoSearch/Index/Posting/ScorePosting.h"
+#include "KinoSearch/Index/PostingList.h"
+#include "KinoSearch/Index/PostingListReader.h"
+#include "KinoSearch/Index/SegPostingList.h"
+#include "KinoSearch/Index/SegReader.h"
+#include "KinoSearch/Index/Similarity.h"
+#include "KinoSearch/Index/TermVector.h"
+#include "KinoSearch/Plan/Schema.h"
+#include "KSx/Search/ProximityScorer.h"
+#include "KinoSearch/Search/Searcher.h"
+#include "KinoSearch/Search/Span.h"
+#include "KinoSearch/Search/TermQuery.h"
+#include "KinoSearch/Store/InStream.h"
+#include "KinoSearch/Store/OutStream.h"
+#include "KinoSearch/Util/Freezer.h"
+
+// Shared initialization routine which assumes that it's ok to assume control
+// over [field] and [terms], eating their refcounts.
+static ProximityQuery*
+S_do_init(ProximityQuery *self, CharBuf *field, VArray *terms, float boost,
+ uint32_t within);
+
+ProximityQuery*
+ProximityQuery_new(const CharBuf *field, VArray *terms, uint32_t within)
+{
+ ProximityQuery *self = (ProximityQuery*)VTable_Make_Obj(PROXIMITYQUERY);
+ return ProximityQuery_init(self, field, terms, within);
+}
+
+ProximityQuery*
+ProximityQuery_init(ProximityQuery *self, const CharBuf *field, VArray *terms,
+ uint32_t within)
+{
+ return S_do_init(self, CB_Clone(field), VA_Clone(terms), 1.0f, within);
+}
+
+void
+ProximityQuery_destroy(ProximityQuery *self)
+{
+ DECREF(self->terms);
+ DECREF(self->field);
+ SUPER_DESTROY(self, PROXIMITYQUERY);
+}
+
+static ProximityQuery*
+S_do_init(ProximityQuery *self, CharBuf *field, VArray *terms, float boost,
+ uint32_t within)
+{
+ uint32_t i, max;
+ Query_init((Query*)self, boost);
+ for (i = 0, max = VA_Get_Size(terms); i < max; i++) {
+ CERTIFY(VA_Fetch(terms, i), OBJ);
+ }
+ self->field = field;
+ self->terms = terms;
+ self->within = within;
+ return self;
+}
+
+void
+ProximityQuery_serialize(ProximityQuery *self, OutStream *outstream)
+{
+ OutStream_Write_F32(outstream, self->boost);
+ CB_Serialize(self->field, outstream);
+ VA_Serialize(self->terms, outstream);
+ OutStream_Write_C32(outstream, self->within);
+}
+
+ProximityQuery*
+ProximityQuery_deserialize(ProximityQuery *self, InStream *instream)
+{
+ float boost = InStream_Read_F32(instream);
+ CharBuf *field = CB_deserialize(NULL, instream);
+ VArray *terms = VA_deserialize(NULL, instream);
+ uint32_t within = InStream_Read_C32(instream);
+ self = self ? self : (ProximityQuery*)VTable_Make_Obj(PROXIMITYQUERY);
+ return S_do_init(self, field, terms, boost, within);
+}
+
+bool_t
+ProximityQuery_equals(ProximityQuery *self, Obj *other)
+{
+ ProximityQuery *evil_twin = (ProximityQuery*)other;
+ if (evil_twin == self) return true;
+ if (!Obj_Is_A(other, PROXIMITYQUERY)) return false;
+ if (self->boost != evil_twin->boost) return false;
+ if (self->field && !evil_twin->field) return false;
+ if (!self->field && evil_twin->field) return false;
+ if (self->field && !CB_Equals(self->field, (Obj*)evil_twin->field))
+ return false;
+ if (!VA_Equals(evil_twin->terms, (Obj*)self->terms)) return false;
+ if (self->within != evil_twin->within) return false;
+ return true;
+}
+
+CharBuf*
+ProximityQuery_to_string(ProximityQuery *self)
+{
+ uint32_t i;
+ uint32_t num_terms = VA_Get_Size(self->terms);
+ CharBuf *retval = CB_Clone(self->field);
+ CB_Cat_Trusted_Str(retval, ":\"", 2);
+ for (i = 0; i < num_terms; i++) {
+ Obj *term = VA_Fetch(self->terms, i);
+ CharBuf *term_string = Obj_To_String(term);
+ CB_Cat(retval, term_string);
+ DECREF(term_string);
+ if (i < num_terms - 1) {
+ CB_Cat_Trusted_Str(retval, " ", 1);
+ }
+ }
+ CB_Cat_Trusted_Str(retval, "\"", 1);
+ CB_catf(retval, "~%u32", self->within);
+ return retval;
+}
+
+Compiler*
+ProximityQuery_make_compiler(ProximityQuery *self, Searcher *searcher,
+ float boost)
+{
+ if (VA_Get_Size(self->terms) == 1) {
+ // Optimize for one-term "phrases".
+ Obj *term = VA_Fetch(self->terms, 0);
+ TermQuery *term_query = TermQuery_new(self->field, term);
+ TermCompiler *term_compiler;
+ TermQuery_Set_Boost(term_query, self->boost);
+ term_compiler = (TermCompiler*)TermQuery_Make_Compiler(term_query,
+ searcher, boost);
+ DECREF(term_query);
+ return (Compiler*)term_compiler;
+ }
+ else {
+ return (Compiler*)ProximityCompiler_new(self, searcher, boost, self->within);
+ }
+}
+
+CharBuf*
+ProximityQuery_get_field(ProximityQuery *self) { return self->field; }
+VArray*
+ProximityQuery_get_terms(ProximityQuery *self) { return self->terms; }
+uint32_t
+ProximityQuery_get_within(ProximityQuery *self) { return self->within; }
+
+/*********************************************************************/
+
+ProximityCompiler*
+ProximityCompiler_new(ProximityQuery *parent, Searcher *searcher, float boost,
+ uint32_t within)
+{
+ ProximityCompiler *self = (ProximityCompiler*)VTable_Make_Obj(PROXIMITYCOMPILER);
+ return ProximityCompiler_init(self, parent, searcher, boost, within);
+}
+
+ProximityCompiler*
+ProximityCompiler_init(ProximityCompiler *self, ProximityQuery *parent,
+ Searcher *searcher, float boost, uint32_t within)
+{
+ Schema *schema = Searcher_Get_Schema(searcher);
+ Similarity *sim = Schema_Fetch_Sim(schema, parent->field);
+ VArray *terms = parent->terms;
+ uint32_t i, max;
+
+ self->within = within;
+
+ // Try harder to find a Similarity if necessary.
+ if (!sim) { sim = Schema_Get_Similarity(schema); }
+
+ // Init.
+ Compiler_init((Compiler*)self, (Query*)parent, searcher, sim, boost);
+
+ // Store IDF for the phrase.
+ self->idf = 0;
+ for (i = 0, max = VA_Get_Size(terms); i < max; i++) {
+ Obj *term = VA_Fetch(terms, i);
+ int32_t doc_max = Searcher_Doc_Max(searcher);
+ int32_t doc_freq = Searcher_Doc_Freq(searcher, parent->field, term);
+ self->idf += Sim_IDF(sim, doc_freq, doc_max);
+ }
+
+ // Calculate raw weight.
+ self->raw_weight = self->idf * self->boost;
+
+ // Make final preparations.
+ ProximityCompiler_Normalize(self);
+
+ return self;
+}
+
+void
+ProximityCompiler_serialize(ProximityCompiler *self, OutStream *outstream)
+{
+ Compiler_serialize((Compiler*)self, outstream);
+ OutStream_Write_F32(outstream, self->idf);
+ OutStream_Write_F32(outstream, self->raw_weight);
+ OutStream_Write_F32(outstream, self->query_norm_factor);
+ OutStream_Write_F32(outstream, self->normalized_weight);
+ OutStream_Write_C32(outstream, self->within);
+}
+
+ProximityCompiler*
+ProximityCompiler_deserialize(ProximityCompiler *self, InStream *instream)
+{
+ self = self ? self : (ProximityCompiler*)VTable_Make_Obj(PROXIMITYCOMPILER);
+ Compiler_deserialize((Compiler*)self, instream);
+ self->idf = InStream_Read_F32(instream);
+ self->raw_weight = InStream_Read_F32(instream);
+ self->query_norm_factor = InStream_Read_F32(instream);
+ self->normalized_weight = InStream_Read_F32(instream);
+ self->within = InStream_Read_C32(instream);
+ return self;
+}
+
+bool_t
+ProximityCompiler_equals(ProximityCompiler *self, Obj *other)
+{
+ ProximityCompiler *evil_twin = (ProximityCompiler*)other;
+ if (!Obj_Is_A(other, PROXIMITYCOMPILER)) return false;
+ if (!Compiler_equals((Compiler*)self, other)) return false;
+ if (self->idf != evil_twin->idf) return false;
+ if (self->raw_weight != evil_twin->raw_weight) return false;
+ if (self->query_norm_factor != evil_twin->query_norm_factor) return false;
+ if (self->normalized_weight != evil_twin->normalized_weight) return false;
+ if (self->within != evil_twin->within) return false;
+ return true;
+}
+
+float
+ProximityCompiler_get_weight(ProximityCompiler *self)
+{
+ return self->normalized_weight;
+}
+
+float
+ProximityCompiler_sum_of_squared_weights(ProximityCompiler *self)
+{
+ return self->raw_weight * self->raw_weight;
+}
+
+void
+ProximityCompiler_apply_norm_factor(ProximityCompiler *self, float factor)
+{
+ self->query_norm_factor = factor;
+ self->normalized_weight = self->raw_weight * self->idf * factor;
+}
+
+Matcher*
+ProximityCompiler_make_matcher(ProximityCompiler *self, SegReader *reader,
+ bool_t need_score)
+{
+ UNUSED_VAR(need_score);
+ ProximityQuery *const parent = (ProximityQuery*)self->parent;
+ VArray *const terms = parent->terms;
+ uint32_t num_terms = VA_Get_Size(terms);
+
+ // Bail if there are no terms.
+ if (!num_terms) return NULL;
+
+ // Bail unless field is valid and posting type supports positions.
+ Similarity *sim = ProximityCompiler_Get_Similarity(self);
+ Posting *posting = Sim_Make_Posting(sim);
+ if (posting == NULL || !Obj_Is_A((Obj*)posting, SCOREPOSTING)) {
+ DECREF(posting);
+ return NULL;
+ }
+ DECREF(posting);
+
+ // Bail if there's no PostingListReader for this segment.
+ PostingListReader *const plist_reader = (PostingListReader*)SegReader_Fetch(
+ reader, VTable_Get_Name(POSTINGLISTREADER));
+ if (!plist_reader) { return NULL; }
+
+ // Look up each term.
+ VArray *plists = VA_new(num_terms);
+ for (uint32_t i = 0; i < num_terms; i++) {
+ Obj *term = VA_Fetch(terms, i);
+ PostingList *plist
+ = PListReader_Posting_List(plist_reader, parent->field, term);
+
+ // Bail if any one of the terms isn't in the index.
+ if (!plist || !PList_Get_Doc_Freq(plist)) {
+ DECREF(plist);
+ DECREF(plists);
+ return NULL;
+ }
+ VA_Push(plists, (Obj*)plist);
+ }
+
+ Matcher *retval
+ = (Matcher*)ProximityScorer_new(sim, plists, (Compiler*)self, self->within);
+ DECREF(plists);
+ return retval;
+}
+
+VArray*
+ProximityCompiler_highlight_spans(ProximityCompiler *self, Searcher *searcher,
+ DocVector *doc_vec, const CharBuf *field)
+{
+ ProximityQuery *const parent = (ProximityQuery*)self->parent;
+ VArray *const terms = parent->terms;
+ VArray *const spans = VA_new(0);
+ VArray *term_vectors;
+ BitVector *posit_vec;
+ BitVector *other_posit_vec;
+ uint32_t i;
+ const uint32_t num_terms = VA_Get_Size(terms);
+ uint32_t num_tvs;
+ UNUSED_VAR(searcher);
+
+ // Bail if no terms or field doesn't match.
+ if (!num_terms) { return spans; }
+ if (!CB_Equals(field, (Obj*)parent->field)) { return spans; }
+
+ term_vectors = VA_new(num_terms);
+ posit_vec = BitVec_new(0);
+ other_posit_vec = BitVec_new(0);
+ for (i = 0; i < num_terms; i++) {
+ Obj *term = VA_Fetch(terms, i);
+ TermVector *term_vector
+ = DocVec_Term_Vector(doc_vec, field, (CharBuf*)term);
+
+ // Bail if any term is missing.
+ if (!term_vector)
+ break;
+
+ VA_Push(term_vectors, (Obj*)term_vector);
+
+ if (i == 0) {
+ // Set initial positions from first term.
+ uint32_t j;
+ I32Array *positions = TV_Get_Positions(term_vector);
+ for (j = I32Arr_Get_Size(positions); j > 0; j--) {
+ BitVec_Set(posit_vec, I32Arr_Get(positions, j - 1));
+ }
+ }
+ else {
+ // Filter positions using logical "and".
+ uint32_t j;
+ I32Array *positions = TV_Get_Positions(term_vector);
+
+ BitVec_Clear_All(other_posit_vec);
+ for (j = I32Arr_Get_Size(positions); j > 0; j--) {
+ int32_t pos = I32Arr_Get(positions, j - 1) - i;
+ if (pos >= 0) {
+ BitVec_Set(other_posit_vec, pos);
+ }
+ }
+ BitVec_And(posit_vec, other_posit_vec);
+ }
+ }
+
+ // Proceed only if all terms are present.
+ num_tvs = VA_Get_Size(term_vectors);
+ if (num_tvs == num_terms) {
+ TermVector *first_tv = (TermVector*)VA_Fetch(term_vectors, 0);
+ TermVector *last_tv
+ = (TermVector*)VA_Fetch(term_vectors, num_tvs - 1);
+ I32Array *tv_start_positions = TV_Get_Positions(first_tv);
+ I32Array *tv_end_positions = TV_Get_Positions(last_tv);
+ I32Array *tv_start_offsets = TV_Get_Start_Offsets(first_tv);
+ I32Array *tv_end_offsets = TV_Get_End_Offsets(last_tv);
+ uint32_t terms_max = num_terms - 1;
+ I32Array *valid_posits = BitVec_To_Array(posit_vec);
+ uint32_t num_valid_posits = I32Arr_Get_Size(valid_posits);
+ uint32_t j = 0;
+ uint32_t posit_tick;
+ float weight = ProximityCompiler_Get_Weight(self);
+ i = 0;
+
+ // Add only those starts/ends that belong to a valid position.
+ for (posit_tick = 0; posit_tick < num_valid_posits; posit_tick++) {
+ int32_t valid_start_posit = I32Arr_Get(valid_posits, posit_tick);
+ int32_t valid_end_posit = valid_start_posit + terms_max;
+ int32_t start_offset = 0, end_offset = 0;
+ uint32_t max;
+
+ for (max = I32Arr_Get_Size(tv_start_positions); i < max; i++) {
+ if (I32Arr_Get(tv_start_positions, i) == valid_start_posit) {
+ start_offset = I32Arr_Get(tv_start_offsets, i);
+ break;
+ }
+ }
+ for (max = I32Arr_Get_Size(tv_end_positions); j < max; j++) {
+ if (I32Arr_Get(tv_end_positions, j) == valid_end_posit) {
+ end_offset = I32Arr_Get(tv_end_offsets, j);
+ break;
+ }
+ }
+
+ VA_Push(spans, (Obj*)Span_new(start_offset,
+ end_offset - start_offset, weight) );
+
+ i++, j++;
+ }
+
+ DECREF(valid_posits);
+ }
+
+ DECREF(other_posit_vec);
+ DECREF(posit_vec);
+ DECREF(term_vectors);
+ return spans;
+}
+
+/* Copyright 2006-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.cfh (added)
+++ incubator/lucy/trunk/import/core/KSx/Search/ProximityQuery.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,107 @@
+parcel KinoSearch cnick Kino;
+
+/** Query matching an ordered list of terms.
+ *
+ * ProximityQuery is a subclass of L<KinoSearch::Search::Query> for matching
+ * against an ordered sequence of terms.
+ */
+
+class KSx::Search::ProximityQuery inherits KinoSearch::Search::Query
+ : dumpable {
+
+ CharBuf *field;
+ VArray *terms;
+ uint32_t within;
+
+ inert incremented ProximityQuery*
+ new(const CharBuf *field, VArray *terms, uint32_t within);
+
+ /**
+ * @param field The field that the phrase must occur in.
+ * @param terms The ordered array of terms that must match.
+ */
+ public inert ProximityQuery*
+ init(ProximityQuery *self, const CharBuf *field, VArray *terms, uint32_t within);
+
+ /** Accessor for object's field attribute.
+ */
+ public CharBuf*
+ Get_Field(ProximityQuery *self);
+
+ /** Accessor for object's array of terms.
+ */
+ public VArray*
+ Get_Terms(ProximityQuery *self);
+
+ /** Accessor for object's within attribute.
+ */
+ public uint32_t
+ Get_Within(ProximityQuery *self);
+
+ public incremented Compiler*
+ Make_Compiler(ProximityQuery *self, Searcher *searcher, float boost);
+
+ public bool_t
+ Equals(ProximityQuery *self, Obj *other);
+
+ public incremented CharBuf*
+ To_String(ProximityQuery *self);
+
+ public void
+ Serialize(ProximityQuery *self, OutStream *outstream);
+
+ public incremented ProximityQuery*
+ Deserialize(ProximityQuery *self, InStream *instream);
+
+ public void
+ Destroy(ProximityQuery *self);
+}
+
+class KSx::Search::ProximityCompiler
+ inherits KinoSearch::Search::Compiler {
+
+ float idf;
+ float raw_weight;
+ float query_norm_factor;
+ float normalized_weight;
+ uint32_t within;
+
+ inert incremented ProximityCompiler*
+ new(ProximityQuery *parent, Searcher *searcher, float boost, uint32_t within);
+
+ inert ProximityCompiler*
+ init(ProximityCompiler *self, ProximityQuery *parent, Searcher *searcher,
+ float boost, uint32_t within);
+
+ public incremented nullable Matcher*
+ Make_Matcher(ProximityCompiler *self, SegReader *reader, bool_t need_score);
+
+ public float
+ Get_Weight(ProximityCompiler *self);
+
+ public float
+ Sum_Of_Squared_Weights(ProximityCompiler *self);
+
+ public void
+ Apply_Norm_Factor(ProximityCompiler *self, float factor);
+
+ public incremented VArray*
+ Highlight_Spans(ProximityCompiler *self, Searcher *searcher,
+ DocVector *doc_vec, const CharBuf *field);
+
+ public bool_t
+ Equals(ProximityCompiler *self, Obj *other);
+
+ public void
+ Serialize(ProximityCompiler *self, OutStream *outstream);
+
+ public incremented ProximityCompiler*
+ Deserialize(ProximityCompiler *self, InStream *instream);
+}
+
+/* Copyright 2006-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+