integration_test.go (2537B)
1 // Copyright 2022 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_test
15
16 import (
17 "testing"
18
19 "github.com/gohugoio/hugo/hugolib"
20 )
21
22 // Issue 9585
23 func TestApplyWithContext(t *testing.T) {
24 t.Parallel()
25
26 files := `
27 -- config.toml --
28 baseURL = 'http://example.com/'
29 -- layouts/index.html --
30 {{ apply (seq 3) "partial" "foo.html"}}
31 -- layouts/partials/foo.html --
32 {{ return "foo"}}
33 `
34
35 b := hugolib.NewIntegrationTestBuilder(
36 hugolib.IntegrationTestConfig{
37 T: t,
38 TxtarString: files,
39 },
40 ).Build()
41
42 b.AssertFileContent("public/index.html", `
43 [foo foo foo]
44 `)
45 }
46
47 // Issue 9865
48 func TestSortStable(t *testing.T) {
49 t.Parallel()
50
51 files := `
52 -- config.toml --
53 -- layouts/index.html --
54 {{ $values := slice (dict "a" 1 "b" 2) (dict "a" 3 "b" 1) (dict "a" 2 "b" 0) (dict "a" 1 "b" 0) (dict "a" 3 "b" 1) (dict "a" 2 "b" 2) (dict "a" 2 "b" 1) (dict "a" 0 "b" 3) (dict "a" 3 "b" 3) (dict "a" 0 "b" 0) (dict "a" 0 "b" 0) (dict "a" 2 "b" 0) (dict "a" 1 "b" 2) (dict "a" 1 "b" 1) (dict "a" 3 "b" 0) (dict "a" 2 "b" 0) (dict "a" 3 "b" 0) (dict "a" 3 "b" 0) (dict "a" 3 "b" 0) (dict "a" 3 "b" 1) }}
55 Asc: {{ sort (sort $values "b" "asc") "a" "asc" }}
56 Desc: {{ sort (sort $values "b" "desc") "a" "desc" }}
57
58 `
59
60 for i := 0; i < 4; i++ {
61
62 b := hugolib.NewIntegrationTestBuilder(
63 hugolib.IntegrationTestConfig{
64 T: t,
65 TxtarString: files,
66 },
67 ).Build()
68
69 b.AssertFileContent("public/index.html", `
70 Asc: [map[a:0 b:0] map[a:0 b:0] map[a:0 b:3] map[a:1 b:0] map[a:1 b:1] map[a:1 b:2] map[a:1 b:2] map[a:2 b:0] map[a:2 b:0] map[a:2 b:0] map[a:2 b:1] map[a:2 b:2] map[a:3 b:0] map[a:3 b:0] map[a:3 b:0] map[a:3 b:0] map[a:3 b:1] map[a:3 b:1] map[a:3 b:1] map[a:3 b:3]]
71 Desc: [map[a:3 b:3] map[a:3 b:1] map[a:3 b:1] map[a:3 b:1] map[a:3 b:0] map[a:3 b:0] map[a:3 b:0] map[a:3 b:0] map[a:2 b:2] map[a:2 b:1] map[a:2 b:0] map[a:2 b:0] map[a:2 b:0] map[a:1 b:2] map[a:1 b:2] map[a:1 b:1] map[a:1 b:0] map[a:0 b:3] map[a:0 b:0] map[a:0 b:0]]
72 `)
73
74 }
75 }