Skip to content

Commit

Permalink
append
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSchulze authored and Nullpointer committed Feb 29, 2024
1 parent 53dd97c commit 2aa4281
Show file tree
Hide file tree
Showing 11 changed files with 768 additions and 300 deletions.
474 changes: 474 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"ms-dotnettools.csharp",
"EditorConfig.EditorConfig",
"selcukermaya.se-csproj-extensions",
"josefpihrt-vscode.roslynator",
"streetsidesoftware.code-spell-checker",
"DavidAnson.vscode-markdownlint"
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"[csharp]": {
"editor.codeActionsOnSave": {
"source.addMissingImports": "explicit",
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": false
},
"csharp.semanticHighlighting.enabled": true,
"editor.semanticHighlighting.enabled": true,
"editor.formatOnSave": true,
"terminal.integrated.tabs.title": "${task}",
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableMsBuildLoadProjectsOnDemand": false,
"omnisharp.maxFindSymbolsItems": 3000,
"omnisharp.organizeImportsOnFormat": true,
"omnisharp.useModernNet": true,
"dotnet.unitTests.runSettingsPath": "./test/.runsettings"
}
21 changes: 16 additions & 5 deletions api/src/Assertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

namespace GdUnit4
{
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Asserts;
using Godot;

/// <summary>
/// A collection of assertions and helpers to verify values
Expand Down Expand Up @@ -115,6 +112,7 @@ public sealed class Assertions
public static INumberAssert<double> AssertThat(double current) => new NumberAssert<double>(current);
public static INumberAssert<decimal> AssertThat(decimal current) => new NumberAssert<decimal>(current);


public static IDictionaryAssert<K, V> AssertThat<K, V>(IDictionary<K, V>? current) where K : notnull
=> new DictionaryAssert<K, V>(current?.ToDictionary(e => e.Key, e => e.Value));

Expand All @@ -124,12 +122,16 @@ public sealed class Assertions
public static IDictionaryAssert<TKey, TValue> AssertThat<[Godot.MustBeVariant] TKey, [Godot.MustBeVariant] TValue>(Godot.Collections.Dictionary<TKey, TValue>? current) where TKey : notnull
=> new DictionaryAssert<TKey, TValue>(current);


/// <summary>
/// The dynamic assertions for all Godot vector types.
/// </summary>
/// <param name="current">The vector value to verify.</param>
/// <returns>An instance of IVectorAssert for further assertions.</returns>
public static IVectorAssert<Godot.Vector2> AssertThat(Godot.Vector2 current) => new VectorAssert<Godot.Vector2>(current);
public static IVectorAssert<Godot.Vector2I> AssertThat(Godot.Vector2I current) => new VectorAssert<Godot.Vector2I>(current);

public static IVectorAssert<Godot.Vector3> AssertThat(Godot.Vector3 current) => new VectorAssert<Godot.Vector3>(current);
public static IVectorAssert<Godot.Vector3I> AssertThat(Godot.Vector3I current) => new VectorAssert<Godot.Vector3I>(current);

public static IVectorAssert<Godot.Vector4> AssertThat(Godot.Vector4 current) => new VectorAssert<Godot.Vector4>(current);
public static IVectorAssert<Godot.Vector4I> AssertThat(Godot.Vector4I current) => new VectorAssert<Godot.Vector4I>(current);

Expand Down Expand Up @@ -251,5 +253,14 @@ public static dynamic AssertThat<T>(T? current)
/// Builds an extractor by given method name and optional arguments
/// </summary>
public static IValueExtractor Extr(string methodName, params object[] args) => new ValueExtractor(methodName, args);


/// <summary>
/// Provides the expected line number via compile state.
/// Is primary designed to use on internal test coverage to validate the reported error line is correct.
/// </summary>
/// <param name="lineNumber"></param>
/// <returns></returns>
internal static int ExpectedLineNumber([System.Runtime.CompilerServices.CallerLineNumber] int lineNumber = 0) => lineNumber - 1;
}
}
20 changes: 10 additions & 10 deletions api/src/IVectorAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,73 @@ public interface IVectorAssert<T> : IAssertBase<T> where T : IEquatable<T>
/// Verifies that the current value is equal to expected one.
/// </summary>
/// <param name="expected">The expencted value</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public new IVectorAssert<T> IsEqual(T expected);

/// <summary>
/// Verifies that the current value is not equal to expected one.
/// </summary>
/// <param name="expected">The expencted value</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public new IVectorAssert<T> IsNotEqual(T expected);

