• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

maxatome / go-testdeep / 21543807886

31 Jan 2026 11:29AM UTC coverage: 26.962% (-73.0%) from 99.921%
21543807886

Pull #287

github

maxatome
chore: gocovmerge not needed anymore

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
Pull Request #287: Some features before the release

25 of 57 new or added lines in 6 files covered. (43.86%)

7342 existing lines in 95 files now uncovered.

2796 of 10370 relevant lines covered (26.96%)

28.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/util/json_pointer.go
1
// Copyright (c) 2020, 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
8

9
import (
10
        "strconv"
11
        "strings"
12
)
13

14
var jsonPointerEsc = strings.NewReplacer("~0", "~", "~1", "/")
15

16
const (
17
        ErrJSONPointerInvalid         = "invalid JSON pointer"
18
        ErrJSONPointerKeyNotFound     = "key not found"
19
        ErrJSONPointerArrayNoIndex    = "array but not an index in JSON pointer"
20
        ErrJSONPointerArrayOutOfRange = "out of array range"
21
        ErrJSONPointerArrayBadType    = "not a map nor an array"
22
)
23

24
type JSONPointerError struct {
25
        Type    string
26
        Pointer string
27
}
28

UNCOV
29
func (e *JSONPointerError) Error() string {
×
UNCOV
30
        if e.Pointer == "" {
×
UNCOV
31
                return e.Type
×
UNCOV
32
        }
×
UNCOV
33
        return e.Type + " @" + e.Pointer
×
34
}
35

36
// JSONPointer returns the value corresponding to JSON pointer
37
// pointer in v as [RFC 6901] specifies it. To be searched, v has
38
// to contains map[string]any or []any values. All
39
// other types fail to be searched.
40
//
41
// [RFC 6901]: https://tools.ietf.org/html/rfc6901
UNCOV
42
func JSONPointer(v any, pointer string) (any, error) {
×
UNCOV
43
        if !strings.HasPrefix(pointer, "/") {
×
UNCOV
44
                if pointer == "" {
×
UNCOV
45
                        return v, nil
×
UNCOV
46
                }
×
UNCOV
47
                return nil, &JSONPointerError{Type: ErrJSONPointerInvalid}
×
48
        }
49

UNCOV
50
        pos := 0
×
UNCOV
51
        for _, part := range strings.Split(pointer[1:], "/") {
×
UNCOV
52
                pos += 1 + len(part)
×
UNCOV
53
                part = jsonPointerEsc.Replace(part)
×
UNCOV
54

×
UNCOV
55
                switch tv := v.(type) {
×
UNCOV
56
                case map[string]any:
×
UNCOV
57
                        var ok bool
×
UNCOV
58
                        v, ok = tv[part]
×
UNCOV
59
                        if !ok {
×
UNCOV
60
                                return nil, &JSONPointerError{
×
UNCOV
61
                                        Type:    ErrJSONPointerKeyNotFound,
×
UNCOV
62
                                        Pointer: pointer[:pos],
×
UNCOV
63
                                }
×
UNCOV
64
                        }
×
65

UNCOV
66
                case []any:
×
UNCOV
67
                        i, err := strconv.Atoi(part)
×
UNCOV
68
                        if err != nil || i < 0 {
×
UNCOV
69
                                return nil, &JSONPointerError{
×
UNCOV
70
                                        Type:    ErrJSONPointerArrayNoIndex,
×
UNCOV
71
                                        Pointer: pointer[:pos],
×
UNCOV
72
                                }
×
UNCOV
73
                        }
×
UNCOV
74
                        if i >= len(tv) {
×
UNCOV
75
                                return nil, &JSONPointerError{
×
UNCOV
76
                                        Type:    ErrJSONPointerArrayOutOfRange,
×
UNCOV
77
                                        Pointer: pointer[:pos],
×
UNCOV
78
                                }
×
UNCOV
79
                        }
×
UNCOV
80
                        v = tv[i]
×
81

UNCOV
82
                default:
×
UNCOV
83
                        return nil, &JSONPointerError{
×
UNCOV
84
                                Type:    ErrJSONPointerArrayBadType,
×
UNCOV
85
                                Pointer: pointer[:pos],
×
UNCOV
86
                        }
×
87
                }
88
        }
89

UNCOV
90
        return v, nil
×
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc