fix: Adds ISpanParsable and fixes command conditionals (#1241)

* Adds `ISpanParsable<T>`
* Removes `[Parsable]`
* Fixes querying by serial, body, and a few others.
* Adds `Parse` to `Rectangle3D`
* Fixes AutoArchive NPE


Closes #1209
This commit is contained in:
Kamron Batman 2022-11-12 00:26:02 -08:00 • committed by GitHub
parent d494a9c78c
commit 03fb36c869
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 1119 additions and 271 deletions

View file

@ -69,4 +69,64 @@ public class Rectangle2DTests
Assert.False(p4.TryFormat(array, out var cp4, null, null));
Assert.Equal(0, cp4);
}
[Fact]
public void TestRectangle2DTryParse()
{
// Happy Path
Assert.True(Rectangle2D.TryParse("(101, 23)+(55, 89)", null, out var p));
Assert.Equal(new Rectangle2D(new Point2D(101, 23), new Point2D(55, 89)), p);
Assert.Equal(new Rectangle2D(new Point2D(101, 23), new Point2D(55, 89)), Rectangle2D.Parse("(101, 23)+(55, 89)", null));
// Trimming
Assert.True(Rectangle2D.TryParse(" (101,23)+ (55, 89) ", null, out p));
Assert.Equal(new Rectangle2D(new Point2D(101, 23), new Point2D(55, 89)), p);
Assert.Equal(new Rectangle2D(new Point2D(101, 23), new Point2D(55, 89)), Rectangle2D.Parse(" (101,23)+ (55, 89) ", null));
// No parenthesis
Assert.False(Rectangle2D.TryParse("101, 23)+( 55, 89)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("101, 23)+( 55, 89)", null));
Assert.False(Rectangle2D.TryParse("(101, 23)+(55, 89", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(101, 23)+(55, 89", null));
// No numbers
Assert.False(Rectangle2D.TryParse("()", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("()", null));
Assert.False(Rectangle2D.TryParse("(,)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(,)", null));
Assert.False(Rectangle2D.TryParse("(|)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(|)", null));
Assert.False(Rectangle2D.TryParse("(101)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(101)", null));
Assert.False(Rectangle2D.TryParse("(101,)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(101,)", null));
Assert.False(Rectangle2D.TryParse("(,23)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(,23)", null));
Assert.False(Rectangle2D.TryParse("(,23)+(,55)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(,23)+(,55)", null));
Assert.False(Rectangle2D.TryParse("(,23,)+(,89)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(,23,)+(,89)", null));
Assert.False(Rectangle2D.TryParse("(,,)+(55,89)", null, out p));
Assert.Equal(default, p);
Assert.Throws<FormatException>(() => Rectangle2D.Parse("(,,)+(55,89)", null));
}
}