Skip to content

Commit

Permalink
update UnmarshaStr and NewReaderStr to UnmarshalString and NewReaderS…
Browse files Browse the repository at this point in the history
…tring (#123)
  • Loading branch information
R-maan authored Jul 31, 2020
1 parent 76e2dde commit 1913ef1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 56 deletions.
10 changes: 5 additions & 5 deletions ion/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (s System) NewReader(in io.Reader) Reader {
return NewReaderCat(in, s.Catalog)
}

// NewReaderStr creates a new reader using this system's catalog.
func (s System) NewReaderStr(in string) Reader {
// NewReaderString creates a new reader using this system's catalog.
func (s System) NewReaderString(in string) Reader {
return NewReaderCat(strings.NewReader(in), s.Catalog)
}

Expand All @@ -95,9 +95,9 @@ func (s System) Unmarshal(data []byte, v interface{}) error {
return d.DecodeTo(v)
}

// UnmarshalStr unmarshals Ion data using this system's catalog.
func (s System) UnmarshalStr(data string, v interface{}) error {
r := s.NewReaderStr(data)
// UnmarshalString unmarshals Ion data using this system's catalog.
func (s System) UnmarshalString(data string, v interface{}) error {
r := s.NewReaderString(data)
d := NewDecoder(r)
return d.DecodeTo(v)
}
2 changes: 1 addition & 1 deletion ion/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func handleEmbeddedDoc(t *testing.T, r Reader) []ionItem {
if err != nil {
t.Error("Must be string value.")
}
newReader := NewReaderStr(str)
newReader := NewReaderString(str)
for newReader.Next() {
values = append(values, readCurrentValue(t, newReader))
}
Expand Down
4 changes: 2 additions & 2 deletions ion/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func NewReader(in io.Reader) Reader {
return NewReaderCat(in, nil)
}

// NewReaderStr creates a new reader from a string.
func NewReaderStr(str string) Reader {
// NewReaderString creates a new reader from a string.
func NewReaderString(str string) Reader {
return NewReader(strings.NewReader(str))
}

Expand Down
38 changes: 19 additions & 19 deletions ion/textreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func TestIgnoreValues(t *testing.T) {
r := NewReaderStr("(skip ++ me / please) {skip: me, please: 0}\n[skip, me, please]\nfoo")
r := NewReaderString("(skip ++ me / please) {skip: me, please: 0}\n[skip, me, please]\nfoo")

_next(t, r, SexpType)
_next(t, r, StructType)
Expand All @@ -37,7 +37,7 @@ func TestIgnoreValues(t *testing.T) {
func TestReadSexps(t *testing.T) {
test := func(str string, f containerhandler) {
t.Run(str, func(t *testing.T) {
r := NewReaderStr(str)
r := NewReaderString(str)
_sexp(t, r, f)
_eof(t, r)
})
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestReadSexps(t *testing.T) {
func TestStructs(t *testing.T) {
test := func(str string, f containerhandler) {
t.Run(str, func(t *testing.T) {
r := NewReaderStr(str)
r := NewReaderString(str)
_struct(t, r, f)
_eof(t, r)
})
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestStructs(t *testing.T) {
}

func TestMultipleStructs(t *testing.T) {
r := NewReaderStr("{} {} {}")
r := NewReaderString("{} {} {}")

for i := 0; i < 3; i++ {
_struct(t, r, func(t *testing.T, r Reader) {
Expand All @@ -107,7 +107,7 @@ func TestMultipleStructs(t *testing.T) {
}

func TestNullStructs(t *testing.T) {
r := NewReaderStr("null.struct 'null'::{foo:bar}")
r := NewReaderString("null.struct 'null'::{foo:bar}")

_null(t, r, StructType)
_nextAF(t, r, StructType, nil, []string{"null"})
Expand All @@ -117,7 +117,7 @@ func TestNullStructs(t *testing.T) {
func TestLists(t *testing.T) {
test := func(str string, f containerhandler) {
t.Run(str, func(t *testing.T) {
r := NewReaderStr(str)
r := NewReaderString(str)
_list(t, r, f)
_eof(t, r)
})
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestReadNestedLists(t *testing.T) {
_eof(t, r)
}

r := NewReaderStr("[[], [[]]]")
r := NewReaderString("[[], [[]]]")

_list(t, r, func(t *testing.T, r Reader) {
_list(t, r, empty)
Expand All @@ -163,7 +163,7 @@ func TestReadNestedLists(t *testing.T) {
func TestClobs(t *testing.T) {
test := func(str string, eval []byte) {
t.Run(str, func(t *testing.T) {
r := NewReaderStr(str)
r := NewReaderString(str)
_next(t, r, ClobType)

val, err := r.ByteValue()
Expand All @@ -187,7 +187,7 @@ func TestClobs(t *testing.T) {
func TestBlobs(t *testing.T) {
test := func(str string, eval []byte) {
t.Run(str, func(t *testing.T) {
r := NewReaderStr(str)
r := NewReaderString(str)
_next(t, r, BlobType)

val, err := r.ByteValue()
Expand All @@ -210,7 +210,7 @@ func TestBlobs(t *testing.T) {
func TestTimestamps(t *testing.T) {
testA := func(str string, etas []string, eval Timestamp) {
t.Run(str, func(t *testing.T) {
r := NewReaderStr(str)
r := NewReaderString(str)
_nextAF(t, r, TimestampType, nil, etas)

val, err := r.TimestampValue()
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestDecimals(t *testing.T) {
t.Run(str, func(t *testing.T) {
ee := MustParseDecimal(eval)

r := NewReaderStr(str)
r := NewReaderString(str)
_nextAF(t, r, DecimalType, nil, etas)

val, err := r.DecimalValue()
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestDecimals(t *testing.T) {
func TestFloats(t *testing.T) {
testA := func(str string, etas []string, eval float64) {
t.Run(str, func(t *testing.T) {
r := NewReaderStr(str)
r := NewReaderString(str)
_floatAF(t, r, nil, etas, eval)
_eof(t, r)
})
Expand All @@ -307,7 +307,7 @@ func TestFloats(t *testing.T) {
func TestInts(t *testing.T) {
test := func(str string, f func(*testing.T, Reader)) {
t.Run(str, func(t *testing.T) {
r := NewReaderStr(str)
r := NewReaderString(str)
_next(t, r, IntType)

f(t, r)
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestInts(t *testing.T) {
}

func TestStrings(t *testing.T) {
r := NewReaderStr(`foo::"bar" "baz" 'a'::'b'::'''beep''' '''boop''' null.string`)
r := NewReaderString(`foo::"bar" "baz" 'a'::'b'::'''beep''' '''boop''' null.string`)

_stringAF(t, r, nil, []string{"foo"}, "bar")
_string(t, r, "baz")
Expand All @@ -388,7 +388,7 @@ func TestStrings(t *testing.T) {
}

func TestSymbols(t *testing.T) {
r := NewReaderStr("'null'::foo bar a::b::'baz' null.symbol")
r := NewReaderString("'null'::foo bar a::b::'baz' null.symbol")

_symbolAF(t, r, nil, []string{"null"}, "foo")
_symbol(t, r, "bar")
Expand All @@ -399,7 +399,7 @@ func TestSymbols(t *testing.T) {
}

func TestSpecialSymbols(t *testing.T) {
r := NewReaderStr("null\nnull.struct\ntrue\nfalse\nnan")
r := NewReaderString("null\nnull.struct\ntrue\nfalse\nnan")

_null(t, r, NullType)
_null(t, r, StructType)
Expand All @@ -411,7 +411,7 @@ func TestSpecialSymbols(t *testing.T) {
}

func TestOperators(t *testing.T) {
r := NewReaderStr("(a*(b+c))")
r := NewReaderString("(a*(b+c))")

_sexp(t, r, func(t *testing.T, r Reader) {
_symbol(t, r, "a")
Expand All @@ -427,7 +427,7 @@ func TestOperators(t *testing.T) {
}

func TestTopLevelOperators(t *testing.T) {
r := NewReaderStr("a + b")
r := NewReaderString("a + b")

_symbol(t, r, "a")

Expand All @@ -449,7 +449,7 @@ func TestTrsToString(t *testing.T) {
}

func TestInStruct(t *testing.T) {
r := NewReaderStr("[ { a:() } ]")
r := NewReaderString("[ { a:() } ]")

r.Next()
r.StepIn() // In the list, before the struct
Expand Down
4 changes: 2 additions & 2 deletions ion/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func Unmarshal(data []byte, v interface{}) error {
return NewDecoder(NewReader(bytes.NewReader(data))).DecodeTo(v)
}

// UnmarshalStr unmarshals Ion data from a string to the given object.
func UnmarshalStr(data string, v interface{}) error {
// UnmarshalString unmarshals Ion data from a string to the given object.
func UnmarshalString(data string, v interface{}) error {
return Unmarshal([]byte(data), v)
}

Expand Down
Loading

0 comments on commit 1913ef1

Please sign in to comment.