Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #105 arithmetic operator between int and text value #123

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
d3bcf8e
update set allow dotNotation for document and array
Jun 7, 2020
3495af8
update set allow dotNotation for document and array
Jun 7, 2020
3ed3ae3
update set allow dotNotation for document and array
tzzed Jun 7, 2020
ff2b649
retire fmt.Println
tzzed Jun 8, 2020
1883368
Update document/document.go
tzzed Jun 10, 2020
c2c7f03
manage multiple document
tzzed Jun 11, 2020
a7d4628
manage multiple document
tzzed Jun 11, 2020
efb63ba
manage multiple document
tzzed Jun 11, 2020
c162ae1
through a document almost recursive
tzzed Jun 12, 2020
cb8ec1c
through a document almost recursive
tzzed Jun 12, 2020
5207c15
added document manager more properly
tzzed Jun 16, 2020
015c256
added document manager more properly
tzzed Jun 16, 2020
aa1f8a9
Merge branch 'update-setDotN' into develop
tzzed Jun 16, 2020
ea7c7c5
clean repo
tzzed Jun 16, 2020
0cbc987
update document ok
tzzed Jun 17, 2020
a325cfe
update replace field
tzzed Jun 17, 2020
1dacfd8
set document ok + units tests
tzzed Jun 17, 2020
41880bf
document ok missing array
tzzed Jun 18, 2020
fae5b51
manage update array, field and documents with errors handlers for man…
tzzed Jun 21, 2020
53e60ab
fix document, and array
tzzed Jun 24, 2020
1796ffe
everything ok remain errors cases
tzzed Jun 24, 2020
24a9279
add error manager, more tests
tzzed Jun 29, 2020
3036ab4
add error manager, more tests
tzzed Jun 29, 2020
18e4894
error in array
tzzed Jun 29, 2020
e6fcaec
error in array git commit error
tzzed Jun 29, 2020
f1b2dc2
error set docomentValue
tzzed Jun 29, 2020
e2b5f09
error set docomentValue
tzzed Jun 30, 2020
d881a68
broken commit
tzzed Jun 30, 2020
15864e9
broken commit
tzzed Jun 30, 2020
fc88b68
corrected commit, remain array manager
tzzed Jun 30, 2020
4a663a9
everything OK remain array
tzzed Jun 30, 2020
f3c16b8
add units tests cases
tzzed Jul 1, 2020
66d5999
add more tests, and manage double quote in the request
tzzed Jul 1, 2020
5bb3501
add more tests, and manage double quote in the request, cleaned code
tzzed Jul 1, 2020
82e76d2
array is OK
tzzed Jul 1, 2020
306243e
array change index OK, field added correctly
tzzed Jul 1, 2020
224a785
add field to array ok need double quote for field
tzzed Jul 1, 2020
47cf4cd
arry ok, everything ok, remain double quotes in field name
tzzed Jul 2, 2020
1c36edb
field name with double quotes ok, units test ok
tzzed Jul 2, 2020
4b72bfe
field name with double quotes ok, units test ok
tzzed Jul 2, 2020
cf2aa5f
copy corrected
tzzed Jul 2, 2020
50433f0
everything ok, with tests, copy corrected and quotes in fields, code …
tzzed Jul 3, 2020
832dd3c
everything ok, with tests, copy corrected and quotes in fields, code …
tzzed Jul 3, 2020
9ac4f91
everything ok, with tests, copy corrected and quotes in fields, code …
tzzed Jul 3, 2020
3867c14
everything ok, with tests, copy corrected and quotes in fields, code …
tzzed Jul 3, 2020
69517fc
everything ok, with tests, copy corrected and quotes in fields, code …
tzzed Jul 3, 2020
0c91015
remain array of array, code refactored
tzzed Jul 3, 2020
4a92c58
remain array of array, code refactored
tzzed Jul 3, 2020
df122b0
all test ok, remain more code refactored
tzzed Jul 3, 2020
543d489
all test ok, remain more code refactored
tzzed Jul 4, 2020
faa7747
Revert to ae1336155298087a5bf0c6f9dddd3cc2f3e78e54
tzzed Jul 4, 2020
d60b183
add change document field at index of array
tzzed Jul 4, 2020
76065db
all tests ok, commit reference
tzzed Jul 4, 2020
9037c7b
more units test, commit reference
tzzed Jul 4, 2020
97e8c1b
more units test, commit reference
tzzed Jul 4, 2020
28eb3b0
more units test, ok, remain refactoring
tzzed Jul 4, 2020
96f80f6
more units test, ok, remain refactoring
tzzed Jul 4, 2020
bf94205
more units test, ok, with more refactor, nested more refactor again
tzzed Jul 5, 2020
0f69e74
more units test, ok, with more refactor, nested more refactor again
tzzed Jul 5, 2020
f1e7e32
broken commit
tzzed Jul 5, 2020
60de387
broken commit
tzzed Jul 5, 2020
bcaf369
broken commit
tzzed Jul 5, 2020
e08df2e
all tests pass, with some refactoring good. Step 1
tzzed Jul 5, 2020
236ebc2
best version
tzzed Jul 6, 2020
f1ded9e
best version ever
tzzed Jul 6, 2020
5421723
top version, tests are ok, refactoring too
tzzed Jul 6, 2020
131ec98
top version, tests are ok, refactoring too
tzzed Jul 6, 2020
eb050c7
last version to merge
tzzed Jul 7, 2020
7f46596
commit after review of code
tzzed Jul 8, 2020
d0658c5
version to PR
tzzed Jul 9, 2020
552bbee
clean git
tzzed Jul 9, 2020
9dff84c
clean git
tzzed Jul 9, 2020
3773c60
last commit
tzzed Jul 9, 2020
d016822
add merge update setnotation
tzzed Jul 9, 2020
ab9d196
revert to master
tzzed Jul 13, 2020
fbe7759
revert to master
tzzed Jul 13, 2020
9cd187b
fix arithmetic operator between text and int, unit test ok
tzzed Jul 13, 2020
3a7def2
fix arithmetic operator between text and int, unit test ok
tzzed Jul 13, 2020
43ff7aa
Merge branch 'fix/operator' of github.com:tzzed/genji into fix/operator
tzzed Jul 13, 2020
099b8aa
Merge branch 'fix/operator' of github.com:tzzed/genji into fix/operator
tzzed Jul 13, 2020
5277ab7
Merge branch 'fix/operator' of github.com:tzzed/genji into fix/operator
tzzed Jul 13, 2020
bc859ac
fix arithmetic operator between text and int, unit test ok
tzzed Jul 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions cmd/genji/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/genjidb/genji v0.5.0 h1:rmM7kYvcyyaHxgxlbu26IT8jtGUmAw5d2JA+R4UrVkQ=
github.com/genjidb/genji v0.5.0/go.mod h1:3NANDRkY9a++/8GCEN1ifxQ0K5sCoGROgjGO2DsaASk=
github.com/c-bata/go-prompt v0.2.3 h1:jjCS+QhG/sULBhAaBdjb2PlMRVaKXQgn+4yzaauvs2s=
github.com/c-bata/go-prompt v0.2.3/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
Expand Down Expand Up @@ -35,6 +33,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM=
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/genjidb/genji v0.5.0 h1:rmM7kYvcyyaHxgxlbu26IT8jtGUmAw5d2JA+R4UrVkQ=
github.com/genjidb/genji v0.5.0/go.mod h1:3NANDRkY9a++/8GCEN1ifxQ0K5sCoGROgjGO2DsaASk=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
Expand Down Expand Up @@ -92,26 +92,43 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200708003708-134513de8882/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
22 changes: 18 additions & 4 deletions document/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ func (vb *ValueBuffer) Copy(a Array) error {
return err
}

