github.com/graemephi/kahugo@v0.62.3-0.20211121071557-d78c0423784d/tpl/collections/append_test.go (about) 1 // Copyright 2018 The Hugo Authors. 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 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package collections 15 16 import ( 17 "reflect" 18 "testing" 19 20 qt "github.com/frankban/quicktest" 21 "github.com/gohugoio/hugo/deps" 22 ) 23 24 // Also see tests in common/collection. 25 func TestAppend(t *testing.T) { 26 t.Parallel() 27 c := qt.New(t) 28 29 ns := New(&deps.Deps{}) 30 31 for i, test := range []struct { 32 start interface{} 33 addend []interface{} 34 expected interface{} 35 }{ 36 {[]string{"a", "b"}, []interface{}{"c"}, []string{"a", "b", "c"}}, 37 {[]string{"a", "b"}, []interface{}{"c", "d", "e"}, []string{"a", "b", "c", "d", "e"}}, 38 {[]string{"a", "b"}, []interface{}{[]string{"c", "d", "e"}}, []string{"a", "b", "c", "d", "e"}}, 39 // Errors 40 {"", []interface{}{[]string{"a", "b"}}, false}, 41 {[]string{"a", "b"}, []interface{}{}, false}, 42 // No string concatenation. 43 { 44 "ab", 45 []interface{}{"c"}, 46 false, 47 }, 48 } { 49 50 errMsg := qt.Commentf("[%d]", i) 51 52 args := append(test.addend, test.start) 53 54 result, err := ns.Append(args...) 55 56 if b, ok := test.expected.(bool); ok && !b { 57 c.Assert(err, qt.Not(qt.IsNil), errMsg) 58 continue 59 } 60 61 c.Assert(err, qt.IsNil, errMsg) 62 63 if !reflect.DeepEqual(test.expected, result) { 64 t.Fatalf("%s got\n%T: %v\nexpected\n%T: %v", errMsg, result, result, test.expected, test.expected) 65 } 66 } 67 }