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

Add tests for DefaultTexFont, fix errors #133

Merged
merged 1 commit into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/WpfMath.Tests/DefaultTexFontTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace WpfMath.Tests

open Xunit

open WpfMath
open WpfMath.Exceptions

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

let font = DefaultTexFont(1.0)

[<Fact>]
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``() =
Assert.Throws<TextStyleMappingNotFoundException>(
fun () -> ignore <| font.GetCharInfo('x', "unknownStyle", TexStyle.Text))

[<Fact>]
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``() =
Assert.Throws<SymbolMappingNotFoundException>(
fun () -> ignore <| font.GetCharInfo("unknownSymbol", TexStyle.Text))

[<Fact>]
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``() =
let char = CharFont('й', 1)
Assert.Throws<TexCharacterMappingNotFoundException>(
fun () -> ignore <| font.GetCharInfo(char, TexStyle.Text))
1 change: 1 addition & 0 deletions src/WpfMath.Tests/WpfMath.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="Utils.fs" />
<Compile Include="BoxTests.fs" />
<Compile Include="CharBoxTests.fs" />
<Compile Include="DefaultTexFontTests.fs" />
<Compile Include="GeometryHelperTests.fs" />
<Compile Include="GeometryElementRendererTests.fs" />
<Compile Include="HorizontalBoxTests.fs" />
Expand Down
24 changes: 9 additions & 15 deletions src/WpfMath/DefaultTexFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,15 @@ private CharInfo GetCharInfo(char character, CharFont[] charFont, TexStyle style
charFont[(int)charKind].FontId), style);
}

public CharInfo GetCharInfo(char character, string textStyle, TexStyle style)
{
var mapping = textStyleMappings[textStyle];
if (mapping == null)
throw new TextStyleMappingNotFoundException(textStyle);
return GetCharInfo(character, (CharFont[])mapping, style);
}

public CharInfo GetCharInfo(string symbolName, TexStyle style)
{
var mapping = symbolMappings[symbolName];
if (mapping == null)
throw new SymbolMappingNotFoundException(symbolName);
return GetCharInfo((CharFont)mapping, style);
}
public CharInfo GetCharInfo(char character, string textStyle, TexStyle style) =>
textStyleMappings.TryGetValue(textStyle, out var mapping)
? this.GetCharInfo(character, mapping, style)
: throw new TextStyleMappingNotFoundException(textStyle);

public CharInfo GetCharInfo(string symbolName, TexStyle style) =>
symbolMappings.TryGetValue(symbolName, out var mapping)
? this.GetCharInfo(mapping, style)
: throw new SymbolMappingNotFoundException(symbolName);

public CharInfo GetCharInfo(CharFont charFont, TexStyle style)
{
Expand Down