Repository: amzn/ion-go
Pull request #37 (2020-05-22 19:10:58)

Implement isScalar() and isContainer() in type.go
Resolves https://github.com/amzn/ion-go/issues/34


codecov-commenter: # [Codecov](https://codecov.io/gh/amzn/ion-go/pull/37?src=pr&el=h1) Report
> Merging [#37](https://codecov.io/gh/amzn/ion-go/pull/37?src=pr&el=desc) into [master](https://codecov.io/gh/amzn/ion-go/commit/e32dee6c36bc4da508fa2968b135fb17171e1dde&el=desc) will **increase** coverage by `0.06%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/amzn/ion-go/pull/37/graphs/tree.svg?width=650&height=150&src=pr&token=OBDT1TNoNE)](https://codecov.io/gh/amzn/ion-go/pull/37?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #37      +/-   ##
==========================================
+ Coverage   71.81%   71.88%   +0.06%     
==========================================
  Files          22       22              
  Lines        4528     4538      +10     
==========================================
+ Hits         3252     3262      +10     
  Misses        791      791              
  Partials      485      485              
```


| [Impacted Files](https://codecov.io/gh/amzn/ion-go/pull/37?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [ion/type.go](https://codecov.io/gh/amzn/ion-go/pull/37/diff?src=pr&el=tree#diff-aW9uL3R5cGUuZ28=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/amzn/ion-go/pull/37?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/amzn/ion-go/pull/37?src=pr&el=footer). Last update [e32dee6...4b7263c](https://codecov.io/gh/amzn/ion-go/pull/37?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Armanbqt: FYI you can change the description from #34 to _resovles #34_ , so once this gets merged, issue 34 will automatically closed.

Patch:
diff --git a/ion/type.go b/ion/type.go
index f016590..ac82183 100644
--- a/ion/type.go
+++ b/ion/type.go
@@ -90,6 +90,16 @@ func (t Type) String() string {
 	}
 }
 
+// IsScalar determines if the type is a scalar type
+func IsScalar(t Type) bool {
+	return NullType <= t && t <= BlobType
+}
+
+// IsContainer determines if the type is a container type
+func IsContainer(t Type) bool {
+	return ListType <= t && t <= StructType
+}
+
 // IntSize represents the size of an integer.
 type IntSize uint8
 


Test patch:
diff --git a/ion/type_test.go b/ion/type_test.go
index e1702ba..2515fe9 100644
--- a/ion/type_test.go
+++ b/ion/type_test.go
@@ -19,3 +19,41 @@ func TestIntSizeToString(t *testing.T) {
 		}
 	}
 }
+
+func TestIsScalar(t *testing.T) {
+	scalarTypes := []Type{NullType, BoolType, IntType, FloatType, DecimalType,
+		TimestampType, SymbolType, StringType, ClobType, BlobType}
+
+	for _, ionType := range scalarTypes {
+		if !IsScalar(ionType) {
+			t.Errorf("Expected IsScalar() to return true for type %s", ionType.String())
+		}
+	}
+
+	nonScalarTypes := []Type{NoType, ListType, SexpType, StructType}
+
+	for _, ionType := range nonScalarTypes {
+		if IsScalar(ionType) {
+			t.Errorf("Expected IsScalar() to return false for type %s", ionType.String())
+		}
+	}
+}
+
+func TestIsContainer(t *testing.T) {
+	containerTypes := []Type{ListType, SexpType, StructType}
+
+	for _, ionType := range containerTypes {
+		if !IsContainer(ionType) {
+			t.Errorf("Expected IsContainer() to return true for type %s", ionType.String())
+		}
+	}
+
+	nonContainerTypes := []Type{NoType, NullType, BoolType, IntType, FloatType, DecimalType,
+		TimestampType, SymbolType, StringType, ClobType, BlobType}
+
+	for _, ionType := range nonContainerTypes {
+		if IsContainer(ionType) {
+			t.Errorf("Expected IsContainer() to return false for type %s", ionType.String())
+		}
+	}
+}