Skip to content

Commit

Permalink
Version bump + few minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaliszko committed Jul 7, 2016
1 parent 1db7a2f commit 289790e
Show file tree
Hide file tree
Showing 20 changed files with 205 additions and 109 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Here instead, we're saying "If condition is met, return some view. Otherwise, ad

#####<a id="grammar">Grammar definition</a>

Valid logical expressions handled by EA parser comply with syntax defined by the following grammar:
Valid expressions handled by EA parser comply with syntax defined by the following grammar:

```
exp => cond-exp
Expand Down
7 changes: 4 additions & 3 deletions build/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ $testdlls = "`"`"$eatestdll`"`" `"`"$vatestdll`"`" `"`"$uitestdll`"`""
$webmvcbin = "$rootdir\src\ExpressiveAnnotations.MvcWebSample\bin"

# collect JS tests
$maintest = "$rootdir\src\expressive.annotations.validate.test.js"
$formtest = "$rootdir\src\tests.html"
$maintest = "$rootdir\src\expressive.annotations.validate.test.js"
$formtest = "$rootdir\src\form.tests.harness.html"
$formtestnew = "$rootdir\src\form.tests.harness.latestdeps.html"

# run tests and analyze code coverage
& $opencover -register:user "-target:$xunit" "-targetargs:$testdlls -nologo -noshadow -appveyor" "-targetdir:$webmvcbin" "-filter:+[ExpressiveAnnotations(.MvcUnobtrusive)?]*" -output:csharp-coverage.xml -hideskipped:All -mergebyhash -returntargetcode
Expand All @@ -37,7 +38,7 @@ if($LastExitCode -ne 0) {
throw "C# tests failed"
}

& $chutzpah /nologo /path $maintest /path $formtest /junit chutzpah-tests.xml /coverage /coverageIgnores "*test*, *jquery*" /coveragehtml javascript-coverage.htm /lcov javascript-coverage.lcov
& $chutzpah /nologo /path $maintest /path $formtest /path $formtestnew /junit chutzpah-tests.xml /coverage /coverageIgnores "*test*, *jquery*" /coveragehtml javascript-coverage.htm /lcov javascript-coverage.lcov

if($LastExitCode -ne 0) {
if($env:APPVEYOR -eq $true) {
Expand Down
Binary file modified doc/api/api.chm
Binary file not shown.
2 changes: 1 addition & 1 deletion src/.nuget/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Chutzpah" version="4.2.1" />
<package id="Chutzpah" version="4.2.3" />
<package id="OpenCover" version="4.6.519" />
<package id="xunit.runner.console" version="2.1.0" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Moq, Version=4.2.1409.1722, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath>
<Reference Include="Moq, Version=4.5.10.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.5.10\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand Down Expand Up @@ -127,7 +131,9 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources.pl.resx" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.3.3" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net451" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net451" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net451" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net451" />
<package id="Moq" version="4.5.10" targetFramework="net451" />
<package id="Newtonsoft.Json" version="5.0.5" targetFramework="net451" />
<package id="xunit" version="2.1.0" targetFramework="net451" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net451" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.4.7.0")]
[assembly: AssemblyFileVersion("2.4.7.0")]
[assembly: AssemblyVersion("2.4.8.0")]
[assembly: AssemblyFileVersion("2.4.8.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=4.2.1409.1722, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Moq, Version=4.5.10.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.5.10\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -93,7 +97,9 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources.pl.resx" />
Expand Down
20 changes: 20 additions & 0 deletions src/ExpressiveAnnotations.Tests/ParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,26 @@ public void verify_various_parsing_errors()
e = Assert.Throws<ParseErrorException>(() => parser.Parse<Model, bool>("GetObject()[0]").Invoke(null));
Assert.Equal("Indexing operation not supported. Subscript operator can be applied to either an array or a type declaring indexer.", e.Error);
Assert.Equal(new Location(1, 12), e.Location, new LocationComparer());

e = Assert.Throws<ParseErrorException>(() => parser.Parse<Model, bool>("SubModel.Unknown1.Unknown2 == 1").Invoke(new Model()));
Assert.Equal("Only public properties, constants and enums are accepted. Identifier 'Unknown1' not known.", e.Error);
Assert.Equal(new Location(1, 10), e.Location, new LocationComparer());

e = Assert.Throws<ParseErrorException>(() => parser.Parse<Model, bool>("GetObject().Unknown1.Unknown2 == 1").Invoke(new Model()));
Assert.Equal("Only public properties, constants and enums are accepted. Identifier 'Unknown1' not known.", e.Error);
Assert.Equal(new Location(1, 13), e.Location, new LocationComparer());

e = Assert.Throws<ParseErrorException>(() => parser.Parse<Model, bool>("[SubModel][0].Unknown1.Unknown2 == 1").Invoke(new Model()));
Assert.Equal("Only public properties, constants and enums are accepted. Identifier 'Unknown1' not known.", e.Error);
Assert.Equal(new Location(1, 15), e.Location, new LocationComparer());

e = Assert.Throws<ParseErrorException>(() => parser.Parse<Model, bool>("[1").Invoke(new Model()));
Assert.Equal("Expected comma or closing bracket. Unexpected end of expression.", e.Error);
Assert.Equal(new Location(1, 3), e.Location, new LocationComparer());

e = Assert.Throws<ParseErrorException>(() => parser.Parse<Model, bool>("[1)").Invoke(new Model()));
Assert.Equal("Expected comma or closing bracket. Unexpected token: ')'.", e.Error);
Assert.Equal(new Location(1, 3), e.Location, new LocationComparer());
}

[Fact]
Expand Down
7 changes: 7 additions & 0 deletions src/ExpressiveAnnotations.Tests/UtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ public void throw_when_non_positive_parameters_are_provided_for_error_message_co
Assert.Equal("Column number should be positive.\r\nParameter name: column", e.Message);
}

[Fact]
public void print_token_for_debug_purposes()
{
var token = new Token(TokenType.FLOAT, 1.0, "1.0", new Location(1, 2));
Assert.Equal(@"""1.0"" FLOAT (1, 2)", token.ToString());
}

private class Model
{
[Display(Name = "Value_1")]
Expand Down
3 changes: 2 additions & 1 deletion src/ExpressiveAnnotations.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Moq" version="4.2.1409.1722" targetFramework="net451" />
<package id="Castle.Core" version="3.3.3" targetFramework="net451" />
<package id="Moq" version="4.5.10" targetFramework="net451" />
<package id="xunit" version="2.1.0" targetFramework="net451" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net451" />
<package id="xunit.assert" version="2.1.0" targetFramework="net451" />
Expand Down
6 changes: 4 additions & 2 deletions src/ExpressiveAnnotations.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExpressiveAnnotations", "ExpressiveAnnotations\ExpressiveAnnotations.csproj", "{70DD327B-F37C-4291-9388-212AA541E970}"
EndProject
Expand All @@ -18,7 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{5908
expressive.annotations.validate.js = expressive.annotations.validate.js
expressive.annotations.validate.min.js = expressive.annotations.validate.min.js
expressive.annotations.validate.test.js = expressive.annotations.validate.test.js
tests.html = tests.html
form.tests.harness.html = form.tests.harness.html
form.tests.harness.latestdeps.html = form.tests.harness.latestdeps.html
form.tests.js = form.tests.js
EndProjectSection
ProjectSection(FolderStartupServices) = postProject
{82A7F48D-3B50-4B1E-B82E-3ADA8210C358} = {82A7F48D-3B50-4B1E-B82E-3ADA8210C358}
Expand Down
8 changes: 4 additions & 4 deletions src/ExpressiveAnnotations/Analysis/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private Expression ParseEqualityExp()

var type1 = arg1.Type;
var type2 = arg2.Type;
Helper.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type);
TypeAdapter.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type);
Wall.Eq(arg1, arg2, type1, type2, oper);

switch (oper.Type)
Expand Down Expand Up @@ -399,7 +399,7 @@ private Expression ParseRelationalExp()

var type1 = arg1.Type;
var type2 = arg2.Type;
Helper.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type);
TypeAdapter.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type);
Wall.Rel(arg1, arg2, type1, type2, oper);

switch (oper.Type)
Expand Down Expand Up @@ -459,7 +459,7 @@ private Expression ParseAdditiveExp()

var type1 = arg1.Type;
var type2 = arg2.Type;
Helper.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type);
TypeAdapter.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type);
Wall.Add(arg1, arg2, type1, type2, oper);

switch (oper.Type)
Expand Down Expand Up @@ -491,7 +491,7 @@ private Expression ParseMultiplicativeExp()
var arg2 = ParseUnaryExp();

Wall.Mul(arg1, arg2, oper);
Helper.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type);
TypeAdapter.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type);

switch (oper.Type)
{
Expand Down
56 changes: 56 additions & 0 deletions src/ExpressiveAnnotations/Analysis/TypeAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Diagnostics;
using System.Linq.Expressions;

namespace ExpressiveAnnotations.Analysis
{
internal static class TypeAdapter
{
public static void MakeTypesCompatible(Expression e1, Expression e2, out Expression oute1, out Expression oute2, TokenType operation)
{
Debug.Assert(e1 != null);
Debug.Assert(e2 != null);

oute1 = e1;
oute2 = e2;

if (oute1.Type.IsEnum && oute2.Type.IsEnum
&& oute1.Type.UnderlyingType() != oute2.Type.UnderlyingType()) // various enum types
return;

if (operation != TokenType.DIV // do not promote integral numeric values to double - exception for division operation, e.g. 1/2 should evaluate to 0.5 double like in JS
&& !oute1.Type.IsEnum && !oute2.Type.IsEnum
&& oute1.Type.IsNumeric() && oute2.Type.IsNumeric()
&& !oute1.Type.IsFloatingPointNumeric() && !oute2.Type.IsFloatingPointNumeric())
return;

// promote numeric values to double - do computations with higher precision (to be compatible with JavaScript, e.g. 1/2 should evaluate to 0.5 double not 0 int)
if (oute1.Type != typeof (double) && oute1.Type != typeof (double?) && oute1.Type.IsNumeric())
oute1 = oute1.Type.IsNullable()
? Expression.Convert(oute1, typeof (double?))
: Expression.Convert(oute1, typeof (double));
if (oute2.Type != typeof (double) && oute2.Type != typeof (double?) && oute2.Type.IsNumeric())
oute2 = oute2.Type.IsNullable()
? Expression.Convert(oute2, typeof (double?))
: Expression.Convert(oute2, typeof (double));

// non-nullable operand is converted to nullable if necessary, and the lifted-to-nullable form of the comparison is used (C# rule, which is currently not followed by expression trees)
if (oute1.Type.UnderlyingType() == oute2.Type.UnderlyingType())
{
if (oute1.Type.IsNullable() && !oute2.Type.IsNullable())
oute2 = Expression.Convert(oute2, oute1.Type);
else if (!oute1.Type.IsNullable() && oute2.Type.IsNullable())
oute1 = Expression.Convert(oute1, oute2.Type);
}

// make DateTime and TimeSpan compatible (also do not care when first argument is TimeSpan and second DateTime because it is not allowed)
if (oute1.Type.IsDateTime() && oute2.Type.IsTimeSpan())
{
if (oute1.Type.IsNullable() && !oute2.Type.IsNullable())
oute2 = Expression.Convert(oute2, typeof (TimeSpan?));
else if (!oute1.Type.IsNullable() && oute2.Type.IsNullable())
oute1 = Expression.Convert(oute1, typeof (DateTime?));
}
}
}
}
1 change: 1 addition & 0 deletions src/ExpressiveAnnotations/ExpressiveAnnotations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Analysis\TypeAdapter.cs" />
<Compile Include="FunctionsManager.cs" />
<Compile Include="IFunctionsManager.cs" />
<Compile Include="Toolchain.cs" />
Expand Down
47 changes: 0 additions & 47 deletions src/ExpressiveAnnotations/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,6 @@ public AssemblyTypeProvider(Assembly assembly)

internal static class Helper
{
public static void MakeTypesCompatible(Expression e1, Expression e2, out Expression oute1, out Expression oute2, TokenType operation)
{
Debug.Assert(e1 != null);
Debug.Assert(e2 != null);

oute1 = e1;
oute2 = e2;

if (oute1.Type.IsEnum && oute2.Type.IsEnum
&& oute1.Type.UnderlyingType() != oute2.Type.UnderlyingType()) // various enum types
return;

if (operation != TokenType.DIV // do not promote integral numeric values to double - exception for division operation, e.g. 1/2 should evaluate to 0.5 double like in JS
&& !oute1.Type.IsEnum && !oute2.Type.IsEnum
&& oute1.Type.IsNumeric() && oute2.Type.IsNumeric()
&& !oute1.Type.IsFloatingPointNumeric() && !oute2.Type.IsFloatingPointNumeric())
return;

// promote numeric values to double - do computations with higher precision (to be compatible with JavaScript, e.g. 1/2 should evaluate to 0.5 double not 0 int)
if (oute1.Type != typeof (double) && oute1.Type != typeof (double?) && oute1.Type.IsNumeric())
oute1 = oute1.Type.IsNullable()
? Expression.Convert(oute1, typeof (double?))
: Expression.Convert(oute1, typeof (double));
if (oute2.Type != typeof (double) && oute2.Type != typeof (double?) && oute2.Type.IsNumeric())
oute2 = oute2.Type.IsNullable()
? Expression.Convert(oute2, typeof (double?))
: Expression.Convert(oute2, typeof (double));

// non-nullable operand is converted to nullable if necessary, and the lifted-to-nullable form of the comparison is used (C# rule, which is currently not followed by expression trees)
if (oute1.Type.UnderlyingType() == oute2.Type.UnderlyingType())
{
if (oute1.Type.IsNullable() && !oute2.Type.IsNullable())
oute2 = Expression.Convert(oute2, oute1.Type);
else if (!oute1.Type.IsNullable() && oute2.Type.IsNullable())
oute1 = Expression.Convert(oute1, oute2.Type);
}

// make DateTime and TimeSpan compatible (also do not care when first argument is TimeSpan and second DateTime because it is not allowed)
if (oute1.Type.IsDateTime() && oute2.Type.IsTimeSpan())
{
if (oute1.Type.IsNullable() && !oute2.Type.IsNullable())
oute2 = Expression.Convert(oute2, typeof (TimeSpan?));
else if (!oute1.Type.IsNullable() && oute2.Type.IsNullable())
oute1 = Expression.Convert(oute1, typeof (DateTime?));
}
}

public static object ExtractValue(object source, string property)
{
Debug.Assert(source != null);
Expand Down
4 changes: 2 additions & 2 deletions src/ExpressiveAnnotations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.5.1.0")]
[assembly: AssemblyFileVersion("2.5.1.0")]
[assembly: AssemblyVersion("2.6.0.0")]
[assembly: AssemblyFileVersion("2.6.0.0")]
Loading

0 comments on commit 289790e

Please sign in to comment.