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

AsaiYusuke / jsonpath / 16411557244

21 Jul 2025 07:59AM UTC coverage: 97.086% (-0.3%) from 97.363%
16411557244

Pull #46

github

AsaiYusuke
update test command to include coverage for internal packages
Pull Request #46: Move syntax to the internal directory and reorganize tests

171 of 181 new or added lines in 16 files covered. (94.48%)

3465 of 3569 relevant lines covered (97.09%)

1007.79 hits per line

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

97.96
/internal/syntax/jsonpath.go
1
package syntax
2

3
import (
4
        "regexp"
5
        "sync"
6
)
7

8
var parseMutex sync.Mutex
9
var parser = pegJSONPathParser{}
10
var unescapeRegex = regexp.MustCompile(`\\(.)`)
11

12
// Retrieve returns the retrieved JSON using the given JSONPath.
13
func Retrieve(jsonPath string, src interface{}, config ...Config) ([]interface{}, error) {
1,404✔
14
        jsonPathFunc, err := Parse(jsonPath, config...)
1,404✔
15
        if err != nil {
1,675✔
16
                return nil, err
271✔
17
        }
271✔
18
        return jsonPathFunc(src)
1,133✔
19
}
20

21
// Parse returns the parser function using the given JSONPath.
22
func Parse(jsonPath string, config ...Config) (f func(src interface{}) ([]interface{}, error), err error) {
1,406✔
23
        parseMutex.Lock()
1,406✔
24
        defer func() {
2,812✔
25
                if exception := recover(); exception != nil {
1,677✔
26
                        if _err, ok := exception.(error); ok {
542✔
27
                                f = nil
271✔
28
                                err = _err
271✔
29
                        }
271✔
30
                }
31
                parser.jsonPathParser = jsonPathParser{}
1,406✔
32
                parseMutex.Unlock()
1,406✔
33
        }()
34

35
        parser.Buffer = jsonPath
1,406✔
36

1,406✔
37
        if parser.parse == nil {
1,407✔
38
                parser.Init()
1✔
39
        } else {
1,406✔
40
                parser.Reset()
1,405✔
41
        }
1,405✔
42

43
        parser.jsonPathParser.unescapeRegex = unescapeRegex
1,406✔
44

1,406✔
45
        if len(config) > 0 {
1,488✔
46
                parser.jsonPathParser.filterFunctions = config[0].filterFunctions
82✔
47
                parser.jsonPathParser.aggregateFunctions = config[0].aggregateFunctions
82✔
48
                parser.jsonPathParser.accessorMode = config[0].accessorMode
82✔
49
        }
82✔
50

51
        parser.Parse()
1,406✔
52
        parser.Execute()
1,406✔
53

1,406✔
54
        root := parser.jsonPathParser.root
1,406✔
55
        return func(src interface{}) ([]interface{}, error) {
2,543✔
56
                container := getContainer()
1,137✔
57
                defer func() {
2,274✔
58
                        putContainer(container)
1,137✔
59
                }()
1,137✔
60

61
                if err := root.retrieve(src, src, container); err != nil {
1,574✔
62
                        if adapter, ok := err.(errorRuntimeAdapter); ok {
874✔
63
                                return nil, adapter.err
437✔
64
                        }
437✔
NEW
65
                        return nil, err.(error)
×
66
                }
67

68
                result := make([]interface{}, len(container.result))
700✔
69
                for index := range result {
2,130✔
70
                        result[index] = container.result[index]
1,430✔
71
                }
1,430✔
72

73
                return result, nil
700✔
74

75
        }, nil
76
}
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