compatible_type

This commit is contained in:
simon lehericey 2022-09-26 21:20:32 +02:00
parent cd2b08e39b
commit f98d1463a6
4 changed files with 7 additions and 7 deletions

View file

@ -182,7 +182,7 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
end
def current_right_valid?(left, right)
Logic.compatible_type?(left, right)
Logic.compatible_type?(left, right, @upper_tdcs)
end
def add_condition_tag

View file

@ -31,7 +31,7 @@ module Logic
in [:number, _]
end
if !compatible_type?(left, right)
if !compatible_type?(left, right, type_de_champs)
right = case left.type(type_de_champs)
when :boolean
Constant.new(true)
@ -47,7 +47,7 @@ module Logic
operator_class.new(left, right)
end
def self.compatible_type?(left, right)
def self.compatible_type?(left, right, type_de_champs)
case [left.type(type_de_champs), right.type(type_de_champs)]
in [a, ^a] # syntax for same type
true

View file

@ -6,7 +6,7 @@ class Logic::Eq < Logic::BinaryOperator
.filter { |term| term.type(type_de_champs) == :unmanaged }
.map { |term| { type: :unmanaged, stable_id: term.stable_id } }
if !Logic.compatible_type?(@left, @right)
if !Logic.compatible_type?(@left, @right, type_de_champs)
errors << {
type: :incompatible,
stable_id: @left.try(:stable_id),

View file

@ -60,15 +60,15 @@ describe Logic do
end
describe '.compatible_type?' do
it { expect(Logic.compatible_type?(constant(true), constant(true))).to be true }
it { expect(Logic.compatible_type?(constant(1), constant(true))).to be false }
it { expect(Logic.compatible_type?(constant(true), constant(true), [])).to be true }
it { expect(Logic.compatible_type?(constant(1), constant(true), [])).to be false }
context 'with a dropdown' do
let(:drop_down) { create(:type_de_champ_drop_down_list) }
let(:first_option) { drop_down.drop_down_list_enabled_non_empty_options.first }
it do
expect(Logic.compatible_type?(champ_value(drop_down.stable_id), constant('a'))).to be true
expect(Logic.compatible_type?(champ_value(drop_down.stable_id), constant('a'), [drop_down])).to be true
end
end
end