Skip to content

Commit

Permalink
Remove generatedRegex
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Mar 4, 2024
1 parent ff22bdf commit cfd9520
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.SmartContract.Template.UnitTests.templates;
using Neo.SmartContract.Testing;
using Neo.SmartContract.Testing.TestingStandards;
using Neo.VM;
Expand Down
10 changes: 4 additions & 6 deletions tests/Neo.SmartContract.Framework.UnitTests/TestCleanup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
using System.Reflection;
using System.Text.RegularExpressions;

namespace Neo.SmartContract.Template.UnitTests.templates
namespace Neo.SmartContract.Framework.UnitTests
{
[TestClass]
public partial class TestCleanup
public class TestCleanup
{
private static readonly Regex WhiteSpaceRegex = new("\\s");
internal static readonly Dictionary<Type, NeoDebugInfo> DebugInfos = new();

/// <summary>
Expand Down Expand Up @@ -95,7 +96,7 @@ private static NeoDebugInfo CreateArtifact(string typeName, CompilationContext c
var artifact = manifest.GetArtifactsSource(typeName, nef, generateProperties: true);

string writtenArtifact = File.Exists(artifactsPath) ? File.ReadAllText(artifactsPath) : "";
if (writtenArtifact == "" || WhiteSpaceRegex().Replace(artifact, "") != WhiteSpaceRegex().Replace(writtenArtifact, ""))
if (writtenArtifact == "" || WhiteSpaceRegex.Replace(artifact, "") != WhiteSpaceRegex.Replace(writtenArtifact, ""))
{
// Uncomment to overwrite the artifact file
File.WriteAllText(artifactsPath, artifact);
Expand Down Expand Up @@ -171,8 +172,5 @@ public static void EnsureCoverage()

Assert.IsTrue(coverage.CoveredLinesPercentage >= RequiredCoverage, $"Coverage is less than {RequiredCoverage:P2}");
}

[GeneratedRegex(@"\s")]
private static partial Regex WhiteSpaceRegex();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
namespace Neo.SmartContract.Template.UnitTests.templates
{
[TestClass]
public partial class TestCleanup
public class TestCleanup
{
private static readonly Regex WhiteSpaceRegex = new("\\s");

private static NeoDebugInfo? DebugInfo_NEP17;
private static NeoDebugInfo? DebugInfo_Oracle;
private static NeoDebugInfo? DebugInfo_Ownable;
Expand Down Expand Up @@ -67,17 +69,14 @@ public void EnsureArtifactsUpToDate()
Path.Combine(artifactsPath, "neocontractowner/TestingArtifacts/OwnableTemplate.artifacts.cs"));
}

[GeneratedRegex(@"\s")]
private static partial Regex WhiteSpaceRegex();

private static (string artifact, NeoDebugInfo debugInfo) CreateArtifact<T>(CompilationContext context, string rootDebug, string artifactsPath)
{
(var nef, var manifest, var debugInfo) = context.CreateResults(rootDebug);
var debug = NeoDebugInfo.FromDebugInfoJson(debugInfo);
var artifact = manifest.GetArtifactsSource(typeof(T).Name, nef, generateProperties: true);

string writtenArtifact = File.Exists(artifactsPath) ? File.ReadAllText(artifactsPath) : "";
if (writtenArtifact == "" || WhiteSpaceRegex().Replace(artifact, "") != WhiteSpaceRegex().Replace(writtenArtifact, ""))
if (writtenArtifact == "" || WhiteSpaceRegex.Replace(artifact, "") != WhiteSpaceRegex.Replace(writtenArtifact, ""))
{
// Uncomment to overwrite the artifact file
File.WriteAllText(artifactsPath, artifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
namespace Neo.SmartContract.Testing.UnitTests.Coverage
{
[TestClass]
public partial class CoverageDataTests
public class CoverageDataTests
{
[GeneratedRegex(@"\s")]
private static partial Regex WhiteSpaceRegex();
private static readonly Regex WhiteSpaceRegex = new("\\s");

[TestMethod]
public void TestDump()
Expand All @@ -21,7 +20,7 @@ public void TestDump()

Assert.AreEqual(100_000_000, engine.Native.NEO.TotalSupply);

Assert.AreEqual(WhiteSpaceRegex().Replace(@"
Assert.AreEqual(WhiteSpaceRegex.Replace(@"
NeoToken [0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5] [5.00 % - 100.00 %]
┌-───────────────────────────────-┬-────────-┬-────────-┐
│ Method │ Line │ Branch │
Expand All @@ -47,16 +46,16 @@ NeoToken [0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5] [5.00 % - 100.00 %]
│ unregisterCandidate(pubkey) │ 0.00 % │ 100.00 % │
│ vote(account,voteTo) │ 0.00 % │ 100.00 % │
└-───────────────────────────────-┴-────────-┴-────────-┘
", ""), WhiteSpaceRegex().Replace(engine.GetCoverage(engine.Native.NEO)?.Dump(), ""));
", ""), WhiteSpaceRegex.Replace(engine.GetCoverage(engine.Native.NEO)?.Dump(), ""));

Assert.AreEqual(WhiteSpaceRegex().Replace(@"
Assert.AreEqual(WhiteSpaceRegex.Replace(@"
NeoToken [0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5] [5.00 % - 100.00 %]
┌-─────────────-┬-────────-┬-────────-┐
│ Method │ Line │ Branch │
├-─────────────-┼-────────-┼-────────-┤
│ totalSupply() │ 100.00 % │ 100.00 % │
└-─────────────-┴-────────-┴-────────-┘
", ""), WhiteSpaceRegex().Replace((engine.Native.NEO.GetCoverage(o => o.TotalSupply) as CoveredMethod)?.Dump(), ""));
", ""), WhiteSpaceRegex.Replace((engine.Native.NEO.GetCoverage(o => o.TotalSupply) as CoveredMethod)?.Dump(), ""));
}

[TestMethod]
Expand Down

0 comments on commit cfd9520

Please sign in to comment.