Debian Codegraph @

internal/util/tag_test.go

raw
1 // Copyright (c) 2019, Maxime Soulé
2 // All rights reserved.
3 //
4 // This source code is licensed under the BSD-style license found in the
5 // LICENSE file in the root directory of this source tree.
6
7 package util_test
8
9 import (
10 "testing"
11
12 "github.com/maxatome/go-testdeep/internal/util"
13 )
14
15 func TestCheckTag(t *testing.T) {
16 tags := []string{
17 "tag12",
18 "_1é",
19 "a9",
20 "a",
21 "é൫",
22 "é",
23 "_",
24 }
25 for _, tag := range tags {
26 if err := util.CheckTag(tag); err != nil {
27 t.Errorf("check(%s) failed: %s", tag, err)
28 }
29 }
30
31 tagsInfo := []struct {
32 tag string
33 err error
34 }{
35 {tag: "", err: util.ErrTagEmpty},
36 {tag: "൫a", err: util.ErrTagInvalid},
37 {tag: "9a", err: util.ErrTagInvalid},
38 {tag: "é ", err: util.ErrTagInvalid},
39 }
40 for _, info := range tagsInfo {
41 err := util.CheckTag(info.tag)
42 if err == nil {
43 t.Errorf("check(%s) should not succeed", info.tag)
44 } else if err != info.err {
45 t.Errorf(`check(%s) returned "%s" intead of expected "%s"`,
46 info.tag, err, info.err)
47 }
48 }
49 }