|
3 | 3 | Tucana.load_protocol(:shared) |
4 | 4 |
|
5 | 5 | RSpec.describe Tucana::Shared::DefinitionDataTypeRule do |
6 | | - describe "#create" do |
| 6 | + describe '#from_hash' do |
| 7 | + context 'GenericType#from_hash' do |
| 8 | + it do |
| 9 | + generic_type = Tucana::Shared::GenericType.new.from_hash({ |
| 10 | + data_type_identifier: 'SomeIdentifier', |
| 11 | + generic_mappers: [ |
| 12 | + { |
| 13 | + source: [{ data_type_identifier: 'SomeType' }], |
| 14 | + target: 'T', |
| 15 | + generic_combinations: [:AND] |
| 16 | + } |
| 17 | + ] |
| 18 | + }) |
| 19 | + |
| 20 | + expect(generic_type).not_to be_nil |
| 21 | + end |
| 22 | + end |
| 23 | + context 'GenericMapper#from_hash' do |
| 24 | + context 'when type is :map_to_generic_type' do |
| 25 | + it do |
| 26 | + generic_mapper = Tucana::Shared::GenericMapper.new.from_hash({ |
| 27 | + source: [{ data_type_identifier: 'SomeType' }], |
| 28 | + target: 'T', |
| 29 | + generic_combinations: [:AND] |
| 30 | + }) |
| 31 | + |
| 32 | + expect(generic_mapper.to_s).to eq("<Tucana::Shared::GenericMapper: source: [<Tucana::Shared::DataTypeIdentifier: data_type_identifier: \"SomeType\">], target: \"T\", generic_combinations: [:AND]>") |
| 33 | + end |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | + describe '#create' do |
7 | 38 | context 'DataTypeIdentifier#to_h' do |
8 | 39 | context 'generic_key' do |
9 | 40 | it do |
|
37 | 68 | end |
38 | 69 | end |
39 | 70 |
|
40 | | - context "with :contains_key variant" do |
41 | | - it "sets the contains_key field" do |
42 | | - config = { key: "test_key", data_type_identifier: { data_type_identifier: "test_type" } } |
| 71 | + context 'with :contains_key variant' do |
| 72 | + it 'sets the contains_key field' do |
| 73 | + config = { key: 'test_key', data_type_identifier: { data_type_identifier: 'test_type' } } |
43 | 74 | rule = described_class.create(:contains_key, config) |
44 | 75 | expect(rule.contains_key).to be_a(Tucana::Shared::DefinitionDataTypeContainsKeyRuleConfig) |
45 | 76 | end |
46 | 77 | end |
47 | 78 |
|
48 | | - context "with :contains_type variant" do |
49 | | - it "sets the contains_type field" do |
50 | | - config = { data_type_identifier: { data_type_identifier: "test_type" } } |
| 79 | + context 'with :contains_type variant' do |
| 80 | + it 'sets the contains_type field' do |
| 81 | + config = { data_type_identifier: { data_type_identifier: 'test_type' } } |
51 | 82 | rule = described_class.create(:contains_type, config) |
52 | 83 | expect(rule.contains_type).to be_a(Tucana::Shared::DefinitionDataTypeContainsTypeRuleConfig) |
53 | 84 | end |
54 | 85 | end |
55 | 86 |
|
56 | | - context "with :item_of_collection variant" do |
57 | | - it "sets the item_of_collection field" do |
| 87 | + context 'with :item_of_collection variant' do |
| 88 | + it 'sets the item_of_collection field' do |
58 | 89 | config = { items: %w[item1 item2] } |
59 | 90 | rule = described_class.create(:item_of_collection, config) |
60 | 91 | expect(rule.item_of_collection).to be_a(Tucana::Shared::DataTypeItemOfCollectionRuleConfig) |
61 | 92 | end |
62 | 93 | end |
63 | 94 |
|
64 | | - context "with :number_range variant" do |
65 | | - it "sets the number_range field" do |
| 95 | + context 'with :number_range variant' do |
| 96 | + it 'sets the number_range field' do |
66 | 97 | config = { from: 1, to: 10 } |
67 | 98 | rule = described_class.create(:number_range, config) |
68 | 99 | expect(rule.number_range).to be_a(Tucana::Shared::DataTypeNumberRangeRuleConfig) |
69 | 100 | end |
70 | 101 | end |
71 | 102 |
|
72 | | - context "with :regex variant" do |
73 | | - it "sets the regex field" do |
74 | | - config = { pattern: "\\d+" } |
| 103 | + context 'with :regex variant' do |
| 104 | + it 'sets the regex field' do |
| 105 | + config = { pattern: '\\d+' } |
75 | 106 | rule = described_class.create(:regex, config) |
76 | 107 | expect(rule.regex).to be_a(Tucana::Shared::DataTypeRegexRuleConfig) |
77 | 108 | end |
78 | 109 | end |
79 | 110 |
|
80 | | - context "with :input_types variant" do |
81 | | - it "sets the input_types field" do |
82 | | - config = { input_types: [{ data_type_identifier: { data_type_identifier: "test_type" }, input_identifier: "test_input" }] } |
| 111 | + context 'with :input_types variant' do |
| 112 | + it 'sets the input_types field' do |
| 113 | + config = { input_types: [{ data_type_identifier: { data_type_identifier: 'test_type' }, |
| 114 | + input_identifier: 'test_input' }] } |
83 | 115 | rule = described_class.create(:input_types, config) |
84 | 116 | expect(rule.input_types).to be_a(Tucana::Shared::DefinitionDataTypeInputTypesRuleConfig) |
85 | 117 | end |
86 | 118 | end |
87 | 119 |
|
88 | | - context "with :return_type variant" do |
89 | | - it "sets the return_type field" do |
90 | | - config = { data_type_identifier: { data_type_identifier: "test_type" } } |
| 120 | + context 'with :return_type variant' do |
| 121 | + it 'sets the return_type field' do |
| 122 | + config = { data_type_identifier: { data_type_identifier: 'test_type' } } |
91 | 123 | rule = described_class.create(:return_type, config) |
92 | 124 | expect(rule.return_type).to be_a(Tucana::Shared::DefinitionDataTypeReturnTypeRuleConfig) |
93 | 125 | end |
94 | 126 | end |
95 | 127 |
|
96 | | - context "with :parent_type variant" do |
97 | | - it "sets the parent_type field" do |
98 | | - config = { parent_type: { data_type_identifier: "test_type" } } |
| 128 | + context 'with :parent_type variant' do |
| 129 | + it 'sets the parent_type field' do |
| 130 | + config = { parent_type: { data_type_identifier: 'test_type' } } |
99 | 131 | rule = described_class.create(:parent_type, config) |
100 | 132 | expect(rule.parent_type).to be_a(Tucana::Shared::DefinitionDataTypeParentTypeRuleConfig) |
101 | 133 | end |
102 | 134 | end |
103 | 135 |
|
104 | | - context "with unknown variant" do |
105 | | - it "raises UnexpectedRuleType error" do |
106 | | - expect { |
| 136 | + context 'with unknown variant' do |
| 137 | + it 'raises UnexpectedRuleType error' do |
| 138 | + expect do |
107 | 139 | described_class.create(:unknown, {}) |
108 | | - }.to raise_error(Tucana::Shared::UnexpectedRuleType, "Unknown rule type unknown") |
| 140 | + end.to raise_error(Tucana::Shared::UnexpectedRuleType, 'Unknown rule type unknown') |
109 | 141 | end |
110 | 142 | end |
111 | 143 | end |
|
0 commit comments