Skip to content

Commit

Permalink
fix unreliable Stack.Fold method behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseCoretta committed Sep 3, 2023
1 parent fd60526 commit e2553a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func (r stack) stackType() stackType {
return sc.stackType()
}

func (r stack) stackKind() string {
sc, _ := r.config()
return sc.kind()
}

func (r nodeConfig) isError() bool {
return r.err != nil
}
Expand Down Expand Up @@ -151,11 +156,7 @@ func (r *nodeConfig) kind() (kind string) {

switch r.typ {
case and, or, not, list, cond:
kind = r.typ.String()
}

if r.positive(cfold) {
kind = lc(kind)
kind = foldValue(r.positive(cfold), r.typ.String())
}

return
Expand Down
2 changes: 1 addition & 1 deletion stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ with an implicit null uint8 value (0x0).
*/
func (r stack) typ() (kind string, typ stackType) {
typ = r.stackType()
kind = typ.String()
kind = r.kind()
if sym := r.getSymbol(); len(sym) > 0 {
kind = sym
} else if !(typ == list || typ == basic) {
Expand Down
8 changes: 4 additions & 4 deletions stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestStack_And001(t *testing.T) {
`testing3`,
)

want := `( testing1 AND testing2 AND testing3 )`
want := `( testing1 and testing2 and testing3 )`
if got.String() != want {
t.Errorf("%s failed: want '%s', got '%s'", t.Name(), want, got)
}
Expand All @@ -53,19 +53,19 @@ func TestStack_Insert(t *testing.T) {

got.Insert(`testing0`, 0)

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

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

got.Insert(`testing4`, 15)
want = `( testing0 AND testing1 AND testing2 AND testing2.5 AND testing3 AND testing4 )`
want = `( testing0 and testing1 and testing2 and testing2.5 and testing3 and testing4 )`
if got.String() != want {
t.Errorf("%s.3 failed: want '%s', got '%s'", t.Name(), want, got)
}
Expand Down

0 comments on commit e2553a4

Please sign in to comment.