for _, v := range *vb {
// if there is nothing to copy
// exit early and make sure the array
// is not nil but an empty array.
if len(*vb) == 0 {
*vb = ValueBuffer{}
return nil
}

for i, v := range *vb {
switch v.Type {
case DocumentValue:
var buf FieldBuffer
Expand All @@ -115,15 +123,21 @@ func (vb *ValueBuffer) Copy(a Array) error {
return err
}

*vb = vb.Append(NewDocumentValue(&buf))
err = vb.Replace(i, NewDocumentValue(&buf))
if err != nil {
return err
}
case ArrayValue:
var buf ValueBuffer
err = buf.Copy(v.V.(Array))
if err != nil {
return err
}

*vb = vb.Append(NewArrayValue(&buf))
err = vb.Replace(i, NewArrayValue(&buf))
if err != nil {
return err
}
}
}

Expand Down Expand Up @@ -212,4 +226,4 @@ func SortArray(a Array) (Array, error) {
}

return &s.vb, nil
}
}
65 changes: 65 additions & 0 deletions document/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package document

import (
"encoding/json"
"reflect"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -53,3 +54,67 @@ func TestSortArray(t *testing.T) {
})
}
}

func TestValueBuffer_GetByIndexWithString(t *testing.T) {
type args struct {
f string
}


vb := NewValueBuffer(
NewTextValue("foo"),
)

tests := []struct {
name string
vb ValueBuffer
args args
want Value
want1 int
wantErr bool
}{
// TODO: Add test cases.
{"Value at index with string number", vb, args{f: "0"}, NewTextValue("foo"), 0, false},
{"Value at index by with string", vb, args{f: "foo"}, Value{}, -1, true},

}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, err := tt.vb.GetByIndexWithString(tt.args.f)
if (err != nil) != tt.wantErr {
t.Errorf("GetByIndexWithString() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetByIndexWithString() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("GetByIndexWithString() got1 = %v, want %v", got1, tt.want1)
}
})
}
}


