Firstborn/Library/PackageCache/com.unity.burst@1.8.4/Tests/Runtime/Shared/032-Patterns.cs
Schaken-Mods 9092858a58 updated to the latest editor
I updated everything to the latest Unity Editor. Also realized I had the wrong shaders on my hairs, those are fixed and the hairs look MUCH better!
2023-05-07 17:43:11 -05:00

66 lines
1.6 KiB
C#

namespace Burst.Compiler.IL.Tests.Shared
{
public class Patterns
{
[TestCompiler(2)]
[TestCompiler(1)]
[TestCompiler(0)]
public static int PropertyPattern(int x)
{
var point = new Point { X = x, Y = 5 };
return point switch
{
{ X: 2 } => 10,
{ X: 1 } => 5,
_ => 0
};
}
private struct Point
{
public int X;
public int Y;
}
[TestCompiler(1, 2)]
[TestCompiler(2, 4)]
[TestCompiler(0, 0)]
public static int TuplePattern(int x, int y)
{
return (x, y) switch
{
(1, 2) => 10,
(2, 4) => 5,
_ => 0
};
}
private struct DeconstructablePoint
{
public int X;
public int Y;
public void Deconstruct(out int x, out int y) => (x, y) = (X, Y);
}
[TestCompiler(1, -1)]
[TestCompiler(-1, 1)]
[TestCompiler(1, 1)]
[TestCompiler(-1, -1)]
public static int PositionalPattern(int pointX, int pointY)
{
var point = new DeconstructablePoint { X = pointX, Y = pointY };
return point switch
{
(0, 0) => 0,
var (x, y) when x > 0 && y > 0 => 1,
var (x, y) when x < 0 && y > 0 => 2,
var (x, y) when x < 0 && y < 0 => 3,
var (x, y) when x > 0 && y < 0 => 4,
var (_, _) => 5
};
}
}
}