/// <summary>
/// Verifies that the current and expected value are approximately equal.
/// </summary>
/// <param name="expected">The expencted value</param>
/// <param name="approx">The approximade</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsEqualApprox(T expected, T approx);

/// <summary>
/// Verifies that the current value is less than the given one.
/// </summary>
/// <param name="expected">The expencted value</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsLess(T expected);

/// <summary>
/// Verifies that the current value is less than or equal the given one.
/// </summary>
/// <param name="expected">The expencted value</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsLessEqual(T expected);

/// <summary>
/// Verifies that the current value is greater than the given one.
/// </summary>
/// <param name="expected">The expencted value</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsGreater(T expected);

/// <summary>
/// Verifies that the current value is greater than or equal the given one.
/// </summary>
/// <param name="expected">The expencted value</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsGreaterEqual(T expected);

/// <summary>
/// Verifies that the current value is between the given boundaries (inclusive).
/// </summary>
/// <param name="from">The value starting from</param>
/// <param name="to">The value ending to</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsBetween(T from, T to);

/// <summary>
/// Verifies that the current value is not between the given boundaries (inclusive).
/// </summary>
/// <param name="from">The value starting from</param>
/// <param name="to">The value ending to</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsNotBetween(T from, T to);

/// <summary>
/// Overrides the default failure message by given custom message.
/// </summary>
/// <param name="message">The message to replace the default message</param>
/// <returns>IVector2Assert</returns>
/// <returns>IVectorAssert</returns>
new IVectorAssert<T> OverrideFailureMessage(string message);
}
}
137 changes: 64 additions & 73 deletions api/src/asserts/VectorAssert.cs
Original file line number Diff line number Diff line change
@@ -1,96 +1,87 @@
namespace GdUnit4.Asserts;
using System;

