Skip to content

Commit

Permalink
#56 - тесты
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepami committed Feb 2, 2025
1 parent f604a1b commit e4cfd8a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion samples/linkedlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function append(lst: list, item: number) {

function getOdd(lst: list): number[] {
let result: number[]
let n = lst.head
let n: node = lst.head
while (n != null) {
if (n.data % 2 != 0) {
let i = n.data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.CommandLine.Parsing;

namespace HydraScript.IntegrationTests.ErrorPrograms;

public class NullAssignmentWhenUndefinedTests(TestHostFixture fixture) : IClassFixture<TestHostFixture>
{
[Theory, MemberData(nameof(NullAssignmentScripts))]
public void NullAssignment_UndefinedDestinationOrReturnType_HydraScriptError(string script)
{
var runner = fixture.GetRunner(
configureTestServices: services =>
services.SetupInMemoryScript(script));
var code = runner.Invoke(fixture.InMemoryScript);
code.Should().Be(ExitCodes.HydraScriptError);
fixture.LogMessages.Should()
.Contain(x => x.Contains("Cannot assign 'null' when type is undefined"));
}

public static TheoryData<string> NullAssignmentScripts
{
get
{
const string lexicalDeclaration = "let x = null";
const string objectLiteralProperty = "let y = {prop: null;}";
const string functionReturn = "function f() { return null }";
return new TheoryData<string>([
lexicalDeclaration,
objectLiteralProperty,
functionReturn]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace HydraScript.IntegrationTests.ErrorPrograms;
public class VariableInitializationTests(TestHostFixture fixture) : IClassFixture<TestHostFixture>
{
[Theory, MemberData(nameof(VariableInitializationScripts))]
public void VariableWithoutTypeDeclared_AccessedBeforeInitialization_ExitCodeHydraScriptError(string script)
public void VariableWithoutTypeDeclared_AccessedBeforeInitialization_HydraScriptError(string script)
{
var runner = fixture.GetRunner(
configureTestServices: services =>
Expand Down Expand Up @@ -36,7 +36,9 @@ function f() {
return 5
}
""";
return new TheoryData<string>([variableWithoutTypeDeclared, typedVariableDeclared]);
return new TheoryData<string>([
variableWithoutTypeDeclared,
typedVariableDeclared]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace HydraScript.IntegrationTests.ErrorPrograms;
public class VoidAssignmentTests(TestHostFixture fixture) : IClassFixture<TestHostFixture>
{
[Fact]
public void FunctionDeclared_VoidReturnAssigned_ExitCodeHydraScriptError()
public void FunctionDeclared_VoidReturnAssigned_HydraScriptError()
{
const string script =
"""
Expand Down

0 comments on commit e4cfd8a

Please sign in to comment.