Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Invoke_NoError_ReturnCodeIsZero(string relativePathToFile)
runner.Invoke().Should().Be(Executor.ExitCodes.Success);
}

public class SuccessfulPrograms : TheoryData<string>
public sealed class SuccessfulPrograms : TheoryData<string>
{
public SuccessfulPrograms()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FunctionWithUndefinedReturnStorageTests
private const string FunctionName = nameof(FunctionName);

[Fact]
public void StorageIsEmptyAfterFlushTest()
public void Flush_AfterSave_ReturnsSavedDeclarationAndClearsStorage()
{
IFunctionWithUndefinedReturnStorage storage = new FunctionWithUndefinedReturnStorage();

Expand All @@ -38,7 +38,7 @@ public void StorageIsEmptyAfterFlushTest()
}

[Fact]
public void StorageIsCorrectOrderTest()
public void Flush_MultipleSavedDeclarations_ReturnsInSaveOrder()
{
FunctionDeclaration[] declarations = [
new(
Expand Down Expand Up @@ -101,4 +101,4 @@ public void StorageIsCorrectOrderTest()

Assert.Equal([declarations[0], declarations[2], declarations[3]], storage.Flush());
}
}
}
4 changes: 2 additions & 2 deletions tests/HydraScript.UnitTests/Application/SymbolTableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace HydraScript.UnitTests.Application;
public class SymbolTableTests
{
[Theory, AutoHydraScriptData]
public void FindSymbolTest(ISymbol symbol)
public void FindSymbol_OpenScopeContainsSymbol_ReturnsSymbol(ISymbol symbol)
{
var id = symbol.Id;

Expand All @@ -18,4 +18,4 @@ public void FindSymbolTest(ISymbol symbol)
Assert.NotNull(innerScope.FindSymbol(id));
Assert.True(outerScope.ContainsSymbol(id));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Resolve_Issue231_Success()
// Arrange
const string itemTypeName = "QueryStringParseResultItem";
const string resultTypeName = "QueryStringParseResult";

var scope = new Scope();
var symbolTable = new SymbolTable();
symbolTable.AddSymbol(new TypeSymbol(itemTypeName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace HydraScript.UnitTests.Domain.BackEnd;
public class AddressedInstructionsTests
{
[Fact]
public void EnumerationPreservedAfterRemovalTest()
public void Remove_MiddleInstruction_PreservesEnumeration()
{
AddressedInstructions instructions =
[
Expand All @@ -28,7 +28,7 @@ public void EnumerationPreservedAfterRemovalTest()
}

[Fact]
public void RemovalOfLastDoesNotThrowTest()
public void Remove_LastInstruction_DoesNotThrow()
{
AddressedInstructions instructions =
[
Expand All @@ -41,7 +41,7 @@ public void RemovalOfLastDoesNotThrowTest()
}

[Fact]
public void ReplacementPreservesOrderTest()
public void Replace_MiddleInstruction_PreservesOrder()
{
var instructions = new AddressedInstructions
{
Expand All @@ -67,4 +67,4 @@ public void ReplacementPreservesOrderTest()
Assert.Same(@new, instructions[prev.Address.Next!]);
Assert.Same(next, instructions[@new.Address.Next!]);
}
}
}
4 changes: 2 additions & 2 deletions tests/HydraScript.UnitTests/Domain/BackEnd/CallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace HydraScript.UnitTests.Domain.BackEnd;
public class CallTests
{
[Fact]
public void ToStringCorrect()
public void ToString_Always_Success()
{
var call = new Call(
new Label("9"),
new FunctionInfo("func"));
const string expected = "9:\n\t: => Start_func:\n\t: func";
Assert.Equal(expected, call.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace HydraScript.UnitTests.Domain.BackEnd;
public class HashAddressTests
{
[Fact]
public void EqualsReturnsFalseForTwoDifferentObjectsWithSameSeed()
public void Equals_DifferentObjectsWithSameSeed_ReturnsFalse()
{
const int seed = 1;

Expand All @@ -16,19 +16,19 @@ public void EqualsReturnsFalseForTwoDifferentObjectsWithSameSeed()
}

[Fact]
public void EqualsReturnsTrueForTwoSameObjectsWithSameSeed()
public void Equals_SameObjectWithSameSeed_ReturnsTrue()
{
var address = new HashAddress(1);

Assert.Equal(address, address);
}

[Fact]
public void EqualsReturnsFalseForTwoObjectsWithDifferentSeed()
public void Equals_ObjectsWithDifferentSeed_ReturnsFalse()
{
var addressOne = new HashAddress(0);
var addressTwo = new HashAddress(1);

Assert.NotEqual(addressOne, addressTwo);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace HydraScript.UnitTests.Domain.BackEnd;

public class InstructionsData : TheoryData<IExecutableInstruction, string>
public sealed class InstructionsData : TheoryData<IExecutableInstruction, string>
{
public InstructionsData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace HydraScript.UnitTests.Domain.BackEnd;

public class TestVirtualMachine(IConsole console, IFrameContext frameContext) :
public sealed class TestVirtualMachine(IConsole console, IFrameContext frameContext) :
VirtualMachine(console, frameContext)
{
private readonly IFrameContext _frameContext = frameContext;
Expand Down
18 changes: 9 additions & 9 deletions tests/HydraScript.UnitTests/Domain/BackEnd/ValuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@ namespace HydraScript.UnitTests.Domain.BackEnd;
public class ValuesTests
{
[Fact]
public void ConstantNotEqualToNameTest()
public void Equals_ConstantComparedWithName_ReturnsFalse()
{
var name = new Name("a", Substitute.For<IFrame>());
var constant = new Constant("a");

Assert.False(name.Equals(constant));
Assert.False(constant.Equals(name));
}

[Fact]
public void ValueToStringCorrectTest()
public void ToString_NameAndConstant_Success()
{
var name = new Name("bbb", Substitute.For<IFrame>());
var constant = new Constant(1, "1.0");

Assert.Equal("bbb", name.ToString());
Assert.Equal("1.0", constant.ToString());
}

[Fact]
public void NameEqualsCorrectTest()
public void Equals_NamesWithSameId_ReturnsTrue()
{
var name1 = new Name("name", Substitute.For<IFrame>());
var name2 = new Name("name", Substitute.For<IFrame>());

Assert.True(name1.Equals(name2));
}

[Fact]
public void ConstantEqualsCorrectTest()
public void Equals_ConstantsWithSameValue_ReturnsTrue()
{
var constant1 = new Constant(1);
var constant2 = new Constant(1, "1.0");

Assert.True(constant1.Equals(constant2));
}
}
20 changes: 9 additions & 11 deletions tests/HydraScript.UnitTests/Domain/BackEnd/VirtualMachineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace HydraScript.UnitTests.Domain.BackEnd;
public class VirtualMachineTests
{
[Theory, AutoHydraScriptData]
public void CorrectPrintToOutTest([Frozen] IConsole console, TestVirtualMachine vm)
public void Execute_OutputInstruction_WritesValueToConsole([Frozen] IConsole console, TestVirtualMachine vm)
{
var print = new Output(new Constant(223))
{
Expand All @@ -32,7 +32,7 @@ public void Run_EmptyProgram_Success(TestVirtualMachine vm)
}

[Theory, AutoHydraScriptData]
public void VirtualMachineFramesClearedAfterExecutionTest(TestVirtualMachine vm)
public void Run_AfterProgramExecution_ClearsFrames(TestVirtualMachine vm)
{
AddressedInstructions program =
[
Expand All @@ -49,7 +49,7 @@ public void VirtualMachineFramesClearedAfterExecutionTest(TestVirtualMachine vm)
}

[Theory, AutoHydraScriptData]
public void VirtualMachineHandlesRecursionTest(TestVirtualMachine vm)
public void Run_RecursiveProgram_ComputesExpectedResult(TestVirtualMachine vm)
{
var halt = HaltTrackable();
var factorial = new FunctionInfo("fact");
Expand Down Expand Up @@ -82,14 +82,13 @@ public void VirtualMachineHandlesRecursionTest(TestVirtualMachine vm)
Assert.Empty(vm.ExecuteParams.CallStack);
Assert.Empty(vm.ExecuteParams.Arguments);
halt.Received(1).Execute(
Arg.Is<IExecuteParams>(
vmParam =>
Convert.ToInt32(vmParam.FrameContext.Current["fa6"]) == 720));
Arg.Is<IExecuteParams>(vmParam =>
Convert.ToInt32(vmParam.FrameContext.Current["fa6"]) == 720));
vm.ExecuteParams.FrameContext.StepOut();
}

[Theory, AutoHydraScriptData]
public void CreateArrayReservesCertainSpaceTest(TestVirtualMachine vm)
public void Execute_CreateArrayInstruction_ReservesRequestedSpace(TestVirtualMachine vm)
{
vm.ExecuteParams.FrameContext.StepIn();

Expand All @@ -116,7 +115,7 @@ public void CreateArrayReservesCertainSpaceTest(TestVirtualMachine vm)
}

[Theory, AutoHydraScriptData]
public void ObjectCreationTest(TestVirtualMachine vm)
public void Run_ObjectCreationProgram_Success(TestVirtualMachine vm)
{
var halt = HaltTrackable();
AddressedInstructions program =
Expand All @@ -128,9 +127,8 @@ public void ObjectCreationTest(TestVirtualMachine vm)

vm.Run(program);
halt.Received(1).Execute(
Arg.Is<IExecuteParams>(
vmParam =>
((Dictionary<string, object?>)vmParam.FrameContext.Current["obj"]!)["prop"] == null));
Arg.Is<IExecuteParams>(vmParam =>
((Dictionary<string, object?>)vmParam.FrameContext.Current["obj"]!)["prop"] == null));
vm.ExecuteParams.FrameContext.StepOut();
}

Expand Down
6 changes: 4 additions & 2 deletions tests/HydraScript.UnitTests/Domain/FrontEnd/LexerInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace HydraScript.UnitTests.Domain.FrontEnd;

public record LexerInput([property:MinLength(10), MaxLength(25)] TokenInput[] TokenInputs) : IReadOnlyList<string>
public sealed record LexerInput(
[property:MinLength(10), MaxLength(25)] TokenInput[] TokenInputs) :
IReadOnlyList<string>
{
public IEnumerator<string> GetEnumerator() =>
TokenInputs.Select(x => x.Value).GetEnumerator();
Expand All @@ -22,7 +24,7 @@ public override string ToString() =>
(x, y) => x + y).Value;
}

public record TokenInput(
public sealed record TokenInput(
[property: RegularExpression(TokenInput.Pattern)]
string Value) :
IAdditiveIdentity<TokenInput, TokenInput>,
Expand Down
10 changes: 5 additions & 5 deletions tests/HydraScript.UnitTests/Domain/FrontEnd/RegexLexerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public class RegexLexerTests(ITestOutputHelper output)

[Theory]
[ClassData(typeof(LexerSuccessData))]
public void LexerDoesNotThrowTest(string text) =>
public void GetTokens_ValidInput_Success(string text) =>
Assert.Null(Record.Exception(() => _regexLexer.GetTokens(text)));

[Theory]
[ClassData(typeof(LexerFailData))]
public void LexerThrowsErrorTest(string text) =>
public void GetTokens_InvalidInput_ThrowsLexerException(string text) =>
Assert.Throws<LexerException>(() => _regexLexer.GetTokens(text).ToList());

[Fact]
public void LexerToStringCorrectTest()
public void ToString_Tokens_ReturnExpectedRepresentations()
{
const string text = "8";
var tokens = _regexLexer.GetTokens(text).ToList();
Expand All @@ -33,7 +33,7 @@ public void LexerToStringCorrectTest()
}

[Fact]
public void EmptyTextTest() =>
public void GetTokens_EmptyText_ReturnsTokens() =>
Assert.NotEmpty(_regexLexer.GetTokens(""));

[Fact]
Expand Down Expand Up @@ -89,4 +89,4 @@ public void GetTokens_MockedRegex_ValidOutput(
tokens[i].Type.Should().BeOneOf(tokenTypes);
}
}
}
}
4 changes: 2 additions & 2 deletions tests/HydraScript.UnitTests/Domain/FrontEnd/StructureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace HydraScript.UnitTests.Domain.FrontEnd;
public class StructureTests
{
[Fact]
public void ToStringCorrectTest()
public void ToString_Always_ReturnsExpectedRepresentation()
{
var tokenTypes = new List<TokenType>
{
Expand Down Expand Up @@ -37,4 +37,4 @@ public void GetTokenTypes_Always_ReturnFromProvider(ITokenTypesProvider provider
var structure = new Structure<GeneratedRegexContainer>(provider);
structure.Should().BeEquivalentTo(expected);
}
}
}
Loading