This commit is contained in:
Mike Farah 2021-05-28 16:48:36 +10:00
parent 38b9856f50
commit ac988d9655
6 changed files with 19 additions and 19 deletions

View File

@ -18,12 +18,12 @@ type Evaluator interface {
}
type allAtOnceEvaluator struct {
treeNavigator DataTreeNavigator
treeNavigator dataTreeNavigator
treeCreator ExpressionParser
}
func NewAllAtOnceEvaluator() Evaluator {
return &allAtOnceEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewExpressionParser()}
return &allAtOnceEvaluator{treeNavigator: newDataTreeNavigator(), treeCreator: NewExpressionParser()}
}
func (e *allAtOnceEvaluator) EvaluateNodes(expression string, nodes ...*yaml.Node) (*list.List, error) {

View File

@ -6,21 +6,21 @@ import (
logging "gopkg.in/op/go-logging.v1"
)
type DataTreeNavigator interface {
type dataTreeNavigator interface {
// given the context and a expressionNode,
// this will process the against the given expressionNode and return
// a new context of matching candidates
GetMatchingNodes(context Context, expressionNode *ExpressionNode) (Context, error)
}
type dataTreeNavigator struct {
type dataTreeNavigatorImpl struct {
}
func NewDataTreeNavigator() DataTreeNavigator {
return &dataTreeNavigator{}
func newDataTreeNavigator() dataTreeNavigator {
return &dataTreeNavigatorImpl{}
}
func (d *dataTreeNavigator) GetMatchingNodes(context Context, expressionNode *ExpressionNode) (Context, error) {
func (d *dataTreeNavigatorImpl) GetMatchingNodes(context Context, expressionNode *ExpressionNode) (Context, error) {
if expressionNode == nil {
log.Debugf("getMatchingNodes - nothing to do")
return context, nil

View File

@ -9,7 +9,7 @@ import (
yaml "gopkg.in/yaml.v3"
)
type Encoder interface {
type encoder interface {
Encode(node *yaml.Node) error
}
@ -20,7 +20,7 @@ type yamlEncoder struct {
firstDoc bool
}
func NewYamlEncoder(destination io.Writer, indent int, colorise bool) Encoder {
func newYamlEncoder(destination io.Writer, indent int, colorise bool) encoder {
if indent < 0 {
indent = 0
}
@ -74,7 +74,7 @@ func mapKeysToStrings(node *yaml.Node) {
}
}
func NewJsonEncoder(destination io.Writer, indent int) Encoder {
func newJsonEncoder(destination io.Writer, indent int) encoder {
var encoder = json.NewEncoder(destination)
encoder.SetEscapeHTML(false) // do not escape html chars e.g. &, <, >

View File

@ -65,7 +65,7 @@ func testScenario(t *testing.T, s *expressionScenario) {
os.Setenv("myenv", s.environmentVariable)
}
context, err := NewDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node)
context, err := newDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node)
if err != nil {
t.Error(fmt.Errorf("%v: %v", err, s.expression))
@ -251,7 +251,7 @@ func documentOutput(t *testing.T, w *bufio.Writer, s expressionScenario, formatt
}
context, err := NewDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node)
context, err := newDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node)
if err != nil {
t.Error(err, s.expression)
}

View File

@ -24,7 +24,7 @@ type resultsPrinter struct {
previousDocIndex uint
previousFileIndex int
printedMatches bool
treeNavigator DataTreeNavigator
treeNavigator dataTreeNavigator
}
func NewPrinter(writer io.Writer, outputToJSON bool, unwrapScalar bool, colorsEnabled bool, indent int, printDocSeparators bool) Printer {
@ -36,7 +36,7 @@ func NewPrinter(writer io.Writer, outputToJSON bool, unwrapScalar bool, colorsEn
indent: indent,
printDocSeparators: !outputToJSON && printDocSeparators,
firstTimePrinting: true,
treeNavigator: NewDataTreeNavigator(),
treeNavigator: newDataTreeNavigator(),
}
}
@ -48,14 +48,14 @@ func (p *resultsPrinter) printNode(node *yaml.Node, writer io.Writer) error {
p.printedMatches = p.printedMatches || (node.Tag != "!!null" &&
(node.Tag != "!!bool" || node.Value != "false"))
var encoder Encoder
var encoder encoder
if node.Kind == yaml.ScalarNode && p.unwrapScalar && !p.outputToJSON {
return p.writeString(writer, node.Value+"\n")
}
if p.outputToJSON {
encoder = NewJsonEncoder(writer, p.indent)
encoder = newJsonEncoder(writer, p.indent)
} else {
encoder = NewYamlEncoder(writer, p.indent, p.colorsEnabled)
encoder = newYamlEncoder(writer, p.indent, p.colorsEnabled)
}
return encoder.Encode(node)
}

View File

@ -18,13 +18,13 @@ type StreamEvaluator interface {
}
type streamEvaluator struct {
treeNavigator DataTreeNavigator
treeNavigator dataTreeNavigator
treeCreator ExpressionParser
fileIndex int
}
func NewStreamEvaluator() StreamEvaluator {
return &streamEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewExpressionParser()}
return &streamEvaluator{treeNavigator: newDataTreeNavigator(), treeCreator: NewExpressionParser()}
}
func (s *streamEvaluator) EvaluateNew(expression string, printer Printer) error {