namespace GdUnit4.Asserts
internal class VectorAssert<T> : AssertBase<T>, IVectorAssert<T> where T : notnull, IEquatable<T>
{

class GodotVector<T> : IComparable<T>
public VectorAssert(T current) : base(current)
{
private T _value;

public GodotVector(T vector)
{
_value = vector;
}

public int CompareTo(T? other)
{
if (other is Godot.Vector2 lv2 && _value is Godot.Vector2 rv2)
return lv2 == rv2 ? 0 : lv2 < rv2 ? 1 : -1;
if (other is Godot.Vector2I lv2i && _value is Godot.Vector2I rv2i)
return lv2i == rv2i ? 0 : lv2i < rv2i ? 1 : -1;

return 0;
}
}

internal class VectorAssert<T> : AssertBase<T>, IVectorAssert<T> where T : notnull, IEquatable<T>
public IVectorAssert<T> IsBetween(T from, T to)
{
private new GodotVector<T> Current { get; set; }
if (CompareTo(Current, from) < 0 || CompareTo(Current, to) > 0)
ThrowTestFailureReport(AssertFailures.IsBetween(Current, from, to), Current, from);
return this;
}

public VectorAssert(T current) : base(current)
{
Current = new GodotVector<T>(current);
}
public new IVectorAssert<T> IsEqual(T expected) => (IVectorAssert<T>)base.IsEqual(expected);

public IVectorAssert<T> IsBetween(T from, T to)
public IVectorAssert<T> IsEqualApprox(T expected, T approx)
{
if (Current is Godot.Vector2 cur && expected is Godot.Vector2 e && approx is Godot.Vector2 a)
{
if (Current.CompareTo(from) < 0 || Current.CompareTo(to) > 0)
ThrowTestFailureReport(AssertFailures.IsBetween(base.Current, from, to), base.Current, from);
return this;
var from = e - a;
var to = e + a;
if (cur < from || cur > to)
ThrowTestFailureReport(AssertFailures.IsBetween(Current, from, to), Current, from);
}
return this;
}

public new IVectorAssert<T> IsEqual(T expected) => (IVectorAssert<T>)base.IsEqual(expected);

public IVectorAssert<T> IsEqualApprox(T expected, T approx)
{
if (base.Current is Godot.Vector2 cur && expected is Godot.Vector2 e && approx is Godot.Vector2 a)
{
Godot.Vector2 from = e - a;
Godot.Vector2 to = e + a;
if (cur < from || cur > to)
ThrowTestFailureReport(AssertFailures.IsBetween(base.Current, from, to), base.Current, from);
}
return this;
}
public IVectorAssert<T> IsGreater(T expected)
{
if (CompareTo(Current, expected) <= 0)
ThrowTestFailureReport(AssertFailures.IsGreater(Current!, expected), Current, expected);
return this;
}

public IVectorAssert<T> IsGreater(T expected)
{
if (Current.CompareTo(expected) <= 0)
ThrowTestFailureReport(AssertFailures.IsGreater(base.Current!, expected), base.Current, expected);
return this;
}
public IVectorAssert<T> IsGreaterEqual(T expected)
{
if (CompareTo(Current, expected) < 0)
ThrowTestFailureReport(AssertFailures.IsGreaterEqual(Current!, expected), Current, expected);
return this;
}

public IVectorAssert<T> IsGreaterEqual(T expected)
{
if (Current.CompareTo(expected) < 0)
ThrowTestFailureReport(AssertFailures.IsGreaterEqual(base.Current!, expected), Current, expected);
return this;
}
public IVectorAssert<T> IsLess(T expected)
{
if (CompareTo(Current, expected) >= 0)
ThrowTestFailureReport(AssertFailures.IsLess(Current!, expected), Current, expected);
return this;
}

public IVectorAssert<T> IsLess(T expected)
{
if (Current.CompareTo(expected) >= 0)
ThrowTestFailureReport(AssertFailures.IsLess(base.Current!, expected), base.Current, expected);
return this;
}
public IVectorAssert<T> IsLessEqual(T expected)
{
if (CompareTo(Current, expected) > 0)
ThrowTestFailureReport(AssertFailures.IsLessEqual(Current!, expected), Current, expected);
return this;
}

public IVectorAssert<T> IsLessEqual(T expected)
{
if (Current.CompareTo(expected) > 0)
ThrowTestFailureReport(AssertFailures.IsLessEqual(base.Current!, expected), base.Current, expected);
return this;
}
public IVectorAssert<T> IsNotBetween(T from, T to)
{
if (CompareTo(Current, from) >= 0 && CompareTo(Current, to) <= 0)
ThrowTestFailureReport(AssertFailures.IsNotBetween(Current, from, to), Current, from);
return this;
}

public IVectorAssert<T> IsNotBetween(T from, T to)
{
if (Current.CompareTo(from) >= 0 && Current.CompareTo(to) <= 0)
ThrowTestFailureReport(AssertFailures.IsNotBetween(base.Current, from, to), base.Current, from);
return this;
}

public new IVectorAssert<T> IsNotEqual(T expected) => (IVectorAssert<T>)base.IsNotEqual(expected);
public new IVectorAssert<T> IsNotEqual(T expected) => (IVectorAssert<T>)base.IsNotEqual(expected);

public new IVectorAssert<T> OverrideFailureMessage(string message) => (IVectorAssert<T>)base.OverrideFailureMessage(message);
public new IVectorAssert<T> OverrideFailureMessage(string message) => (IVectorAssert<T>)base.OverrideFailureMessage(message);

private static int CompareTo(T? left, T right)
{
if (left == null)
return -1;
return (left, right) switch
{
(Godot.Vector2 l, Godot.Vector2 r) => l == r ? 0 : l > r ? 1 : -1,
(Godot.Vector2I l, Godot.Vector2I r) => l == r ? 0 : l > r ? 1 : -1,
(Godot.Vector3 l, Godot.Vector3 r) => l == r ? 0 : l > r ? 1 : -1,
(Godot.Vector3I l, Godot.Vector3I r) => l == r ? 0 : l > r ? 1 : -1,
(Godot.Vector4 l, Godot.Vector4 r) => l == r ? 0 : l > r ? 1 : -1,
(Godot.Vector4I l, Godot.Vector4I r) => l == r ? 0 : l > r ? 1 : -1,
_ => 0
};
}
}
9 changes: 8 additions & 1 deletion api/src/core/execution/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Reflection;
using System.Linq;
using System;
using System.Threading;
using System.Globalization;

namespace GdUnit4.Executions
{
Expand Down Expand Up @@ -61,7 +63,12 @@ private IEnumerable<object> InitialParameters()
public static string BuildTestCaseName(string testName, TestCaseAttribute attribute)
{
if (attribute.Arguments.Any())
return $"{testName}.{attribute.TestName ?? testName}({attribute.Arguments.Formated()})";
{
var saveCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true);
testName = $"{testName}.{attribute.TestName ?? testName}({attribute.Arguments.Formated()})";
Thread.CurrentThread.CurrentCulture = saveCulture;
}
return testName;
}

Expand Down
Loading

0 comments on commit 2aa4281

Please sign in to comment.