func TestValueBufferCopy(t *testing.T) {
tests := []struct {
name string
want string
}{
{"empty array", `[]`},
{"flat", `[1.4,-5,"hello",true]`},
{"nested", `[["foo","bar",1],{"a":1},[1,2]]`},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var from, to ValueBuffer
require.NoError(t, from.UnmarshalJSON([]byte(test.want)))
err := to.Copy(from)
require.NoError(t, err)
got, err := json.Marshal(to)
require.NoError(t, err)
require.Equal(t, test.want, string(got))
})
}
}
26 changes: 25 additions & 1 deletion document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@ type Keyer interface {
Key() []byte
}

// Length returns the length of a document.
func Length(d Document) (int, error) {
if fb, ok := d.(*FieldBuffer); ok {
return fb.Len(), nil
}

var len int
err := d.Iterate(func(_ string, _ Value) error {
len++
return nil
})
return len, err
}

// FieldBuffer stores a group of fields in memory. It implements the Document interface.
type FieldBuffer struct {
fields []fieldValue
key []byte
}

// NewFieldBuffer creates a FieldBuffer.
Expand All @@ -50,6 +65,10 @@ func (fb *FieldBuffer) Add(field string, v Value) *FieldBuffer {

// ScanDocument copies all the fields of d to the buffer.
func (fb *FieldBuffer) ScanDocument(d Document) error {
if k, ok := d.(Keyer); ok {
fb.key = k.Key()
}

return d.Iterate(func(f string, v Value) error {
fb.Add(f, v)
return nil
Expand Down Expand Up @@ -158,6 +177,11 @@ func (fb *FieldBuffer) Reset() {
fb.fields = fb.fields[:0]
}

// Key of the document if any.
func (fb *FieldBuffer) Key() []byte {
return fb.key
}

// A ValuePath represents the path to a particular value within a document.
type ValuePath []string

Expand Down Expand Up @@ -237,4 +261,4 @@ func (p ValuePath) getValueFromValue(v Value) (Value, error) {
}

return Value{}, ErrFieldNotFound
}
}
73 changes: 64 additions & 9 deletions document/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,74 @@ func TestFieldBuffer(t *testing.T) {

t.Run("Set", func(t *testing.T) {
var buf document.FieldBuffer
buf.Add("a", document.NewInt64Value(10))
buf.Add("b", document.NewTextValue("hello"))
var vbuf document.ValueBuffer

buf.Set("a", document.NewFloat64Value(11))
v, err := buf.GetByField("a")
vbuf = vbuf.Append(document.NewInt64Value(1))
vbuf = vbuf.Append(document.NewInt64Value(0))
vbuf = vbuf.Append(document.NewInt64Value(0))

data :=[]byte(`{
"name": "Foo",
"address": {
"city": "Lyon",
"zipcode": "69001"
},
"friends": [
{
"name": "Bar",
"address": {
"city": "Paris",
"zipcode": "75001"
}
},
{
"name": "Baz",
"address": {
"city": "Ajaccio",
"zipcode": "20000"
},
"favorite game": "FF IX"
}
]
}`)
d, err := document.NewFromJSON(data)
buf.Copy(d)


vb, err := buf.GetByField("friends")
require.NoError(t, err)
arr, err := vb.ConvertToArray()
require.NoError(t, err)
v, err := arr.GetByIndex(0)
require.NoError(t, err)
d, err = v.ConvertToDocument()
require.NoError(t, err)
require.Equal(t, document.NewFloat64Value(11), v)
v, err = d.GetByField("address")
fbuf, _ := document.NewFieldBufferByCopy(v)
fbuf.Set(document.NewValuePath("a"), document.NewArrayValue(&vbuf))
err = buf.Set(document.NewValuePath("friends.0.address"), document.NewDocumentValue(fbuf))
require.NoError(t, err)
err = buf.Set(document.NewValuePath("friends.0.address.a.2"), document.NewInt64Value(99))

buf.Set("c", document.NewInt64Value(12))
require.Equal(t, 3, buf.Len())
v, err = buf.GetByField("c")
err = buf.Set(document.NewValuePath("friends.0.address.a.2"), document.NewArrayValue(&vbuf))
require.NoError(t, err)
v, err = buf.GetByField("friends")
require.NoError(t, err)
arr, err = v.ConvertToArray()
require.NoError(t, err)
v, err = arr.GetByIndex(0)
require.NoError(t, err)
require.Equal(t, document.NewInt64Value(12), v)
d, err = v.ConvertToDocument()
v, err = d.GetByField("address")
d, err = v.ConvertToDocument()
va, err := d.GetByField("a")
arr, err = va.ConvertToArray()
v, err = arr.GetByIndex(2)
require.NoError(t, err)
require.Equal(t, v, document.NewArrayValue(vbuf))



})

t.Run("Delete", func(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions document/genji.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": ".."
}
]
}
4 changes: 2 additions & 2 deletions document/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,12 @@ func calculateIntegers(a, b Value, operator byte) (res Value, err error) {

xa, err = a.ConvertToInt64()
if err != nil {
return
return NewNullValue(), nil
}

xb, err = b.ConvertToInt64()
if err != nil {
return
return NewNullValue(), nil
}

var xr int64
Expand Down
Loading