1+ use crate :: shared:: DataTypeIdentifier ;
12use crate :: shared:: data_type_input_types_rule_config:: DataTypeInputType ;
23use crate :: shared:: {
34 DataTypeContainsKeyRuleConfig , DataTypeContainsTypeRuleConfig , DataTypeInputTypesRuleConfig ,
@@ -14,20 +15,24 @@ impl RuleBuilder {
1415 Self { rules : Vec :: new ( ) }
1516 }
1617
17- pub fn add_contains_key ( mut self , key : String , data_type_identifier : String ) -> Self {
18+ pub fn add_contains_key (
19+ mut self ,
20+ key : String ,
21+ data_type_identifier : DataTypeIdentifier ,
22+ ) -> Self {
1823 self . rules . push ( DataTypeRule {
1924 config : Some ( Config :: ContainsKey ( DataTypeContainsKeyRuleConfig {
2025 key,
21- data_type_identifier,
26+ data_type_identifier : Some ( data_type_identifier ) ,
2227 } ) ) ,
2328 } ) ;
2429 self
2530 }
2631
27- pub fn add_contains_type ( mut self , data_type_identifier : String ) -> Self {
32+ pub fn add_contains_type ( mut self , data_type_identifier : DataTypeIdentifier ) -> Self {
2833 self . rules . push ( DataTypeRule {
2934 config : Some ( Config :: ContainsType ( DataTypeContainsTypeRuleConfig {
30- data_type_identifier,
35+ data_type_identifier : Some ( data_type_identifier ) ,
3136 } ) ) ,
3237 } ) ;
3338 self
@@ -69,10 +74,10 @@ impl RuleBuilder {
6974 self
7075 }
7176
72- pub fn add_return_type ( mut self , data_type_identifier : String ) -> Self {
77+ pub fn add_return_type ( mut self , data_type_identifier : DataTypeIdentifier ) -> Self {
7378 self . rules . push ( DataTypeRule {
7479 config : Some ( Config :: ReturnType ( DataTypeReturnTypeRuleConfig {
75- data_type_identifier,
80+ data_type_identifier : Some ( data_type_identifier ) ,
7681 } ) ) ,
7782 } ) ;
7883 self
@@ -87,32 +92,40 @@ impl RuleBuilder {
8792mod tests {
8893 use super :: * ;
8994 use crate :: shared:: {
90- data_type_input_types_rule_config :: DataTypeInputType , data_type_rule :: Config ,
91- helper:: value:: ToValue ,
95+ data_type_identifier :: Type , data_type_input_types_rule_config :: DataTypeInputType ,
96+ data_type_rule :: Config , helper:: value:: ToValue ,
9297 } ;
9398
99+ fn to_data_type ( str : & str ) -> DataTypeIdentifier {
100+ DataTypeIdentifier {
101+ r#type : Some ( Type :: DataTypeIdentifier ( str. into ( ) ) ) ,
102+ }
103+ }
104+
94105 #[ test]
95106 fn test_add_contains_key ( ) {
96107 let rules = RuleBuilder :: new ( )
97- . add_contains_key ( "id" . into ( ) , "User" . into ( ) )
108+ . add_contains_key ( "id" . into ( ) , to_data_type ( "User" ) )
98109 . build ( ) ;
99110
100111 match & rules[ 0 ] . config {
101112 Some ( Config :: ContainsKey ( cfg) ) => {
102113 assert_eq ! ( cfg. key, "id" ) ;
103- assert_eq ! ( cfg. data_type_identifier, "User" ) ;
114+ assert_eq ! ( cfg. data_type_identifier, Some ( to_data_type ( "User" ) ) ) ;
104115 }
105116 _ => panic ! ( "Expected ContainsKey config" ) ,
106117 }
107118 }
108119
109120 #[ test]
110121 fn test_add_contains_type ( ) {
111- let rules = RuleBuilder :: new ( ) . add_contains_type ( "User" . into ( ) ) . build ( ) ;
122+ let rules = RuleBuilder :: new ( )
123+ . add_contains_type ( to_data_type ( "User" ) )
124+ . build ( ) ;
112125
113126 match & rules[ 0 ] . config {
114127 Some ( Config :: ContainsType ( cfg) ) => {
115- assert_eq ! ( cfg. data_type_identifier, "User" ) ;
128+ assert_eq ! ( cfg. data_type_identifier, Some ( to_data_type ( "User" ) ) ) ;
116129 }
117130 _ => panic ! ( "Expected ContainsType config" ) ,
118131 }
@@ -163,11 +176,11 @@ mod tests {
163176 fn test_add_input_types ( ) {
164177 let input_types = vec ! [
165178 DataTypeInputType {
166- data_type_identifier: "Type1" . into ( ) ,
179+ data_type_identifier: Some ( to_data_type ( "Type1" ) ) ,
167180 input_identifier: "input1" . into( ) ,
168181 } ,
169182 DataTypeInputType {
170- data_type_identifier: "Type2" . into ( ) ,
183+ data_type_identifier: Some ( to_data_type ( "Type2" ) ) ,
171184 input_identifier: "input2" . into( ) ,
172185 } ,
173186 ] ;
@@ -186,11 +199,13 @@ mod tests {
186199
187200 #[ test]
188201 fn test_add_return_type ( ) {
189- let rules = RuleBuilder :: new ( ) . add_return_type ( "Result" . into ( ) ) . build ( ) ;
202+ let rules = RuleBuilder :: new ( )
203+ . add_return_type ( to_data_type ( "Result" ) )
204+ . build ( ) ;
190205
191206 match & rules[ 0 ] . config {
192207 Some ( Config :: ReturnType ( cfg) ) => {
193- assert_eq ! ( cfg. data_type_identifier, "Result" ) ;
208+ assert_eq ! ( cfg. data_type_identifier, Some ( to_data_type ( "Result" ) ) ) ;
194209 }
195210 _ => panic ! ( "Expected ReturnType config" ) ,
196211 }
@@ -199,23 +214,23 @@ mod tests {
199214 #[ test]
200215 fn test_add_many_rules ( ) {
201216 let rules = RuleBuilder :: new ( )
202- . add_contains_key ( "id" . into ( ) , "User" . into ( ) )
203- . add_return_type ( "Result" . into ( ) )
217+ . add_contains_key ( "id" . into ( ) , to_data_type ( "User" ) )
218+ . add_return_type ( to_data_type ( "Result" ) )
204219 . add_regex ( r"^\d+$" . into ( ) )
205- . add_contains_key ( "id" . into ( ) , "User" . into ( ) )
220+ . add_contains_key ( "id" . into ( ) , to_data_type ( "User" ) )
206221 . build ( ) ;
207222
208223 match & rules[ 0 ] . config {
209224 Some ( Config :: ContainsKey ( cfg) ) => {
210225 assert_eq ! ( cfg. key, "id" ) ;
211- assert_eq ! ( cfg. data_type_identifier, "User" ) ;
226+ assert_eq ! ( cfg. data_type_identifier, Some ( to_data_type ( "User" ) ) ) ;
212227 }
213228 _ => panic ! ( "Expected ContainsKey config" ) ,
214229 }
215230
216231 match & rules[ 1 ] . config {
217232 Some ( Config :: ReturnType ( cfg) ) => {
218- assert_eq ! ( cfg. data_type_identifier, "Result" ) ;
233+ assert_eq ! ( cfg. data_type_identifier, Some ( to_data_type ( "Result" ) ) ) ;
219234 }
220235 _ => panic ! ( "Expected ReturnType config" ) ,
221236 }
@@ -230,7 +245,7 @@ mod tests {
230245 match & rules[ 3 ] . config {
231246 Some ( Config :: ContainsKey ( cfg) ) => {
232247 assert_eq ! ( cfg. key, "id" ) ;
233- assert_eq ! ( cfg. data_type_identifier, "User" ) ;
248+ assert_eq ! ( cfg. data_type_identifier, Some ( to_data_type ( "User" ) ) ) ;
234249 }
235250 _ => panic ! ( "Expected ContainsKey config" ) ,
236251 }
0 commit comments