1// Copyright 2014 Google Inc. All rights reserved. 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 blueprint 16 17import ( 18 "reflect" 19 "testing" 20) 21 22func mods(mods []string) []*moduleGroup { 23 ret := []*moduleGroup{} 24 25 for _, v := range mods { 26 m := moduleGroup{name: v} 27 ret = append(ret, &m) 28 } 29 30 return ret 31} 32 33func assertEqual(t *testing.T, a, b []string) { 34 if len(a) == 0 && len(b) == 0 { 35 return 36 } 37 38 if !reflect.DeepEqual(a, b) { 39 t.Errorf("Expected the following to be equal:\n\t%q\n\t%q", a, b) 40 } 41} 42 43func TestLevenshteinWontGuessUnlike(t *testing.T) { 44 assertEqual(t, namesLike("a", "test", mods([]string{"test"})), []string{}) 45} 46func TestLevenshteinInsert(t *testing.T) { 47 assertEqual(t, namesLike("a", "test", mods([]string{"ab", "ac", "not_this"})), []string{"ab", "ac"}) 48} 49func TestLevenshteinDelete(t *testing.T) { 50 assertEqual(t, namesLike("ab", "test", mods([]string{"a", "b", "not_this"})), []string{"a", "b"}) 51} 52func TestLevenshteinReplace(t *testing.T) { 53 assertEqual(t, namesLike("aa", "test", mods([]string{"ab", "ac", "not_this"})), []string{"ab", "ac"}) 54} 55