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

AsaiYusuke / jsonpath / 16410926563

21 Jul 2025 07:14AM UTC coverage: 17.851% (-79.5%) from 97.363%
16410926563

Pull #46

github

AsaiYusuke
refactor: move syntax and tests to internal directory

Separate directory structure from public API by relocating syntax
and test files under internal/ directory structure.
Pull Request #46: Move syntax to the internal directory and reorganize tests

181 of 406 new or added lines in 17 files covered. (44.58%)

3 existing lines in 1 file now uncovered.

676 of 3787 relevant lines covered (17.85%)

17.95 hits per line

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

0.0
/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.
NEW
13
func Retrieve(jsonPath string, src interface{}, config ...Config) ([]interface{}, error) {
×
NEW
14
        jsonPathFunc, err := Parse(jsonPath, config...)
×
NEW
15
        if err != nil {
×
NEW
16
                return nil, err
×
NEW
17
        }
×
NEW
18
        return jsonPathFunc(src)
×
19
}
20

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

NEW
35
        parser.Buffer = jsonPath
×
NEW
36

×
NEW
37
        if parser.parse == nil {
×
NEW
38
                parser.Init()
×
NEW
39
        } else {
×
NEW
40
                parser.Reset()
×
NEW
41
        }
×
42

NEW
43
        parser.jsonPathParser.unescapeRegex = unescapeRegex
×
NEW
44

×
NEW
45
        if len(config) > 0 {
×
NEW
46
                parser.jsonPathParser.filterFunctions = config[0].filterFunctions
×
NEW
47
                parser.jsonPathParser.aggregateFunctions = config[0].aggregateFunctions
×
NEW
48
                parser.jsonPathParser.accessorMode = config[0].accessorMode
×
NEW
49
        }
×
50

NEW
51
        parser.Parse()
×
NEW
52
        parser.Execute()
×
NEW
53

×
NEW
54
        root := parser.jsonPathParser.root
×
NEW
55
        return func(src interface{}) ([]interface{}, error) {
×
NEW
56
                container := getContainer()
×
NEW
57
                defer func() {
×
NEW
58
                        putContainer(container)
×
NEW
59
                }()
×
60

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

NEW
68
                result := make([]interface{}, len(container.result))
×
NEW
69
                for index := range result {
×
NEW
70
                        result[index] = container.result[index]
×
NEW
71
                }
×
72

NEW
73
                return result, nil
×
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