TestScriptTemplateHelperFunctions tests the helper functions used in templates.
(t *testing.T)
| 271 | // TestScriptTemplateHelperFunctions tests the helper functions used in |
| 272 | // templates. |
| 273 | func TestScriptTemplateHelperFunctions(t *testing.T) { |
| 274 | t.Run("rangeIter", func(t *testing.T) { |
| 275 | result := rangeIter(2, 5) |
| 276 | expected := []int{2, 3, 4} |
| 277 | |
| 278 | require.Equal( |
| 279 | t, expected, result, |
| 280 | "rangeIter(2, 5) returned unexpected result", |
| 281 | ) |
| 282 | }) |
| 283 | |
| 284 | t.Run("hexEncode", func(t *testing.T) { |
| 285 | input := []byte{0x12, 0x34, 0x56} |
| 286 | result := hexEncode(input) |
| 287 | expected := "0x123456" |
| 288 | |
| 289 | require.Equal( |
| 290 | t, expected, result, |
| 291 | "hexEncode(%v) = %q, want %q", |
| 292 | input, result, expected, |
| 293 | ) |
| 294 | }) |
| 295 | |
| 296 | t.Run("hexStr", func(t *testing.T) { |
| 297 | input := []byte{0x12, 0x34, 0x56} |
| 298 | result := hexStr(input) |
| 299 | expected := "123456" |
| 300 | |
| 301 | require.Equal( |
| 302 | t, expected, result, |
| 303 | "hexStr(%v) = %q, want %q", |
| 304 | input, result, expected, |
| 305 | ) |
| 306 | }) |
| 307 | |
| 308 | t.Run("hexDecode", func(t *testing.T) { |
| 309 | tests := []struct { |
| 310 | input string |
| 311 | expected []byte |
| 312 | wantErr bool |
| 313 | }{ |
| 314 | {"123456", []byte{0x12, 0x34, 0x56}, false}, |
| 315 | {"0x123456", []byte{0x12, 0x34, 0x56}, false}, |
| 316 | {"zz", nil, true}, |
| 317 | } |
| 318 | |
| 319 | for _, test := range tests { |
| 320 | result, err := hexDecode(test.input) |
| 321 | |
| 322 | if test.wantErr { |
| 323 | require.Error( |
| 324 | t, err, |
| 325 | "hexDecode(%q) expected error, got nil", |
| 326 | test.input, |
| 327 | ) |
| 328 | continue |
| 329 | } |
| 330 |