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

Upgrade to .NET Framework 4.6.1, add .NET Core 3.0 target #219

Closed
wants to merge 11 commits into from
Closed
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ Documentation
Build and Maintenance Instructions
----------------------------------

Build the project using [MSBuild][msbuild] or any compatible environment (e.g. Visual Studio 2017 or Rider). WPF-Math requires C# 7.2 support. Build script:
Build the project using .NET Core SDK 3.1. WPF-Math requires C# 8 and F# 4.7 support. Here's the build and test script:

```console
$ nuget restore
$ msbuild /p:Configuration=Release
$ dotnet build --configuration Release
$ dotnet test
```

To run the unit tests, use any xunit-compatible runner (e.g. Visual Studio 2017 or Rider).

To approve the test results if they differ from the existing ones, execute the `scripts/approve-all.ps1` script using PowerShell or PowerShell Core.

To publish the package, execute the following command with [PowerShell][pwsh]:
Expand Down
10 changes: 4 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
image:
- Visual Studio 2017
- Visual Studio 2019
before_build:
- nuget restore

before_test:
- nuget install xunit.runner.console -version 2.4.1
- cinst dotnetcore --version 3.1.0
build_script:
- dotnet build
test_script:
- xunit.runner.console.2.4.1\tools\net46\xunit.console.exe src\WpfMath.Tests\bin\Debug\net461\WpfMath.Tests.dll
- dotnet test
6 changes: 4 additions & 2 deletions src/WpfMath.Example/WpfMath.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Sunburst.NET.Sdk.WPF.Patched/1.0.49">
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<UseWpf>true</UseWpf>
<DebugType>Full</DebugType>
</PropertyGroup>
<ItemGroup>
Expand Down
33 changes: 26 additions & 7 deletions src/WpfMath.Tests/ApprovalTestUtils.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module WpfMath.Tests.ApprovalTestUtils

open System.Globalization
open System.Text
open System.Reflection
open System.Windows.Media
Expand All @@ -19,7 +20,7 @@ do ()

type private InnerPropertyContractResolver() =
inherit DefaultContractResolver()
member private __.DoCreateProperty(p, ms) =
member private _.DoCreateProperty(p, ms) =
base.CreateProperty(p, ms, Readable = true)

override this.CreateProperties(``type``, memberSerialization) =
Expand All @@ -32,21 +33,39 @@ type private InnerPropertyContractResolver() =

type private GlyphTypefaceConverter() =
inherit JsonConverter()
override __.CanConvert ``type`` = ``type`` = typeof<GlyphTypeface>
override _.CanConvert ``type`` = ``type`` = typeof<GlyphTypeface>

override __.CanRead = false
override __.ReadJson(_, _, _, _) = failwith "Not supported"
override _.CanRead = false
override _.ReadJson(_, _, _, _) = failwith "Not supported"

override __.WriteJson(writer, value, _) =
override _.WriteJson(writer, value, _) =
let typeface = value :?> GlyphTypeface
if isNull typeface then
writer.WriteNull()
else
writer.WriteValue(typeface.FontUri)

let private jsonSettings = JsonSerializerSettings (ContractResolver = InnerPropertyContractResolver(),
/// This converter should provide the same results on both .NET 4.6.1 and .NET Core 3.0 which is important for approval
/// tests. The roundtrippable double formatting (used by default) differs between these frameworks.
type private UniversalDoubleConverter() =
inherit JsonConverter()
override _.CanConvert ``type`` = ``type`` = typeof<float>

override _.CanRead = false
override _.ReadJson(_, _, _, _) = failwith "Not supported"

override _.WriteJson(writer, value, _) =
let doubleValue = value :?> float
let stringified = doubleValue.ToString("0.0###############", CultureInfo.InvariantCulture)
writer.WriteRawValue stringified

let private jsonSettings = JsonSerializerSettings(ContractResolver = InnerPropertyContractResolver(),
Formatting = Formatting.Indented,
Converters = [| StringEnumConverter(); GlyphTypefaceConverter() |])
Converters = [|
StringEnumConverter()
GlyphTypefaceConverter()
UniversalDoubleConverter()
|])

