(t *testing.T)
| 120 | } |
| 121 | |
| 122 | func TestBasicPostprocess(t *testing.T) { |
| 123 | funcs := htmltmpl.FuncMap{ |
| 124 | "golive_postprocess_context_var": func() string { return "$ppctx" }, |
| 125 | "golive_postprocess_start": func() []string { return []string{"pp", "qq"} }, |
| 126 | "golive_postprocess_end": func() []string { return []string{"xpp"} }, |
| 127 | "pp": func() string { |
| 128 | return "[" |
| 129 | }, |
| 130 | "qq": func() string { |
| 131 | return "(" |
| 132 | }, |
| 133 | "xpp": func(x ...any) string { |
| 134 | if len(x) == 0 { |
| 135 | return "]" |
| 136 | } |
| 137 | if x[0] != "!" { |
| 138 | t.Fatalf("$ppctx not set correctly, got %v (%T)", x[0], x[0]) |
| 139 | } |
| 140 | return x[1].(string) + "]" |
| 141 | }, |
| 142 | } |
| 143 | |
| 144 | tests := []struct { |
| 145 | tmpl string |
| 146 | want string |
| 147 | plain string |
| 148 | }{ |
| 149 | { |
| 150 | tmpl: `{{$ppctx := "!"}}a{{ pp }}123{{ xpp }}b{{qq}}456{{ xpp }}c`, |
| 151 | want: `{"0":"[123]","1":"(456]","s":["a","b","c"]}`, |
| 152 | plain: `a[123]b(456]c`, |
| 153 | }, |
| 154 | { |
| 155 | tmpl: `{{$ppctx := "!"}}a{{ .X }}b{{ pp }}123{{ xpp }}c`, |
| 156 | want: `{"0":"X","1":"[123]","s":["a","b","c"]}`, |
| 157 | plain: `aXb[123]c`, |
| 158 | }, |
| 159 | } |
| 160 | |
| 161 | for _, test := range tests { |
| 162 | testExec(t, funcs, test.tmpl, test.want, test.plain, dot{"X": "X"}) |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | func TestEmptyRangeSerialization(t *testing.T) { |
| 167 | root := tmpl.NewTree() |
nothing calls this directly
no test coverage detected