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 19// FIXME add tests for MRU 20 21func TestRegistry(t *testing.T) { 22 p := &builderNodePool{} 23 r := newRegistry(p, 10, 1) 24 25 n1 := &builderNode{ 26 trans: []transition{ 27 { 28 in: 'a', 29 addr: 1, 30 }, 31 { 32 in: 'b', 33 addr: 2, 34 }, 35 { 36 in: 'c', 37 addr: 3, 38 }, 39 }, 40 } 41 42 // first look, doesn't exist 43 found, _, cell := r.entry(n1) 44 if found { 45 t.Errorf("expected empty registry to not have equivalent") 46 } 47 48 cell.addr = 276 49 50 // second look, does 51 var nowAddr int 52 found, nowAddr, _ = r.entry(n1) 53 if !found { 54 t.Errorf("expected to find equivalent after registering it") 55 } 56 if nowAddr != 276 { 57 t.Errorf("expected to get addr 276, got %d", nowAddr) 58 } 59} 60