Skip to content

Commit

Permalink
support interrogating Condition/Stack for Parenthetical or Padding st…
Browse files Browse the repository at this point in the history
…atus
  • Loading branch information
JesseCoretta committed Aug 2, 2023
1 parent 496f549 commit 9df2477
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,14 @@ func (r Condition) Paren(state ...bool) Condition {
return r
}

/*
IsParen returns a boolean value indicative of whether the
receiver is parenthetical.
*/
func (r Condition) IsParen() bool {
return r.cfg.positive(parens)
}

func (r *condition) toggleOpt(x cfgFlag) {
r.cfg.toggleOpt(x)
}
Expand Down Expand Up @@ -480,6 +488,14 @@ func (r Condition) NoPadding(state ...bool) Condition {
return r
}

/*
IsPadded returns a boolean value indicative of whether the
receiver pads its contents with a SPACE char (ASCII #32).
*/
func (r Condition) IsPadded() bool {
return !r.cfg.positive(nspad)
}

/*
SetPushPolicy assigns the instance of PushPolicy to the receiver. This
will allow the Set method to control what elements may (or may not) be
Expand Down
18 changes: 18 additions & 0 deletions cond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ func TestCondition_002(t *testing.T) {
}
}

func TestCondition_IsParen(t *testing.T) {
cond := List().Paren().Push(
Cond(`person`, Eq, `Jesse`),
)

if got := cond.IsParen(); !got {
t.Errorf("%s failed: want 'true', got '%t'", t.Name(), got)
}
}

func TestCondition_IsPadded(t *testing.T) {
cond := Cond(`person`, Eq, `Jesse`).Paren().Encap(`"`).NoPadding()

if got := cond.IsPadded(); got {
t.Errorf("%s failed: want 'false', got '%t'", t.Name(), got)
}
}

func ExampleCondition_basic() {
c := Cond(`person`, Eq, `Jesse`).Paren().Encap(`"`).NoPadding()
fmt.Printf("%s", c)
Expand Down
16 changes: 16 additions & 0 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ func (r Stack) Paren(state ...bool) Stack {
return r
}

/*
IsParen returns a boolean value indicative of whether the
receiver is parenthetical.
*/
func (r Stack) IsParen() bool {
return r.stack.positive(parens)
}

/*
Stack will fold the case of logical Boolean operators which
are not represented through symbols. For example, `AND`
Expand Down Expand Up @@ -629,6 +637,14 @@ func (r Stack) NoPadding(state ...bool) Stack {
return r
}

/*
IsPadded returns a boolean value indicative of whether the
receiver pads its contents with a SPACE char (ASCII #32).
*/
func (r Stack) IsPadded() bool {
return r.stack.positive(parens)
}

/*
Symbol sets the provided symbol expression, which will be
a sequence of any characters desired, to represent various
Expand Down
25 changes: 25 additions & 0 deletions stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,37 @@ func TestStack_And001(t *testing.T) {
`testing2`,
`testing3`,
)

want := `( testing1 AND testing2 AND testing3 )`
if got.String() != want {
t.Errorf("%s failed: want '%s', got '%s'", t.Name(), want, got)
}
}

func TestStack_IsParen(t *testing.T) {
stk := And().Paren().Fold().Push(
`testing1`,
`testing2`,
`testing3`,
)

if got := stk.IsParen(); !got {
t.Errorf("%s failed: want 'true', got '%t'", t.Name(), got)
}
}

func TestStack_IsPadded(t *testing.T) {
stk := And().Paren().Fold().Push(
`testing1`,
`testing2`,
`testing3`,
)

if got := stk.IsPadded(); !got {
t.Errorf("%s failed: want 'true', got '%t'", t.Name(), got)
}
}

func TestStackAnd_001(t *testing.T) {

A := And().Paren().Push(
Expand Down

0 comments on commit 9df2477

Please sign in to comment.