1// Copyright 2015 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 kati 16 17import ( 18 "reflect" 19 "testing" 20) 21 22func TestWordBuffer(t *testing.T) { 23 for _, tc := range []struct { 24 in []string 25 want []string 26 }{ 27 { 28 in: []string{"foo"}, 29 want: []string{"foo"}, 30 }, 31 { 32 in: []string{"foo bar"}, 33 want: []string{"foo", "bar"}, 34 }, 35 { 36 in: []string{" foo bar\tbaz "}, 37 want: []string{"foo", "bar", "baz"}, 38 }, 39 { 40 in: []string{"foo", "bar"}, 41 want: []string{"foobar"}, 42 }, 43 { 44 in: []string{"foo ", "bar"}, 45 want: []string{"foo", "bar"}, 46 }, 47 { 48 in: []string{"foo", " bar"}, 49 want: []string{"foo", "bar"}, 50 }, 51 { 52 in: []string{"foo ", " bar"}, 53 want: []string{"foo", "bar"}, 54 }, 55 } { 56 var wb wordBuffer 57 for _, s := range tc.in { 58 wb.Write([]byte(s)) 59 } 60 61 var got []string 62 for _, word := range wb.words { 63 got = append(got, string(word)) 64 } 65 if !reflect.DeepEqual(got, tc.want) { 66 t.Errorf("%q => %q; want %q", tc.in, got, tc.want) 67 } 68 } 69} 70