mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
Fix SliceNode String()
This commit is contained in:
@@ -94,6 +94,15 @@ func (n *MemberNode) String() string {
|
||||
}
|
||||
|
||||
func (n *SliceNode) String() string {
|
||||
if n.From == nil && n.To == nil {
|
||||
return fmt.Sprintf("%s[:]", n.Node.String())
|
||||
}
|
||||
if n.From == nil {
|
||||
return fmt.Sprintf("%s[:%s]", n.Node.String(), n.To.String())
|
||||
}
|
||||
if n.To == nil {
|
||||
return fmt.Sprintf("%s[%s:]", n.Node.String(), n.From.String())
|
||||
}
|
||||
return fmt.Sprintf("%s[%s:%s]", n.Node.String(), n.From.String(), n.To.String())
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/antonmedv/expr/ast"
|
||||
"github.com/antonmedv/expr/parser"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -63,14 +64,16 @@ func TestPrint(t *testing.T) {
|
||||
{`a.b()`, `a.b()`},
|
||||
{`a.b(c)`, `a.b(c)`},
|
||||
{`a[1:-1]`, `a[1:-1]`},
|
||||
{`a[1:]`, `a[1:]`},
|
||||
{`a[1:]`, `a[1:]`},
|
||||
{`a[:]`, `a[:]`},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
tree, err := parser.Parse(tt.input)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tt.want, tree.Node.String())
|
||||
assert.Equal(t, tt.want, tree.Node.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user