-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function Definition can be added to 'group' functions together to make it easier to write expressions with a lot of redundant function calls Resolves #59
- Loading branch information
1 parent
6290a57
commit 0efcfad
Showing
7 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace ExpressionEngine | ||
{ | ||
/// <summary> | ||
/// A Function Definition is a map to a collected set of functions. | ||
/// - currentCellValue() -> formvalue(logicalName())[idx()][attributeLogicalName()] | ||
/// </summary> | ||
public class FunctionDefinition : IFunctionDefinition | ||
{ | ||
private readonly string _from; | ||
private readonly string _to; | ||
|
||
/// <summary> | ||
/// Construction a Function Definition | ||
/// </summary> | ||
/// <param name="from"></param> | ||
/// <param name="to"></param> | ||
public FunctionDefinition(string from, string to) | ||
{ | ||
_from = @from; | ||
_to = to; | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
public string From() | ||
{ | ||
return _from; | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
public string To() | ||
{ | ||
return _to; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ExpressionEngine | ||
{ | ||
public interface IFunctionDefinition | ||
{ | ||
public string From(); | ||
public string To(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Threading.Tasks; | ||
using ExpressionEngine; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
|
||
namespace Test | ||
{ | ||
public class FunctionDefinitionTests | ||
{ | ||
private IExpressionEngine _ee; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddExpressionEngine(); | ||
serviceCollection.AddFunctionDefinition("addAndConcat()", "concat('result of 1+1 is: ', add(1,1))"); | ||
|
||
_ee = serviceCollection.BuildServiceProvider().GetRequiredService<IExpressionEngine>(); | ||
} | ||
|
||
[TestCase] | ||
public async Task TestFunctionDef() | ||
{ | ||
const string expectedResult = "result of 1+1 is: 2!"; | ||
|
||
var actualResult = await _ee.Parse("@concat(addAndConcat(), '!')"); | ||
|
||
Assert.AreEqual(expectedResult, actualResult); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters