Skip to content

Commit 829c0e7

Browse files
author
dmitriy kalinin
committed
add Pointer.IsSet
1 parent a15438b commit 829c0e7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

patch/pointer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ func NewPointer(tokens []Token) Pointer {
103103

104104
func (p Pointer) Tokens() []Token { return p.tokens }
105105

106+
func (p Pointer) IsSet() bool { return len(p.tokens) > 0 }
107+
106108
func (p Pointer) String() string {
107109
var strs []string
108110

patch/pointer_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ var _ = Describe("Pointer.Tokens", func() {
132132
}
133133
})
134134

135+
var _ = Describe("Pointer.IsSet", func() {
136+
It("returns true if there is at least one token", func() {
137+
Expect(MustNewPointerFromString("").IsSet()).To(BeTrue())
138+
})
139+
140+
It("returns false if it's not a valid pointer", func() {
141+
Expect(Pointer{}.IsSet()).To(BeFalse())
142+
})
143+
})
144+
135145
var _ = Describe("Pointer.UnmarshalFlag", func() {
136146
It("parses pointer if it's valid", func() {
137147
ptr := &Pointer{}

0 commit comments

Comments
 (0)