Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix expandText return type error #4132

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ private EvaluatorLookup CustomizedEvaluatorLookup(EvaluatorLookup baseLookup)

if (name.Equals(expandText))
{
return new ExpressionEvaluator(expandText, ExpressionFunctions.Apply(this.ExpandText()), ReturnType.Boolean, ExpressionFunctions.ValidateUnaryString);
return new ExpressionEvaluator(expandText, ExpressionFunctions.Apply(this.ExpandText()), ReturnType.Object, ExpressionFunctions.ValidateUnaryString);
}

return null;
Expand All @@ -518,7 +518,8 @@ private Func<IReadOnlyList<object>, object> ExpandText()
=> (IReadOnlyList<object> args) =>
{
var stringContent = args[0].ToString();
var newScope = CurrentTarget().Scope;

var newScope = evaluationTargetStack.Count == 0 ? null : CurrentTarget().Scope;
var newTemplates = new Templates(templates: Templates, expressionParser: ExpressionParser);
return newTemplates.EvaluateText(stringContent, newScope, lgOptions);
};
Expand Down Expand Up @@ -549,7 +550,7 @@ private Func<IReadOnlyList<object>, object> FromFile()
var resourcePath = GetResourcePath(filePath);
var stringContent = File.ReadAllText(resourcePath);

var newScope = CurrentTarget().Scope;
var newScope = evaluationTargetStack.Count == 0 ? null : CurrentTarget().Scope;
var newTemplates = new Templates(templates: Templates, expressionParser: ExpressionParser);
return newTemplates.EvaluateText(stringContent, newScope, lgOptions);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ private EvaluatorLookup CustomizedEvaluatorLookup(EvaluatorLookup baseLookup, bo

if (name.Equals(expandText))
{
return new ExpressionEvaluator(expandText, ExpressionFunctions.Apply(this.ExpandText()), ReturnType.Boolean, ExpressionFunctions.ValidateUnaryString);
return new ExpressionEvaluator(expandText, ExpressionFunctions.Apply(this.ExpandText()), ReturnType.Object, ExpressionFunctions.ValidateUnaryString);
}

return null;
Expand All @@ -551,7 +551,7 @@ private Func<IReadOnlyList<object>, object> ExpandText()
=> (IReadOnlyList<object> args) =>
{
var stringContent = args[0].ToString();
var newScope = CurrentTarget().Scope;
var newScope = evaluationTargetStack.Count == 0 ? null : CurrentTarget().Scope;
var newTemplates = new Templates(templates: Templates, expressionParser: expressionParser);
return newTemplates.EvaluateText(stringContent, newScope, lgOptions);
};
Expand Down Expand Up @@ -678,7 +678,7 @@ private Func<IReadOnlyList<object>, object> FromFile()
var resourcePath = GetResourcePath(filePath);
var stringContent = File.ReadAllText(resourcePath);

var newScope = CurrentTarget().Scope;
var newScope = evaluationTargetStack.Count == 0 ? null : CurrentTarget().Scope;
var newTemplates = new Templates(templates: Templates, expressionParser: expressionParser);
return newTemplates.EvaluateText(stringContent, newScope, lgOptions);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# template
- ${expandText(@answer)}
- ${length(expandText(@answer))}
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public void TestExpandText()
}
};

// - ${expandText(@answer)}
// - ${length(expandText(@answer))}
var evaled = templates.Evaluate("template", scope);
Assert.AreEqual("hello vivian", evaled);
Assert.AreEqual("hello vivian".Length, evaled);
}

[TestMethod]
Expand Down