Skip to content

Commit

Permalink
(#63) Tests: fix everything after the resource migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Dec 31, 2022
1 parent 851b0b6 commit d261b8a
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 22 deletions.
6 changes: 6 additions & 0 deletions WpfMath.Shared/Data/WpfMathResourceMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace WpfMath.Data;

/// <summary>Marks an assembly containing the WPF-Math resource files (XML and fonts).</summary>
public static class WpfMathResourceMarker
{
}
12 changes: 12 additions & 0 deletions WpfMath.Shared/Utils/AssemblyEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.IO;
using System.Reflection;

namespace WpfMath.Utils;

internal static class AssemblyEx
{
public static Stream ReadResource(this Assembly assembly, string resourceName) =>
assembly.GetManifestResourceStream(resourceName)
?? throw new Exception($"Cannot find resource {resourceName} in assembly {assembly}.");
}
4 changes: 3 additions & 1 deletion WpfMath.Shared/Utils/TupleExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;

namespace WpfMath.Utils
{
#if NET452 // not needed for .NET Core 3.0+ because there're System.TupleExtensions
#if NET452 // not needed for .NET Core 3.0+ because there are System.TupleExtensions
internal static class TupleExtensions
{
public static void Deconstruct<T1, T2>(this Tuple<T1, T2> tuple, out T1 x1, out T2 x2)
Expand Down
7 changes: 0 additions & 7 deletions WpfMath.Shared/WpfMath.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
<EmbeddedResource Include="Data\TexSymbols.xml" />
</ItemGroup>

<ItemGroup>
<Resource Include="Fonts\cmex10.ttf" />
<Resource Include="Fonts\cmmi10.ttf" />
<Resource Include="Fonts\cmr10.ttf" />
<Resource Include="Fonts\cmsy10.ttf" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="WpfMath" />
<InternalsVisibleTo Include="WpfMath.Tests" />
Expand Down
5 changes: 3 additions & 2 deletions src/WpfMath/Colors/PredefinedColorParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Windows.Media;
using System.Xml.Linq;
using WpfMath.Data;
using WpfMath.Utils;

namespace WpfMath.Colors
{
Expand All @@ -17,7 +18,7 @@ public class PredefinedColorParser : IColorParser

private PredefinedColorParser(string resourceName)
{
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
using (var resource = typeof(WpfMathResourceMarker).Assembly.ReadResource(resourceName))
{
var doc = XDocument.Load(resource);
_colors = Parse(doc.Root);
Expand Down
6 changes: 4 additions & 2 deletions src/WpfMath/DefaultTexFontParser.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Media;
using System.Xml.Linq;
using WpfMath.Data;
using WpfMath.Utils;

namespace WpfMath
{
Expand Down Expand Up @@ -48,7 +49,8 @@ private static void SetCharChildParsers()

public DefaultTexFontParser()
{
var doc = XDocument.Load(new System.IO.StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)!));
using var resource = typeof(WpfMathResourceMarker).Assembly.ReadResource(resourceName);
var doc = XDocument.Load(resource);
this.rootElement = doc.Root;

this.parsedTextStyles = new Dictionary<string, CharFont[]>();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions src/WpfMath/GlueSettingsParser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml.Linq;
using WpfMath.Data;
using WpfMath.Utils;

namespace WpfMath
{
Expand Down Expand Up @@ -58,7 +59,8 @@ private static void SetStyleMappings()

public GlueSettingsParser()
{
var doc = XDocument.Load(new System.IO.StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)!));
using var resource = typeof(WpfMathResourceMarker).Assembly.ReadResource(resourceName);
var doc = XDocument.Load(resource);
this.rootElement = doc.Root;

this.glueTypes = new List<Glue>();
Expand Down
6 changes: 4 additions & 2 deletions src/WpfMath/PredefinedTexFormulaSettingsParser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Xml.Linq;
using WpfMath.Data;
using WpfMath.Utils;

namespace WpfMath
{
Expand Down Expand Up @@ -31,7 +32,8 @@ private static void AddToMap(IEnumerable<XElement> mapList, string[] table)

public TexPredefinedFormulaSettingsParser()
{
var doc = XDocument.Load(new System.IO.StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)!));
using var resource = typeof(WpfMathResourceMarker).Assembly.ReadResource(resourceName);
var doc = XDocument.Load(resource);
this.rootElement = doc.Root;
}

Expand Down
7 changes: 4 additions & 3 deletions src/WpfMath/TexPredefinedFormulaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Windows.Media;
using System.Xml.Linq;
using WpfMath.Data;
using WpfMath.Parsers.PredefinedFormulae;
using WpfMath.Utils;

namespace WpfMath
{
Expand Down Expand Up @@ -83,7 +83,8 @@ private static Type[] GetArgumentTypes(IEnumerable<XElement> args)

public TexPredefinedFormulaParser()
{
var doc = XDocument.Load(new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)!));
using var resource = typeof(WpfMathResourceMarker).Assembly.ReadResource(resourceName);
var doc = XDocument.Load(resource);
this.rootElement = doc.Root;
}

Expand Down
7 changes: 4 additions & 3 deletions src/WpfMath/TexSymbolParser.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml.Linq;
using WpfMath.Atoms;
using WpfMath.Data;
using WpfMath.Utils;

namespace WpfMath
{
Expand Down Expand Up @@ -38,7 +38,8 @@ private static void SetTypeMappings()
public TexSymbolParser()
{
// for 3.5
var doc = XDocument.Load(new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)!));
using var resource = typeof(WpfMathResourceMarker).Assembly.ReadResource(resourceName);
var doc = XDocument.Load(resource);
this.rootElement = doc.Root;
}

Expand Down
7 changes: 7 additions & 0 deletions src/WpfMath/WpfMath.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ Fixed:
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
</PropertyGroup>

<ItemGroup>
<Resource Include="Fonts\cmex10.ttf" />
<Resource Include="Fonts\cmmi10.ttf" />
<Resource Include="Fonts\cmr10.ttf" />
<Resource Include="Fonts\cmsy10.ttf" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
Expand Down

0 comments on commit d261b8a

Please sign in to comment.