1// Copyright (c) 2017 Couchbase, Inc. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package vellum 16 17import "testing" 18 19func TestCommonInputs(t *testing.T) { 20 21 // first ensure items that can be encoded round trip properly 22 for i := 0; i < 256; i++ { 23 roundTrip(t, byte(i)) 24 } 25 26 // G maps to 62, +1 is 63, which is highest 6-bit value we can encode 27 enc := encodeCommon('G') 28 if enc != 63 { 29 t.Errorf("expected G to encode to 63, got %d", enc) 30 } 31 32 // W encodes to 63, +1 is 64, which is too big to fit 33 enc = encodeCommon('W') 34 if enc != 0 { 35 t.Errorf("expected W to encode to 0, got %d", enc) 36 } 37} 38 39func roundTrip(t *testing.T, b byte) { 40 enc := encodeCommon(b) 41 if enc > 0 { 42 dec := decodeCommon(enc) 43 if dec != b { 44 t.Errorf("error round trip common input: %d", b) 45 } 46 } 47} 48