Skip to content

Commit 9fedf22

Browse files
committed
Тест конверсии к строке кастомного представления
1 parent 638d83c commit 9fedf22

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

src/OneScript.Core/Types/BasicTypes.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ This Source Code Form is subject to the terms of the
55
at http://mozilla.org/MPL/2.0/.
66
----------------------------------------------------------*/
77

8-
using System;
98
using OneScript.Values;
109

1110
namespace OneScript.Types

src/OneScript.Core/Values/BslObjectValue.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ This Source Code Form is subject to the terms of the
66
----------------------------------------------------------*/
77

88
using OneScript.Exceptions;
9-
using OneScript.Execution;
109
using OneScript.Localization;
1110

1211
namespace OneScript.Values
@@ -20,11 +19,6 @@ public override int CompareTo(BslValue other)
2019

2120
throw new RuntimeException(msg);
2221
}
23-
24-
public virtual string ConvertToString(IBslProcess process)
25-
{
26-
return ConvertToString();
27-
}
2822

2923
public override bool Equals(BslValue other)
3024
{

src/OneScript.Core/Values/BslValue.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This Source Code Form is subject to the terms of the
88
using System;
99
using System.Dynamic;
1010
using OneScript.Exceptions;
11+
using OneScript.Execution;
1112
using OneScript.Types;
1213
using ScriptEngine.Machine;
1314

@@ -16,6 +17,11 @@ namespace OneScript.Values
1617
public abstract class BslValue : DynamicObject, IComparable<BslValue>, IEquatable<BslValue>, IValue
1718
{
1819
protected virtual string ConvertToString() => ToString();
20+
21+
public virtual string ConvertToString(IBslProcess process)
22+
{
23+
return ConvertToString();
24+
}
1925

2026
public abstract int CompareTo(BslValue other);
2127

src/ScriptEngine/Machine/MachineInstance.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ private void Add(int arg)
735735
{
736736
var op2 = _operationStack.Pop();
737737
var op1 = _operationStack.Pop();
738-
_operationStack.Push(ValueFactory.Add(op1.GetRawValue(), op2.GetRawValue()));
738+
_operationStack.Push(ValueFactory.Add(op1.GetRawValue(), op2.GetRawValue(), _process));
739739
NextInstruction();
740740
}
741741

@@ -1487,8 +1487,8 @@ private void Number(int arg)
14871487

14881488
private void Str(int arg)
14891489
{
1490-
string value = _operationStack.Pop().AsString();
1491-
_operationStack.Push(ValueFactory.Create(value));
1490+
var value = (BslValue)_operationStack.Pop().GetRawValue();
1491+
_operationStack.Push(ValueFactory.Create(value.ConvertToString(_process)));
14921492
NextInstruction();
14931493
}
14941494

src/ScriptEngine/Machine/ValueFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This Source Code Form is subject to the terms of the
88
using System.Diagnostics;
99
using OneScript.Contexts;
1010
using OneScript.Exceptions;
11+
using OneScript.Execution;
1112
using OneScript.Types;
1213
using OneScript.Values;
1314

@@ -89,14 +90,14 @@ public static IValue Parse(string presentation, DataType type)
8990
return result;
9091
}
9192

92-
public static IValue Add(IValue op1, IValue op2)
93+
public static IValue Add(IValue op1, IValue op2, IBslProcess process)
9394
{
9495
// принимаем только RawValue
9596
Debug.Assert(!(op1 is IVariable || op2 is IVariable));
9697

9798
if (op1 is BslStringValue s)
9899
{
99-
return Create(s + op2.AsString());
100+
return Create(s + ((BslValue)op2).ConvertToString(process));
100101
}
101102

102103
if (op1 is BslDateValue date)

tests/constructor.os

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
НовыйОбъект = Новый Проверка(1, 2, 3);
8787
НовыйОбъект.ПроизвольноеПредставление = "Я специальный объект";
8888
Ожидаем.Что(Строка(НовыйОбъект)).Равно("Я специальный объект");
89+
Ожидаем.Что("> " + НовыйОбъект).Равно("> Я специальный объект");
8990

9091
КонецПроцедуры
9192

0 commit comments

Comments
 (0)