Add more tests for Perl bindings
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/b99a5ecb Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/b99a5ecb Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/b99a5ecb Branch: refs/heads/master Commit: b99a5ecb41b285f2daed4c043567ca8e0abe5012 Parents: 693cff8 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Sun Nov 15 15:01:08 2015 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Tue Nov 17 19:08:43 2015 +0100 ---------------------------------------------------------------------- runtime/perl/t/binding/017-hash.t | 12 ++++- runtime/perl/t/binding/021-blob.t | 37 +++++++++++++++ runtime/perl/t/binding/022-bytebuf.t | 45 ++++++++++++++++++ runtime/perl/t/binding/023-string.t | 78 +++++++++++++++++++++++++++++++ runtime/perl/t/binding/029-charbuf.t | 53 ++++----------------- runtime/perl/t/binding/031-num.t | 68 +++++++++++++++++++++++++++ 6 files changed, 248 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b99a5ecb/runtime/perl/t/binding/017-hash.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/017-hash.t b/runtime/perl/t/binding/017-hash.t index 5a3c07c..9b26829 100644 --- a/runtime/perl/t/binding/017-hash.t +++ b/runtime/perl/t/binding/017-hash.t @@ -16,13 +16,22 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 10; use Clownfish qw( to_clownfish ); my $hash = Clownfish::Hash->new( capacity => 10 ); $hash->store( "foo", Clownfish::String->new("bar") ); $hash->store( "baz", Clownfish::String->new("banana") ); +my $iter = Clownfish::HashIterator->new($hash); +isa_ok( $iter, 'Clownfish::HashIterator' ); +for (my $i = 0; $i < 2; $i++) { + ok( $iter->next, "iter next $i" ); + my $key = $iter->get_key; + is( $iter->get_value, $hash->fetch($key), "iter get $i" ); +} +ok( !$iter->next, 'iter next final'); + ok( !defined( $hash->fetch("blah") ), "fetch for a non-existent key returns undef" ); @@ -35,3 +44,4 @@ my %hash_with_utf8_keys = ( "\x{263a}" => "foo" ); my $round_tripped = to_clownfish( \%hash_with_utf8_keys )->to_perl; is_deeply( $round_tripped, \%hash_with_utf8_keys, "Round trip conversion of hash with UTF-8 keys" ); + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b99a5ecb/runtime/perl/t/binding/021-blob.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/021-blob.t b/runtime/perl/t/binding/021-blob.t new file mode 100644 index 0000000..bcdcc18 --- /dev/null +++ b/runtime/perl/t/binding/021-blob.t @@ -0,0 +1,37 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use strict; +use warnings; +use lib 'buildlib'; + +use Test::More tests => 8; +use Clownfish; + +my $blob = Clownfish::Blob->new('abc'); +isa_ok( $blob, 'Clownfish::Blob' ); + +is( $blob->to_perl, 'abc', 'to_perl' ); +is( $blob->get_size, 3, 'get_size' ); + +my $other = Clownfish::Blob->new('abcd'); +ok( $blob->equals($blob), 'equals true'); +ok( !$blob->equals($other), 'equals false'); +ok( $blob->compare_to($other) < 0, 'compare_to'); + +$blob = $other->clone; +isa_ok( $blob, 'Clownfish::Blob', 'clone' ); +ok( $blob->equals($other), 'equals after clone' ); + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b99a5ecb/runtime/perl/t/binding/022-bytebuf.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/022-bytebuf.t b/runtime/perl/t/binding/022-bytebuf.t new file mode 100644 index 0000000..d7e4d96 --- /dev/null +++ b/runtime/perl/t/binding/022-bytebuf.t @@ -0,0 +1,45 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use strict; +use warnings; +use lib 'buildlib'; + +use Test::More tests => 11; +use Clownfish; + +my $buf = Clownfish::ByteBuf->new('abc'); +isa_ok( $buf, 'Clownfish::ByteBuf' ); + +is( $buf->to_perl, 'abc', 'to_perl' ); +is( $buf->get_size, 3, 'get_size' ); + +$buf->set_size(2); +is( $buf->to_perl, 'ab', 'set_size' ); +$buf->cat(Clownfish::Blob->new('c')); +is( $buf->to_perl, 'abc', 'cat' ); + +my $other = Clownfish::ByteBuf->new('abcd'); +ok( $buf->equals($buf), 'equals true'); +ok( !$buf->equals($other), 'equals false'); +ok( $buf->compare_to($other) < 0, 'compare_to'); + +$buf->mimic($other); +ok( $buf->equals($other), 'mimic' ); + +$buf = $other->clone; +isa_ok( $buf, 'Clownfish::ByteBuf', 'clone' ); +ok( $buf->equals($other), 'equals after clone' ); + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b99a5ecb/runtime/perl/t/binding/023-string.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/023-string.t b/runtime/perl/t/binding/023-string.t new file mode 100644 index 0000000..6ae2535 --- /dev/null +++ b/runtime/perl/t/binding/023-string.t @@ -0,0 +1,78 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use strict; +use warnings; +use lib 'buildlib'; + +use Test::More tests => 6; +use Encode qw( _utf8_off ); +use Clownfish; + +# Return 3 strings useful for verifying UTF-8 integrity. +sub utf8_test_strings { + my $smiley = "\x{263a}"; + my $not_a_smiley = $smiley; + _utf8_off($not_a_smiley); + my $frowny = $not_a_smiley; + utf8::upgrade($frowny); + return ( $smiley, $not_a_smiley, $frowny ); +} + +my ( $smiley, $not_a_smiley, $frowny ) = utf8_test_strings(); + +my $string = Clownfish::String->new($smiley); +isa_ok( $string, "Clownfish::String" ); +is( $string->to_perl, $smiley, "round trip UTF-8" ); + +$string = Clownfish::String->new($smiley); +my $clone = $string->clone; +is( $clone->to_perl, Clownfish::String->new($smiley)->to_perl, "clone" ); + +my $wanted = "abc\x00de"; +$string = Clownfish::String->new($wanted); +my $iter = $string->top; +isa_ok( $iter, "Clownfish::StringIterator" ); +my $buf = ''; +while (my $cp = $iter->next) { + $buf .= chr($cp); +} +is( $buf, $wanted, 'iter next' ); + +{ + package MyStringCallbackTest; + use base qw(Clownfish::Test::StringCallbackTest); + + our $string_ref; + + sub new { + $string_ref = \$_[1]; + return $_[0]->SUPER::new; + } + + sub callback { + my $self = shift; + $$string_ref = 'bar'; + } +} + +SKIP: { + skip( "Known issue CLOWNFISH-44", 1 ); + my $string = 'foo'; + my $callback_test = MyStringCallbackTest->new($string); + ok( $callback_test->unchanged_by_callback($string), + "String unchanged by callback" ); +} + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b99a5ecb/runtime/perl/t/binding/029-charbuf.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/029-charbuf.t b/runtime/perl/t/binding/029-charbuf.t index a8b790b..1509e81 100644 --- a/runtime/perl/t/binding/029-charbuf.t +++ b/runtime/perl/t/binding/029-charbuf.t @@ -18,51 +18,16 @@ use warnings; use lib 'buildlib'; use Test::More tests => 4; -use Encode qw( _utf8_off ); use Clownfish; -# Return 3 strings useful for verifying UTF-8 integrity. -sub utf8_test_strings { - my $smiley = "\x{263a}"; - my $not_a_smiley = $smiley; - _utf8_off($not_a_smiley); - my $frowny = $not_a_smiley; - utf8::upgrade($frowny); - return ( $smiley, $not_a_smiley, $frowny ); -} +my $buf = Clownfish::CharBuf->new; +isa_ok( $buf, 'Clownfish::CharBuf' ); -my ( $smiley, $not_a_smiley, $frowny ) = utf8_test_strings(); - -my $string = Clownfish::String->new($smiley); -isa_ok( $string, "Clownfish::String" ); -is( $string->to_perl, $smiley, "round trip UTF-8" ); - -$string = Clownfish::String->new($smiley); -my $clone = $string->clone; -is( $clone->to_perl, Clownfish::String->new($smiley)->to_perl, "clone" ); - -{ - package MyStringCallbackTest; - use base qw(Clownfish::Test::StringCallbackTest); - - our $string_ref; - - sub new { - $string_ref = \$_[1]; - return $_[0]->SUPER::new; - } - - sub callback { - my $self = shift; - $$string_ref = 'bar'; - } -} - -SKIP: { - skip( "Known issue CLOWNFISH-44", 1 ); - my $string = 'foo'; - my $callback_test = MyStringCallbackTest->new($string); - ok( $callback_test->unchanged_by_callback($string), - "String unchanged by callback" ); -} +$buf->cat('xyz'); +$buf->clear; +$buf->cat('abc'); +$buf->cat_char(ord('d')); +is ( $buf->to_string, 'abcd', 'to_string' ); +is ( $buf->get_size, 4, 'get_size' ); +is ( $buf->yield_string, 'abcd', 'yield_string' ); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b99a5ecb/runtime/perl/t/binding/031-num.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/031-num.t b/runtime/perl/t/binding/031-num.t new file mode 100644 index 0000000..9112612 --- /dev/null +++ b/runtime/perl/t/binding/031-num.t @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use strict; +use warnings; +use lib 'buildlib'; + +use Test::More tests => 28; +use Clownfish; +use Clownfish::Boolean qw( $true_singleton $false_singleton ); + +my $float = Clownfish::Float->new(0.5); +my $neg_float = Clownfish::Float->new(-0.5); +isa_ok( $float, 'Clownfish::Float' ); + +is ( $float->get_value, 0.5, 'Float get_value' ); +is ( $float->to_i64, 0, 'Float to_i64' ); +ok ( $float->to_bool, 'Float to_bool' ); +is ( $float->to_string, '0.5', 'Float to_string' ); +ok ( $float->equals($float), 'Float equals true' ); +ok ( !$float->equals($neg_float), 'Float equals false' ); +ok ( $float->compare_to($neg_float) > 0, 'Float compare_to' ); + +my $float_clone = $float->clone; +isa_ok( $float_clone, 'Clownfish::Float', 'Float clone' ); +ok ( $float->equals($float_clone), 'Float clone is equal' ); + +my $int = Clownfish::Integer->new(12345); +my $neg_int = Clownfish::Integer->new(-12345); +isa_ok( $int, 'Clownfish::Integer' ); + +is ( $int->get_value, 12345, 'Integer get_value' ); +ok ( $int->to_bool, 'Integer to_bool' ); +is ( $int->to_string, '12345', 'Integer to_string' ); +ok ( $int->equals($int), 'Integer equals true' ); +ok ( !$int->equals($neg_int), 'Integer equals false' ); +ok ( $int->compare_to($neg_int) > 0, 'Integer compare_to' ); + +my $int_clone = $int->clone; +isa_ok( $int_clone, 'Clownfish::Integer', 'Integer clone' ); +ok ( $int->equals($int_clone), 'Integer clone is equal' ); + +my $bool = Clownfish::Boolean->singleton(1); +isa_ok( $bool, 'Clownfish::Boolean' ); + +ok ( $bool->get_value, 'Boolean get_value true' ); +ok ( !$false_singleton->get_value, 'Boolean get_value false' ); +is ( $bool->to_i64, 1, 'Boolean to_i64' ); +is ( $bool->to_string, 'true', 'Boolean to_string' ); +ok ( $bool->equals($true_singleton), 'Boolean equals true' ); +ok ( !$bool->equals($false_singleton), 'Boolean equals false' ); + +my $bool_clone = $bool->clone; +isa_ok( $bool_clone, 'Clownfish::Boolean', 'Boolean clone' ); +ok ( $bool->equals($bool_clone), 'Boolean clone is equal' ); +