Skip to content

Commit 1a8f52e

Browse files
authored
Fix/issue 232 (#242)
1 parent 72a2501 commit 1a8f52e

5 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/Domain/HydraScript.Domain.BackEnd/Impl/Instructions/WithAssignment/Simple.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ protected virtual void Assign()
7373
{
7474
"-" => -Convert.ToDouble(value),
7575
"!" => !Convert.ToBoolean(value),
76-
"~" when value is List<object> list => list.Count,
77-
"~" when value is string @string => @string.Length,
76+
"~" when value is List<object> list => Convert.ToDouble(list.Count),
77+
"~" when value is string @string => Convert.ToDouble(@string.Length),
7878
"" => value,
7979
_ => throw new NotSupportedException($"_operator {_operator} is not supported")
8080
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using HydraScript.Infrastructure;
2+
3+
namespace HydraScript.IntegrationTests.SuccessPrograms;
4+
5+
public class ArithmeticTests(TestHostFixture fixture) : IClassFixture<TestHostFixture>
6+
{
7+
/// <summary>
8+
/// https://github.com/Stepami/hydrascript/issues/232
9+
/// </summary>
10+
[Fact]
11+
public void Equality_AdditionToTheLeft_Success()
12+
{
13+
const string script =
14+
"""
15+
let i = 0
16+
const s = "abcdef"
17+
const sLen = ~s
18+
while (i < sLen) {
19+
if (i + 1 == sLen)
20+
>>> "i is 5"
21+
i = i + 1
22+
}
23+
""";
24+
using var runner = fixture.GetRunner(
25+
new TestHostFixture.Options(
26+
InMemoryScript: script));
27+
var code = runner.Invoke();
28+
code.Should().Be(Executor.ExitCodes.Success);
29+
fixture.LogMessages.Should()
30+
.Contain(log => log.Contains("i is 5"));
31+
}
32+
}

tests/HydraScript.IntegrationTests/DumpOptionTests.cs renamed to tests/HydraScript.IntegrationTests/SuccessPrograms/DumpOptionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.Extensions.DependencyInjection;
44
using NSubstitute;
55

6-
namespace HydraScript.IntegrationTests;
6+
namespace HydraScript.IntegrationTests.SuccessPrograms;
77

88
public class DumpOptionTests(TestHostFixture fixture) : IClassFixture<TestHostFixture>
99
{

tests/HydraScript.IntegrationTests/InputTests.cs renamed to tests/HydraScript.IntegrationTests/SuccessPrograms/InputTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.Extensions.DependencyInjection.Extensions;
44
using NSubstitute;
55

6-
namespace HydraScript.IntegrationTests;
6+
namespace HydraScript.IntegrationTests.SuccessPrograms;
77

88
public class InputTests(TestHostFixture fixture) : IClassFixture<TestHostFixture>
99
{

tests/HydraScript.IntegrationTests/SuccessfulProgramsTests.cs renamed to tests/HydraScript.IntegrationTests/SuccessPrograms/SuccessfulProgramsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using HydraScript.Infrastructure;
22

3-
namespace HydraScript.IntegrationTests;
3+
namespace HydraScript.IntegrationTests.SuccessPrograms;
44

55
public class SuccessfulProgramsTests(TestHostFixture fixture) : IClassFixture<TestHostFixture>
66
{

0 commit comments

Comments
 (0)