"Fossies" - the Fresh Open Source Software Archive 
Member "hugo-0.113.0/common/collections/append_test.go" (5 Jun 2023, 2487 Bytes) of package /linux/www/hugo-0.113.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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 "html/template"
18 "testing"
19
20 qt "github.com/frankban/quicktest"
21 )
22
23 func TestAppend(t *testing.T) {
24 t.Parallel()
25 c := qt.New(t)
26
27 for _, test := range []struct {
28 start any
29 addend []any
30 expected any
31 }{
32 {[]string{"a", "b"}, []any{"c"}, []string{"a", "b", "c"}},
33 {[]string{"a", "b"}, []any{"c", "d", "e"}, []string{"a", "b", "c", "d", "e"}},
34 {[]string{"a", "b"}, []any{[]string{"c", "d", "e"}}, []string{"a", "b", "c", "d", "e"}},
35 {[]string{"a"}, []any{"b", template.HTML("c")}, []any{"a", "b", template.HTML("c")}},
36 {nil, []any{"a", "b"}, []string{"a", "b"}},
37 {nil, []any{nil}, []any{nil}},
38 {[]any{}, []any{[]string{"c", "d", "e"}}, []string{"c", "d", "e"}},
39 {
40 tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}},
41 []any{&tstSlicer{"c"}},
42 tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}, &tstSlicer{"c"}},
43 },
44 {
45 &tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}},
46 []any{&tstSlicer{"c"}},
47 tstSlicers{
48 &tstSlicer{"a"},
49 &tstSlicer{"b"},
50 &tstSlicer{"c"},
51 },
52 },
53 {
54 testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}},
55 []any{&tstSlicerIn1{"c"}},
56 testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}, &tstSlicerIn1{"c"}},
57 },
58 //https://github.com/gohugoio/hugo/issues/5361
59 {
60 []string{"a", "b"},
61 []any{tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}},
62 []any{"a", "b", &tstSlicer{"a"}, &tstSlicer{"b"}},
63 },
64 {
65 []string{"a", "b"},
66 []any{&tstSlicer{"a"}},
67 []any{"a", "b", &tstSlicer{"a"}},
68 },
69 // Errors
70 {"", []any{[]string{"a", "b"}}, false},
71 // No string concatenation.
72 {
73 "ab",
74 []any{"c"},
75 false,
76 },
77 } {
78
79 result, err := Append(test.start, test.addend...)
80
81 if b, ok := test.expected.(bool); ok && !b {
82
83 c.Assert(err, qt.Not(qt.IsNil))
84 continue
85 }
86
87 c.Assert(err, qt.IsNil)
88 c.Assert(result, qt.DeepEquals, test.expected)
89 }
90 }