Skip to content

Commit

Permalink
(#63) Tests: fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jan 10, 2023
1 parent bcf683c commit 79f45ed
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/WpfMath.Tests/ApprovalTestUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ open Newtonsoft.Json
open Newtonsoft.Json.Converters
open Newtonsoft.Json.Serialization

open WpfMath
open WpfMath.Atoms
open WpfMath.Fonts
open WpfMath.Parsers
open WpfMath.Rendering

type private BomlessFileWriter(data: string, ?extensionWithoutDot: string) =
Expand Down Expand Up @@ -119,7 +119,7 @@ let verifyObject: obj -> unit =
serialize >> Approvals.Verify

let verifyParseResult (formulaText: string): unit =
let parser = TexFormulaParser()
let parser = WpfTeXFormulaParser.Instance
let formula = parser.Parse formulaText
verifyObject formula

Expand Down
7 changes: 4 additions & 3 deletions src/WpfMath.Tests/BoxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module WpfMath.Tests.BoxTests
open System

open FSharp.Core.Fluent
open WpfMath.Parsers
open Xunit

open WpfMath
Expand All @@ -12,7 +13,7 @@ open WpfMath.Rendering
open WpfMath.Tests.ApprovalTestUtils

let private parse(text: string) =
let parser = TexFormulaParser()
let parser = WpfTeXFormulaParser.Instance
let result = parser.Parse text
result.RootAtom

Expand Down Expand Up @@ -52,7 +53,7 @@ let ``ScriptsAtom should set Shift on the created box when creating box without
let ``RowAtom creates boxes with proper sources``() =
let source = "2+2"
let src = src source
let parser = TexFormulaParser()
let parser = WpfTeXFormulaParser.Instance
let formula = parser.Parse source
let box = formula.CreateBox environment :?> HorizontalBox
let chars = box.Children.filter (fun x -> x :? CharBox)
Expand All @@ -66,7 +67,7 @@ let ``RowAtom creates boxes with proper sources``() =
let ``BigOperatorAtom creates a box with proper sources``() =
let source = @"\int_a^b"
let src = src source
let parser = TexFormulaParser()
let parser = WpfTeXFormulaParser.Instance
let formula = parser.Parse source
let box = formula.CreateBox environment :?> VerticalBox

Expand Down
5 changes: 3 additions & 2 deletions src/WpfMath.Tests/CharBoxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ open Xunit

open WpfMath
open WpfMath.Boxes
open WpfMath.Exceptions
open WpfMath.Fonts
open WpfMath.Parsers
open WpfMath.Rendering
open WpfMath.Exceptions

type CharBoxTests() =
static do Utils.initializeFontResourceLoading()

let parse(text: string) =
let parser = TexFormulaParser()
let parser = WpfTeXFormulaParser.Instance
let result = parser.Parse text
result.RootAtom

Expand Down
9 changes: 8 additions & 1 deletion src/WpfMath.Tests/ParserExceptionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ open WpfMath.Atoms
open WpfMath.Colors
open WpfMath.Exceptions
open WpfMath.Parsers
open WpfMath.Rendering
open WpfMath.Tests.Utils

[<Fact>]
Expand Down Expand Up @@ -69,7 +70,13 @@ let ``Incorrect command parser behavior should be detected``(): unit =
member _.ProcessCommand _ =
CommandProcessingResult(SpaceAtom(null), 0) }
let parserRegistry = Map([| "dummy", incorrectParser |])
let parser = TexFormulaParser(parserRegistry, Dictionary(), PredefinedColorParser.Instance)
let parser = TexFormulaParser(
parserRegistry,
Dictionary(),
PredefinedColorParser.Instance,
WpfBrushFactory.Instance,
Dictionary()
)
let ex = Assert.Throws<TexParseException>(Action(fun () -> ignore <| parser.Parse("\dummy")))
Assert.Contains("NextPosition = 0", ex.Message)

Expand Down
3 changes: 1 addition & 2 deletions src/WpfMath.Tests/PredefinedColorParserTests.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module WpfMath.Tests.PredefinedColorParserTests

open System.Windows.Media

open Xunit

Expand All @@ -10,7 +9,7 @@ let parser = PredefinedColorParser.Instance

[<Fact>]
let ``PredefinedColorParser parses a correctly defined color``(): unit =
Assert.Equal(Color.FromRgb(237uy, 27uy, 35uy), parser.Parse([| "red" |]).Value)
Assert.Equal(RgbaColor.FromRgb(237uy, 27uy, 35uy), parser.Parse([| "red" |]).Value)

[<Fact>]
let ``PredefinedColorParser returns null for wrong input``(): unit =
Expand Down
7 changes: 3 additions & 4 deletions src/WpfMath.Tests/RenderingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ module WpfMath.Tests.RenderingTests

open Xunit

open WpfMath
open WpfMath.Parsers
open WpfMath.Rendering

let private parser = WpfTeXFormulaParser.Instance

[<Fact>]
let ``TexRenderer.RenderToBitmap should create an image of proper size``() =
let parser = TexFormulaParser()
let formula = parser.Parse "2+2=2"
let environment = WpfTeXEnvironment.Create()
let bitmap = formula.RenderToBitmap environment
Expand All @@ -16,7 +17,6 @@ let ``TexRenderer.RenderToBitmap should create an image of proper size``() =

[<Fact>]
let ``TexRenderer.RenderToBitmap should create an image of proper size with offset``() =
let parser = TexFormulaParser()
let formula = parser.Parse "2+2=2"
let environment = WpfTeXEnvironment.Create()
let margin = 50
Expand All @@ -29,7 +29,6 @@ let ``TexRenderer.RenderToBitmap should create an image of proper size with offs

[<Fact>]
let ``TexRenderer.RenderToBitmap should work with different DPI``() =
let parser = TexFormulaParser()
let formula = parser.Parse "2+2=2"
let environment = WpfTeXEnvironment.Create()
let bitmap = formula.RenderToBitmap(environment, dpi = 192.0)
Expand Down
4 changes: 2 additions & 2 deletions src/WpfMath.Tests/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module WpfMath.Tests.Utils
open System
open System.Windows

open WpfMath.Parsers
open Xunit

open WpfMath

let initializeFontResourceLoading =
let monitor = obj()
Expand All @@ -15,5 +15,5 @@ let initializeFontResourceLoading =
then new Application() |> ignore)

let assertParseThrows<'ex when 'ex :> exn>(formula: string): 'ex =
let parser = TexFormulaParser()
let parser = WpfTeXFormulaParser.Instance
Assert.Throws<'ex>(Func<obj>(fun () -> upcast parser.Parse formula))

0 comments on commit 79f45ed

Please sign in to comment.