Skip to content

Commit

Permalink
add lambda unit tests for invalid scenario and to check return type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davideicardi authored Nov 25, 2021
1 parent 862aa8a commit afaeaaf
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion test/DynamicExpresso.UnitTest/LambdaExpressionTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DynamicExpresso.Exceptions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand All @@ -10,6 +11,28 @@ public class LambdaExpressionTest
{
private const InterpreterOptions _options = InterpreterOptions.Default | InterpreterOptions.LambdaExpressions;

[Test]
public void Invalid_Lambda_Should_Produce_a_ParseException()
{
var target = new Interpreter(_options);
var list = new List<string> { "abc", "dfe", "test" };
target.SetVariable("list", list);

Assert.Throws<ParseException>(() => target.Parse("list.Select(str => str.Legnth)") );
}

[Test]
public void Check_Lambda_Return_Type()
{
var target = new Interpreter(_options);
var list = new List<string> { "abc", "dfe", "test" };
target.SetVariable("list", list);

var lambda = target.Parse("list.Select(str => str.Length)");

Assert.AreEqual(typeof(IEnumerable<int>), lambda.ReturnType);
}

[Test]
public void Where_inferred_parameter_type()
{
Expand Down Expand Up @@ -249,7 +272,7 @@ public void Zip()
}

/// <summary>
/// Ensure that a lambda expression is matched to a parameter of type delegate
/// Ensure that a lambda expression is matched to a parameter of type delegate
/// (so the 1st overload shouldn't be considered during resolution)
/// </summary>
internal static class ExtensionMethodExt
Expand Down

0 comments on commit afaeaaf

Please sign in to comment.