let private serialize o =
JsonConvert.SerializeObject(o, jsonSettings)
Expand Down
4 changes: 2 additions & 2 deletions src/WpfMath.Tests/CharBoxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type CharBoxTests() =
static do Utils.initializeFontResourceLoading()

[<Fact>]
member __.``CharBox rendering calls to RenderGlyphRun``() =
member _.``CharBox rendering calls to RenderGlyphRun``() =
let font = DefaultTexFont 20.0
let environment = TexEnvironment(TexStyle.Display, font, font)
let char = environment.MathFont.GetDefaultCharInfo('x', TexStyle.Display).Value
Expand All @@ -29,7 +29,7 @@ type CharBoxTests() =
Mock.Verify(<@ mockedRenderer.RenderGlyphRun(any(), x, y, Brushes.Black) @>, once)

[<Fact>]
member __.``Currently unsupporteded characters like "Å" should result in TexCharacterMappingNotFoundException``() =
member _.``Currently unsupporteded characters like "Å" should result in TexCharacterMappingNotFoundException``() =
let font = DefaultTexFont 20.0
let environment = TexEnvironment(TexStyle.Display, font, font)
Assert.IsType<TexCharacterMappingNotFoundException>(
Expand Down
12 changes: 6 additions & 6 deletions src/WpfMath.Tests/DefaultTexFontTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ type DefaultTexFontTests() =
let font = DefaultTexFont(1.0)

[<Fact>]
member __.``GetCharInfo(char, string, TexStyle) returns a CharInfo for existing character``() =
member _.``GetCharInfo(char, string, TexStyle) returns a CharInfo for existing character``() =
Assert.NotNull <| font.GetCharInfo('x', "text", TexStyle.Text)

[<Fact>]
member __.``GetCharInfo(char, string, TexStyle) throws a TextStyleMappingNotFoundException for unknown text style``() =
member _.``GetCharInfo(char, string, TexStyle) throws a TextStyleMappingNotFoundException for unknown text style``() =
Assert.IsType<TextStyleMappingNotFoundException>(font.GetCharInfo('x', "unknownStyle", TexStyle.Text).Error)

[<Fact>]
member __.``GetCharInfo(string, TexStyle) returns a CharInfo for existing symbol``() =
member _.``GetCharInfo(string, TexStyle) returns a CharInfo for existing symbol``() =
Assert.NotNull <| font.GetCharInfo("sqrt", TexStyle.Text)

[<Fact>]
member __.``GetCharInfo(string, TexStyle) throws a SymbolMappingNotFoundException for unknown symbol``() =
member _.``GetCharInfo(string, TexStyle) throws a SymbolMappingNotFoundException for unknown symbol``() =
Assert.IsType<SymbolMappingNotFoundException>(font.GetCharInfo("unknownSymbol", TexStyle.Text).Error)

[<Fact>]
member __.``GetCharInfo(CharFont, TexStyle) returns a CharInfo for existing symbol``() =
member _.``GetCharInfo(CharFont, TexStyle) returns a CharInfo for existing symbol``() =
let char = CharFont('x', 1)
Assert.NotNull <| font.GetCharInfo(char, TexStyle.Text)

[<Fact>]
member __.``GetCharInfo(CharFont, TexStyle) throws a TexCharacterMappingNotFoundException for unknown character``() =
member _.``GetCharInfo(CharFont, TexStyle) throws a TexCharacterMappingNotFoundException for unknown character``() =
let char = CharFont('й', 1)
Assert.IsType<TexCharacterMappingNotFoundException>(font.GetCharInfo(char, TexStyle.Text).Error)
8 changes: 4 additions & 4 deletions src/WpfMath.Tests/GeometryElementRendererTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ type GeometryElementRendererTests() =
let renderer = GeometryElementRenderer(geometry, 1.0) :> IElementRenderer

[<Fact>]
member __.``GeometryElementRenderer.RenderElement delegates to element.RenderTo``() : unit =
member _.``GeometryElementRenderer.RenderElement delegates to element.RenderTo``() : unit =
let box = Mock.Of<Box>()
renderer.RenderElement(box, 1.0, 2.0)
Mock.Verify(<@ box.RenderTo(renderer, 1.0, 2.0) @>, once)

[<Fact>]
member __.``GeometryElementRenderer.RenderGlyphRun adds a PathGeometry group``() : unit =
member _.``GeometryElementRenderer.RenderGlyphRun adds a PathGeometry group``() : unit =
let font = DefaultTexFont 20.0
let environment = TexEnvironment(TexStyle.Display, font, font)
let char = environment.MathFont.GetDefaultCharInfo('x', TexStyle.Display).Value
Expand All @@ -38,13 +38,13 @@ type GeometryElementRendererTests() =
Assert.IsType<PathGeometry>(Seq.exactlyOne group.Children) |> ignore

[<Fact>]
member __.``GeometryElementRenderer.RenderRectangle adds a RectangleGeometry``() : unit =
member _.``GeometryElementRenderer.RenderRectangle adds a RectangleGeometry``() : unit =
let rect = Rect(1.0, 2.0, 3.0, 4.0)
renderer.RenderRectangle(rect, null)

Assert.IsType<RectangleGeometry>(Seq.exactlyOne geometry.Children) |> ignore

[<Fact>]
member __.``GeometryElementRenderer.RenderTransformed adds a GeometryGroup``() : unit =
member _.``GeometryElementRenderer.RenderTransformed adds a GeometryGroup``() : unit =
renderer.RenderTransformed(HorizontalBox(), [| Transformation.Translate(1.0, 1.0) |], 0.0, 0.0)
Assert.IsType<GeometryGroup>(Seq.exactlyOne geometry.Children) |> ignore
2 changes: 1 addition & 1 deletion src/WpfMath.Tests/HorizontalBoxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open WpfMath.Rendering

type HorizontalBoxTests() =
[<Fact>]
member __.``HorizontalBox rendering calls to RenderElement for each child``() =
member _.``HorizontalBox rendering calls to RenderElement for each child``() =
let x = 0.5
let y = 1.0

Expand Down
2 changes: 1 addition & 1 deletion src/WpfMath.Tests/HorizontalRuleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type HorizontalRuleTests() =
static do Utils.initializeFontResourceLoading()

[<Fact>]
member __.``HorizontalRule rendering calls to RenderRect``() =
member _.``HorizontalRule rendering calls to RenderRect``() =
let font = DefaultTexFont 20.0
let environment = TexEnvironment(TexStyle.Display, font, font)
let x = 0.5
Expand Down
4 changes: 2 additions & 2 deletions src/WpfMath.Tests/OverUnderBoxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ type OverUnderBoxTests() =
let overUnderBox = OverUnderBox(baseBox, delimiterBox, scriptBox, 1.0, true)

[<Fact>]
member __.``OverUnderBox rendering calls to RenderElement for base and script``() =
member _.``OverUnderBox rendering calls to RenderElement for base and script``() =
overUnderBox.RenderTo(mockedRenderer, x, y)
Mock.Verify(<@ mockedRenderer.RenderElement(baseBox, x, any()) @>, once)
Mock.Verify(<@ mockedRenderer.RenderTransformed(delimiterBox, any(), any(), any()) @>, once)
Mock.Verify(<@ mockedRenderer.RenderElement(scriptBox, x, any()) @>, once)

[<Fact>]
member __.``OverUnderBox rendering calls to RenderTransformed for delimiter``() =
member _.``OverUnderBox rendering calls to RenderTransformed for delimiter``() =
overUnderBox.RenderTo(mockedRenderer, x, y)
Mock.Verify(<@ mockedRenderer.RenderTransformed(delimiterBox, any(), any(), any()) @>, once)
2 changes: 1 addition & 1 deletion src/WpfMath.Tests/ParserExceptionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let ``"\frac{}" should throw a TexParseException``(): unit =
let ``Incorrect command parser behavior should be detected``(): unit =
let incorrectParser =
{ new ICommandParser with
member __.ProcessCommand _ =
member _.ProcessCommand _ =
CommandProcessingResult(SpaceAtom(null), 0) }
let parserRegistry = Map([| "dummy", incorrectParser |])
let parser = TexFormulaParser(parserRegistry, Dictionary(), PredefinedColorParser.Instance)
Expand Down
46 changes: 23 additions & 23 deletions src/WpfMath.Tests/TestResults/BoxTests.casesBox.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"Source": null,
"Foreground": null,
"Background": null,
"TotalHeight": 2.4000239999999997,
"TotalHeight": 2.400024,
"TotalWidth": 0.750002,
"Italic": 0.0,
"Width": 0.750002,
Expand Down Expand Up @@ -106,11 +106,11 @@
"Source": null,
"Foreground": null,
"Background": null,
"TotalHeight": 0.78055500000000011,
"TotalHeight": 0.780555,
"TotalWidth": 0.52859,
"Italic": 0.0,
"Width": 0.52859,
"Height": 0.78055500000000011,
"Height": 0.780555,
"Depth": 0.0,
"Shift": 0.0
},
Expand All @@ -131,11 +131,11 @@
"Source": null,
"Foreground": null,
"Background": null,
"TotalHeight": 0.78055500000000011,
"TotalWidth": 0.70358999999999994,
"TotalHeight": 0.780555,
"TotalWidth": 0.70359,
"Italic": 0.0,
"Width": 0.70358999999999994,
"Height": 0.78055500000000011,
"Width": 0.70359,
"Height": 0.780555,
"Depth": 0.0,
"Shift": 0.0
},
Expand Down Expand Up @@ -229,9 +229,9 @@
"Foreground": null,
"Background": null,
"TotalHeight": 1.044445,
"TotalWidth": 0.70358999999999994,
"TotalWidth": 0.70359,
"Italic": 0.0,
"Width": 0.70358999999999994,
"Width": 0.70359,
"Height": 1.044445,
"Depth": 0.0,
"Shift": 0.0
Expand Down Expand Up @@ -300,11 +300,11 @@
"Source": null,
"Foreground": null,
"Background": null,
"TotalHeight": 0.78055500000000011,
"TotalHeight": 0.780555,
"TotalWidth": 0.432756,
"Italic": 0.0,
"Width": 0.432756,
"Height": 0.78055500000000011,
"Height": 0.780555,
"Depth": 0.0,
"Shift": 0.0
},
Expand All @@ -325,11 +325,11 @@
"Source": null,
"Foreground": null,
"Background": null,
"TotalHeight": 0.78055500000000011,
"TotalWidth": 0.70358999999999994,
"TotalHeight": 0.780555,
"TotalWidth": 0.70359,
"Italic": 0.0,
"Width": 0.70358999999999994,
"Height": 0.78055500000000011,
"Width": 0.70359,
"Height": 0.780555,
"Depth": 0.0,
"Shift": 0.0
}
Expand All @@ -342,12 +342,12 @@
},
"Foreground": null,
"Background": null,
"TotalHeight": 2.6055550000000003,
"TotalWidth": 0.70358999999999994,
"TotalHeight": 2.605555,
"TotalWidth": 0.70359,
"Italic": 0.0,
"Width": 0.70358999999999994,
"Height": 1.5527775000000001,
"Depth": 1.0527775000000001,
"Width": 0.70359,
"Height": 1.5527775,
"Depth": 1.0527775,
"Shift": 0.0
},
{
Expand All @@ -374,11 +374,11 @@
},
"Foreground": null,
"Background": null,
"TotalHeight": 2.6055550000000003,
"TotalHeight": 2.605555,
"TotalWidth": 1.453592,
"Italic": 0.0,
"Width": 1.453592,
"Height": 1.5527775000000001,
"Depth": 1.0527775000000001,
"Height": 1.5527775,
"Depth": 1.0527775,
"Shift": 0.0
}
Loading