Skip to content

Commit

Permalink
Merge branch 'main' of github.com:xiatechs/jsonata-go into xiatechs-main
Browse files Browse the repository at this point in the history
  • Loading branch information
tbal999 committed May 14, 2023
2 parents 3bdc564 + 49373f6 commit bf93223
Show file tree
Hide file tree
Showing 40 changed files with 798 additions and 119 deletions.
40 changes: 18 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
on: [push]
on:
push:
branches: '*'
pull_request:
branches: '*'

name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
run: |
go get -u honnef.co/go/tools/cmd/staticcheck@latest
go get -u golang.org/x/tools/cmd/goimports
- name: Run staticcheck
run: staticcheck ./...
- name: Check code formatting
run: test -z $(goimports -l .)
- name: Run Test
run: go test ./...
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20.1'

- name: Checkout code
uses: actions/checkout@v2

- name: Unit tests
run: go test ./... -race
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
.idea

# Test binary, built with `go test -c`
*.test
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to tbal999/jsonata-go
# Contributing to blues/jsonata-go [xiatechs fork]

We love pull requests from everyone. By participating in this project, you
agree to abide by the Blues Inc [code of conduct].
Expand All @@ -18,7 +18,7 @@ clean up inconsistent whitespace )
* by closing [issues][]
* by reviewing patches

[issues]: https://github.com/tbal999/jsonata-go/issues
[issues]: https://github.com/xiatechs/jsonata-go/issues

## Submitting an Issue

Expand Down Expand Up @@ -55,7 +55,7 @@ clean up inconsistent whitespace )
* If you don't know how to add tests, please put in a PR and leave a comment asking for help.
We love helping!

[repo]: https://github.com/tbal999/jsonata-go/tree/master
[repo]: https://github.com/xiatechs/jsonata-go/tree/master
[fork]: https://help.github.com/articles/fork-a-repo/
[branch]:
https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ It currently has feature parity with jsonata-js 1.5.4. As well as a most of the

## Install

go get github.com/tbal999/jsonata-go
go get github.com/xiatechs/jsonata-go

## Usage

Expand All @@ -17,7 +17,7 @@ import (
"fmt"
"log"

jsonata "github.com/tbal999/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

const jsonString = `
Expand Down Expand Up @@ -56,7 +56,7 @@ func main() {

## JSONata Server
A locally hosted version of [JSONata Exerciser](http://try.jsonata.org/)
for testing is [available here](https://github.com/tbal999/jsonata-go/jsonata-server).
for testing is [available here](https://github.com/xiatechs/jsonata-go/jsonata-server).

## JSONata tests
A CLI tool for running jsonata-go against the [JSONata test suite](https://github.com/jsonata-js/jsonata/tree/master/test/test-suite) is [available here](./jsonata-test).
Expand Down
13 changes: 10 additions & 3 deletions callable.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
"reflect"
"regexp"
"strings"
"sync"

"github.com/tbal999/jsonata-go/jlib"
"github.com/tbal999/jsonata-go/jparse"
"github.com/tbal999/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type callableName struct {
mu sync.Mutex
name string
}

Expand All @@ -25,6 +27,8 @@ func (n callableName) Name() string {
}

func (n *callableName) SetName(s string) {
n.mu.Lock()
defer n.mu.Unlock()
n.name = s
}

Expand Down Expand Up @@ -76,6 +80,7 @@ func newGoCallableParam(typ reflect.Type) goCallableParam {
// A goCallable represents a built-in or third party Go function.
// It implements the Callable interface.
type goCallable struct {
mu sync.Mutex
callableName
callableMarshaler
fn reflect.Value
Expand Down Expand Up @@ -205,6 +210,8 @@ func makeGoCallableParams(typ reflect.Type) []goCallableParam {
}

func (c *goCallable) SetContext(context reflect.Value) {
c.mu.Lock()
defer c.mu.Unlock()
c.context = context
}

Expand Down
41 changes: 27 additions & 14 deletions callable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"regexp"
"sort"
"strings"
"sync"
"testing"

"github.com/tbal999/jsonata-go/jparse"
"github.com/tbal999/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

var (
Expand Down Expand Up @@ -2371,30 +2372,34 @@ func TestRegexCallable(t *testing.T) {
"groups": []string{},
"next": &matchCallable{
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ac",
start: 3,
end: 5,
groups: []string{},
next: &matchCallable{
callableName: callableName{
"next",
},
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ad",
start: 5,
end: 7,
groups: []string{},
next: &matchCallable{
callableName: callableName{
"next",
},
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ab",
start: 7,
end: 9,
groups: []string{},
next: &matchCallable{
callableName: callableName{
sync.Mutex{},
"next",
},
match: "a",
Expand Down Expand Up @@ -2425,6 +2430,7 @@ func TestRegexCallable(t *testing.T) {
},
"next": &matchCallable{
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ac",
Expand All @@ -2435,6 +2441,7 @@ func TestRegexCallable(t *testing.T) {
},
next: &matchCallable{
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ad",
Expand All @@ -2444,9 +2451,10 @@ func TestRegexCallable(t *testing.T) {
"d",
},
next: &matchCallable{
callableName: callableName{
"next",
},
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ab",
start: 7,
end: 9,
Expand All @@ -2455,6 +2463,7 @@ func TestRegexCallable(t *testing.T) {
},
next: &matchCallable{
callableName: callableName{
sync.Mutex{},
"next",
},
match: "a",
Expand Down Expand Up @@ -2491,6 +2500,7 @@ func TestRegexCallable(t *testing.T) {
},
"next": &matchCallable{
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ac",
Expand All @@ -2502,6 +2512,7 @@ func TestRegexCallable(t *testing.T) {
},
next: &matchCallable{
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ad",
Expand All @@ -2512,9 +2523,10 @@ func TestRegexCallable(t *testing.T) {
"", // undefined in jsonata-js
},
next: &matchCallable{
callableName: callableName{
"next",
},
callableName: callableName{
sync.Mutex{},
"next",
},
match: "ab",
start: 7,
end: 9,
Expand All @@ -2524,6 +2536,7 @@ func TestRegexCallable(t *testing.T) {
},
next: &matchCallable{
callableName: callableName{
sync.Mutex{},
"next",
},
match: "a",
Expand Down
38 changes: 34 additions & 4 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"strings"
"unicode/utf8"

"github.com/tbal999/jsonata-go/jlib"
"github.com/tbal999/jsonata-go/jparse"
"github.com/tbal999/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type environment struct {
Expand Down Expand Up @@ -67,6 +67,37 @@ var (

var baseEnv = initBaseEnv(map[string]Extension{

/*
EXTENDED START
*/
"objmerge": {
Func: jlib.ObjMerge,
UndefinedHandler: defaultUndefinedHandler,
EvalContextHandler: nil,
},

"sjoin": {
Func: jlib.SimpleJoin,
UndefinedHandler: defaultUndefinedHandler,
EvalContextHandler: nil,
},

"eval": {
Func: RunEval,
UndefinedHandler: defaultUndefinedHandler,
EvalContextHandler: defaultContextHandler,
},

"unescape": {
Func: jlib.Unescape,
UndefinedHandler: defaultUndefinedHandler,
EvalContextHandler: defaultContextHandler,
},

/*
EXTENDED END
*/

// String functions

"string": {
Expand Down Expand Up @@ -442,7 +473,6 @@ func undefinedHandlerAppend(argv []reflect.Value) bool {
// Context handlers

func contextHandlerSubstring(argv []reflect.Value) bool {

// If substring() is called with one or two numeric arguments,
// use the evaluation context as the first argument.
switch len(argv) {
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"regexp"

"github.com/tbal999/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// ErrUndefined is returned by the evaluation methods when
Expand Down
10 changes: 6 additions & 4 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"math"
"reflect"
"sort"
"sync"

"github.com/tbal999/jsonata-go/config"
"github.com/tbal999/jsonata-go/jlib"
"github.com/tbal999/jsonata-go/jparse"
"github.com/tbal999/jsonata-go/jtypes"
"github.com/shopspring/decimal"
"github.com/xiatechs/jsonata-go/config"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

var undefined reflect.Value
Expand Down Expand Up @@ -831,6 +832,7 @@ func evalTypedLambda(node *jparse.TypedLambdaNode, data reflect.Value, env *envi
func evalObjectTransformation(node *jparse.ObjectTransformationNode, data reflect.Value, env *environment) (reflect.Value, error) {
f := &transformationCallable{
callableName: callableName{
sync.Mutex{},
"transform",
},
pattern: node.Pattern,
Expand Down
6 changes: 3 additions & 3 deletions eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"strings"
"testing"

"github.com/tbal999/jsonata-go/jlib"
"github.com/tbal999/jsonata-go/jparse"
"github.com/tbal999/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type evalTestCase struct {
Expand Down
2 changes: 1 addition & 1 deletion example_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"log"

jsonata "github.com/tbal999/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

const jsonString = `
Expand Down
Loading

0 comments on commit bf93223

Please sign in to comment.