"Fossies" - the Fresh Open Source Software Archive

Member "hugo-0.113.0/tpl/collections/append_test.go" (5 Jun 2023, 1727 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. See also the last Fossies "Diffs" side-by-side code changes report for "append_test.go": 0.111.3_vs_0.112.0.

    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 )
   22 
   23 // Also see tests in common/collection.
   24 func TestAppend(t *testing.T) {
   25     t.Parallel()
   26     c := qt.New(t)
   27     ns := newNs()
   28 
   29     for i, test := range []struct {
   30         start    any
   31         addend   []any
   32         expected any
   33     }{
   34         {[]string{"a", "b"}, []any{"c"}, []string{"a", "b", "c"}},
   35         {[]string{"a", "b"}, []any{"c", "d", "e"}, []string{"a", "b", "c", "d", "e"}},
   36         {[]string{"a", "b"}, []any{[]string{"c", "d", "e"}}, []string{"a", "b", "c", "d", "e"}},
   37         // Errors
   38         {"", []any{[]string{"a", "b"}}, false},
   39         {[]string{"a", "b"}, []any{}, false},
   40         // No string concatenation.
   41         {
   42             "ab",
   43             []any{"c"},
   44             false,
   45         },
   46     } {
   47 
   48         errMsg := qt.Commentf("[%d]", i)
   49 
   50         args := append(test.addend, test.start)
   51 
   52         result, err := ns.Append(args...)
   53 
   54         if b, ok := test.expected.(bool); ok && !b {
   55             c.Assert(err, qt.Not(qt.IsNil), errMsg)
   56             continue
   57         }
   58 
   59         c.Assert(err, qt.IsNil, errMsg)
   60 
   61         if !reflect.DeepEqual(test.expected, result) {
   62             t.Fatalf("%s got\n%T: %v\nexpected\n%T: %v", errMsg, result, result, test.expected, test.expected)
   63         }
   64     }
   65 }