Skip to content

Commit

Permalink
working one-return no-param method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Knetic committed Jun 20, 2017
1 parent f9296ab commit 2d87532
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
7 changes: 6 additions & 1 deletion evaluationStage.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ func makeAccessorStage(pair []string) evaluationOperator {
}

default:
if right == nil {
params = []reflect.Value{}
break
}

params = []reflect.Value {reflect.ValueOf(right.(interface{}))}
}

Expand All @@ -291,7 +296,7 @@ func makeAccessorStage(pair []string) evaluationOperator {
}

if len(returned) == 1 {
return returned[0], nil
return returned[0].Interface(), nil
}

if len(returned) == 2 {
Expand Down
45 changes: 45 additions & 0 deletions evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ type EvaluationParameter struct {
Value interface{}
}

type dummyParameterStruct struct {
String string
Int int
}

func (this dummyParameterStruct) Func() string {
return "funk"
}

var fooParameter = EvaluationParameter {
Name: "foo",
Value: dummyParameterStruct {
String: "string!",
Int: 101,
},
}

func TestNoParameterEvaluation(test *testing.T) {

evaluationTests := []EvaluationTest{
Expand Down Expand Up @@ -1272,6 +1289,34 @@ func TestParameterizedEvaluation(test *testing.T) {
},
Expected: "foo",
},
EvaluationTest{

Name: "Simple parameter call",
Input: "foo.String",
Parameters: []EvaluationParameter{fooParameter},
Expected: fooParameter.Value.(dummyParameterStruct).String,
},
EvaluationTest{

Name: "Simple parameter function call",
Input: "foo.Func()",
Parameters: []EvaluationParameter{fooParameter},
Expected: "funk",
},
// EvaluationTest{
//
// Name: "Simple parameter call",
// Input: "foo.String == 'hi'",
// Parameters: []EvaluationParameter{fooParameter},
// Expected: fooParameter.Value.(dummyParameterStruct).String,
// },
// EvaluationTest{
//
// Name: "Simple parameter call with modifier",
// Input: "foo.String + 'hi'",
// Parameters: []EvaluationParameter{fooParameter},
// Expected: fooParameter.Value.(dummyParameterStruct).String,
// },
}

runEvaluationTests(evaluationTests, test)
Expand Down
4 changes: 2 additions & 2 deletions stagePlanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func planAccessor(stream *tokenStream) (*evaluationStage, error) {
return planValue(stream)
}

rightStage, err = planValue(stream)
rightStage, err = planTokens(stream)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -365,7 +365,7 @@ func planValue(stream *tokenStream) (*evaluationStage, error) {
if !stream.hasNext() {
return nil, nil
}

token = stream.next()

switch token.Kind {
Expand Down

0 comments on commit 2d87532

Please sign in to comment.