Skip to content

Commit 604ec35

Browse files
committed
#1327: Порядок приведения.
1 parent 1748964 commit 604ec35

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/OneScript.StandardLibrary/TypeDescriptions/TypeDescription.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,41 +114,36 @@ IValueAdjuster GetAdjusterForType(BslTypeValue type)
114114
}
115115

116116
[ContextMethod("ПривестиЗначение", "AdjustValue")]
117-
public IValue AdjustValue(IValue value = null)
117+
public IValue AdjustValue(IValue pValue = null)
118118
{
119-
119+
var value = pValue?.GetRawValue();
120120
if (_types.Count == 0)
121121
{
122122
return value ?? ValueFactory.Create();
123123
}
124124

125-
BslTypeValue typeToCast = null;
126-
127125
if (value != null && value.SystemType != BasicTypes.Undefined)
128126
{
129127
var valueType = new BslTypeValue(value.SystemType);
130128
if (_types.Contains(valueType))
131129
{
132130
// Если такой тип у нас есть
133-
typeToCast = valueType;
131+
var adjuster = GetAdjusterForType(valueType);
132+
var adjustedValue = adjuster.Adjust(value);
133+
if (adjustedValue != null)
134+
return adjustedValue;
134135
}
135136
}
136137

137-
if (typeToCast == null)
138+
foreach (var type in _types)
138139
{
139-
// Если типа нет, то нужно брать значение по-умолчанию
140-
if (_types.Count != 1)
141-
{
142-
// много типов - Неопределено
143-
return ValueFactory.Create();
144-
}
145-
146-
typeToCast = _types[0];
140+
var adjuster = GetAdjusterForType(type);
141+
var adjustedValue = adjuster?.Adjust(value);
142+
if (adjustedValue != null)
143+
return adjustedValue;
147144
}
148145

149-
var adjuster = GetAdjusterForType(typeToCast);
150-
151-
return adjuster?.Adjust(value) ?? ValueFactory.Create();
146+
return ValueFactory.Create();
152147
}
153148

154149
internal static BslTypeValue TypeNumber()

tests/typedescription.os

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
ВсеТесты.Добавить("ТестДолжен_Преобразование_ОписаниеБезТипов_КвалификаторыИгнорируются");
3737

3838
ВсеТесты.Добавить("ТестДолжен_ПроверитьОдинаковыйПорядокТипов");
39+
ВсеТесты.Добавить("ТестДолжен_ПроверитьПорядокПриведенияТипов");
3940

4041
Возврат ВсеТесты;
4142

@@ -543,6 +544,17 @@
543544

544545
КонецПроцедуры
545546

547+
Процедура ТестДолжен_ПроверитьПорядокПриведенияТипов() Экспорт
548+
549+
ОписаниеТипов = Новый ОписаниеТипов("Число, Строка", Новый КвалификаторыСтроки(1));
550+
551+
юТест.ПроверитьРавенство(ОписаниеТипов.ПривестиЗначение(Истина), "Д"); // TODO: локализация
552+
юТест.ПроверитьРавенство(ОписаниеТипов.ПривестиЗначение("Строка"), "С");
553+
юТест.ПроверитьРавенство(ОписаниеТипов.ПривестиЗначение(15), 15);
554+
юТест.ПроверитьРавенство(ОписаниеТипов.ПривестиЗначение('20230911'), "1"); // TODO: локализация
555+
556+
КонецПроцедуры
557+
546558
Процедура ТестДолжен_ПроверитьОдинаковыйПорядокТипов() Экспорт
547559

548560
ОТ = Новый ОписаниеТипов("Число, Строка");

0 commit comments

Comments
 (0)