You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2015/08/14 20:06:19 UTC
[12/14] lucy-clownfish git commit: Tests for ByteBuf Go bindings.
Tests for ByteBuf Go 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/b42dfa9c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/b42dfa9c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/b42dfa9c
Branch: refs/heads/master
Commit: b42dfa9ca9f69575836c208b3d02e903eca85994
Parents: 3e4631b
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Aug 8 19:19:41 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Aug 10 15:11:57 2015 -0700
----------------------------------------------------------------------
runtime/go/clownfish/bytebuf_test.go | 107 ++++++++++++++++++++++++++++++
1 file changed, 107 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b42dfa9c/runtime/go/clownfish/bytebuf_test.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/bytebuf_test.go b/runtime/go/clownfish/bytebuf_test.go
new file mode 100644
index 0000000..0854f8d
--- /dev/null
+++ b/runtime/go/clownfish/bytebuf_test.go
@@ -0,0 +1,107 @@
+/* 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.
+ */
+
+package clownfish
+
+import "testing"
+import "reflect"
+
+func TestByteBufCat(t *testing.T) {
+ bb := NewByteBuf(0)
+ content := []byte("foo")
+ bb.Cat(content)
+ if got := bb.YieldBlob(); !reflect.DeepEqual(got, content) {
+ t.Errorf("Expected %v, got %v", content, got)
+ }
+}
+
+func TestByteBufSetSizeGetSize(t *testing.T) {
+ bb := NewByteBuf(0)
+ content := []byte("abc")
+ bb.Cat(content)
+ bb.SetSize(2)
+ if got := bb.GetSize(); got != 2 {
+ t.Errorf("Expected size 2, got %d", got)
+ }
+ expected := []byte("ab")
+ if got := bb.YieldBlob(); !reflect.DeepEqual(got, expected) {
+ t.Errorf("Expected %v, got %v", expected, got)
+ }
+}
+
+func TestByteBufGetCapacity(t *testing.T) {
+ bb := NewByteBuf(5)
+ if cap := bb.GetCapacity(); cap < 5 {
+ t.Errorf("Expected at least 5, got %d", cap)
+ }
+}
+
+func TestByteBufMimic(t *testing.T) {
+ bb := NewByteBuf(0)
+ content := []byte("foo")
+ bb.Cat(content)
+ other := NewByteBuf(0)
+ other.Mimic(bb)
+ if got := other.YieldBlob(); !reflect.DeepEqual(got, content) {
+ t.Errorf("Expected %v, got %v", content, got)
+ }
+}
+
+func TestByteBufEquals(t *testing.T) {
+ bb := NewByteBuf(0)
+ other := NewByteBuf(0)
+ content := []byte("foo")
+ bb.Cat(content)
+ other.Cat(content)
+ if !bb.Equals(other) {
+ t.Errorf("Equals against equal ByteBuf")
+ }
+ other.SetSize(2)
+ if bb.Equals(other) {
+ t.Errorf("Equals against non-equal ByteBuf")
+ }
+ if bb.Equals(42) {
+ t.Errorf("Equals against arbitrary Go type")
+ }
+}
+
+func TestByteBufClone(t *testing.T) {
+ content := []byte("foo")
+ bb := NewByteBuf(0)
+ bb.Cat(content)
+ clone := bb.Clone().(ByteBuf)
+ if got := clone.YieldBlob(); !reflect.DeepEqual(got, content) {
+ t.Errorf("Expected %v, got %v", content, got)
+ }
+}
+
+func TestByteBufCompareTo(t *testing.T) {
+ bb := NewByteBuf(0)
+ other := NewByteBuf(0)
+ content := []byte("foo")
+ bb.Cat(content)
+ other.Cat(content)
+ if got := bb.CompareTo(other); got != 0 {
+ t.Errorf("CompareTo equal, got %d", got)
+ }
+ other.SetSize(2)
+ if got := bb.CompareTo(other); got <= 0 {
+ t.Errorf("CompareTo lesser, got %d", got)
+ }
+ if got := other.CompareTo(bb); got >= 0 {
+ t.Errorf("CompareTo greater, got %d", got)
+ }
+}