diff options
Diffstat (limited to 'template/dict_test.go')
-rw-r--r-- | template/dict_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/template/dict_test.go b/template/dict_test.go new file mode 100644 index 0000000..8b236e0 --- /dev/null +++ b/template/dict_test.go @@ -0,0 +1,42 @@ +// Copyright 2018 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package template + +import ( + "testing" +) + +func TestDict(t *testing.T) { + d, err := dict("k1", "v1", "k2", "v2") + if err != nil { + t.Fatalf(`The dict should be valid: %v`, err) + } + + if value, found := d["k1"]; found { + if value != "v1" { + t.Fatalf(`Incorrect value for k1: %q`, value) + } + } + + if value, found := d["k2"]; found { + if value != "v2" { + t.Fatalf(`Incorrect value for k2: %q`, value) + } + } +} + +func TestDictWithIncorrectNumberOfPairs(t *testing.T) { + _, err := dict("k1", "v1", "k2") + if err == nil { + t.Fatalf(`The dict should not be valid because the number of keys/values pairs are incorrect`) + } +} + +func TestDictWithInvalidKey(t *testing.T) { + _, err := dict(1, "v1") + if err == nil { + t.Fatalf(`The dict should not be valid because the key is not a string`) + } +} |