Skip to content

Commit

Permalink
Remove unused RemoveProperty of unmarshal.go
Browse files Browse the repository at this point in the history
  • Loading branch information
zemyblue authored and Kynea0b committed May 6, 2021
1 parent 2496cf5 commit 6134756
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/contract_tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
func removeOptionalFieldsOfExpected(t *transaction.Transaction, paths []string) {
expected := unmarshaler.UnmarshalJSON(&t.Expected.Body)
for _, path := range paths {
expected.RemoveProperty(strings.Split(path, "."))
expected.DeleteProperty(strings.Split(path, ".")...)
}
newBody, err := json.Marshal(expected.Body)
if err != nil {
Expand Down
24 changes: 0 additions & 24 deletions cmd/contract_tests/unmarshaler/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package unmarshaler

import (
"encoding/json"
"fmt"
"strconv"

"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -42,27 +39,6 @@ func (obj *UnmarshalledArbitraryObject) DeleteProperty(keys ...string) {
delete(body.(map[string]interface{}), lastKey)
}

func (obj *UnmarshalledArbitraryObject) RemoveProperty(keys []string) {
keyToRemove := keys[len(keys)-1]

body := obj.Body
for _, key := range keys[:len(keys)-1] {
switch parent := body.(type) {
case map[string]interface{}:
body = parent[key]
case []interface{}:
idx, err := strconv.Atoi(key)
if err != nil {
panic(fmt.Sprintf("illegal property path(%s)", err))
}
body = parent[idx]
default:
panic("illegal property path")
}
}
delete(body.(map[string]interface{}), keyToRemove)
}

func UnmarshalJSON(str *string) UnmarshalledArbitraryObject {
return UnmarshalledArbitraryObject{unmarshalArbitraryFormat(json.Unmarshal, str)}
}
Expand Down

0 comments on commit 6134756

Please sign in to comment.