Fix NRE in atmos helpers and add tests (#1775)

This commit is contained in:
DrSmugleaf
2020-08-18 13:32:18 +02:00
committed by GitHub
parent 32cf0f4c8e
commit bbc01c7e47
2 changed files with 172 additions and 8 deletions

View File

@@ -0,0 +1,160 @@
using System.Threading.Tasks;
using Content.Server.Atmos;
using NUnit.Framework;
using Robust.Shared.Map;
namespace Content.IntegrationTests.Tests.Atmos
{
[TestFixture]
[TestOf(typeof(AtmosHelpersTest))]
public class AtmosHelpersTest : ContentIntegrationTest
{
[Test]
public async Task GetTileAtmosphereGridCoordinatesNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var atmosphere = default(GridCoordinates).GetTileAtmosphere();
Assert.Null(atmosphere);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task GetTileAirGridCoordinatesNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var air = default(GridCoordinates).GetTileAir();
Assert.Null(air);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task TryGetTileAtmosphereGridCoordinatesNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var hasAtmosphere = default(GridCoordinates).TryGetTileAtmosphere(out var atmosphere);
Assert.False(hasAtmosphere);
Assert.Null(atmosphere);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task TryGetTileTileAirGridCoordinatesNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var hasAir = default(GridCoordinates).TryGetTileAir(out var air);
Assert.False(hasAir);
Assert.Null(air);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task GetTileAtmosphereMapIndicesNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var atmosphere = default(MapIndices).GetTileAtmosphere(default);
Assert.Null(atmosphere);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task GetTileAirMapIndicesNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var air = default(MapIndices).GetTileAir(default);
Assert.Null(air);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task TryGetTileAtmosphereMapIndicesNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var hasAtmosphere = default(MapIndices).TryGetTileAtmosphere(default, out var atmosphere);
Assert.False(hasAtmosphere);
Assert.Null(atmosphere);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task TryGetTileAirMapIndicesNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var hasAir = default(MapIndices).TryGetTileAir(default, out var air);
Assert.False(hasAir);
Assert.Null(air);
});
});
await server.WaitIdleAsync();
}
}
}

View File

@@ -20,14 +20,16 @@ namespace Content.Server.Atmos
return coordinates.GetTileAtmosphere()?.Air;
}
public static bool TryGetTileAtmosphere(this GridCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere atmosphere)
public static bool TryGetTileAtmosphere(this GridCoordinates coordinates, [MaybeNullWhen(false)] out TileAtmosphere atmosphere)
{
return (atmosphere = coordinates.GetTileAtmosphere()!) != default;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = coordinates.GetTileAtmosphere()!, default);
}
public static bool TryGetTileAir(this GridCoordinates coordinates, [NotNullWhen(true)] out GasMixture air)
public static bool TryGetTileAir(this GridCoordinates coordinates, [MaybeNullWhen(false)] out GasMixture air)
{
return !(air = coordinates.GetTileAir()!).Equals(default);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = coordinates.GetTileAir()!, default);
}
public static TileAtmosphere? GetTileAtmosphere(this MapIndices indices, GridId gridId)
@@ -43,14 +45,16 @@ namespace Content.Server.Atmos
}
public static bool TryGetTileAtmosphere(this MapIndices indices, GridId gridId,
[NotNullWhen(true)] out TileAtmosphere atmosphere)
[MaybeNullWhen(false)] out TileAtmosphere atmosphere)
{
return (atmosphere = indices.GetTileAtmosphere(gridId)!) != default;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId)!, default);
}
public static bool TryGetTileAir(this MapIndices indices, GridId gridId, [NotNullWhen(true)] out GasMixture air)
public static bool TryGetTileAir(this MapIndices indices, GridId gridId, [MaybeNullWhen(false)] out GasMixture air)
{
return !(air = indices.GetTileAir(gridId)!).Equals(default);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = indices.GetTileAir(gridId)!, default);
}
}
}