@@ -271,68 +271,30 @@ fn table_annotations_none() -> TestResult {
271271 run_test ( input, expected)
272272}
273273
274- #[ test]
275- fn table_annotations ( ) -> TestResult {
276- let input = "def run [t: table<age: int>] { $t }; run [[age]; [3]] | describe" ;
277- let expected = "table<age: int>" ;
278- run_test ( input, expected)
279- }
280-
281- #[ test]
282- fn table_annotations_two_types ( ) -> TestResult {
283- let input = "\
284- def run [t: table<name: string age: int>] { $t };
285- run [[name, age]; [nushell, 3]] | describe" ;
286- let expected = "table<name: string, age: int>" ;
287- run_test ( input, expected)
288- }
289-
290- #[ test]
291- fn table_annotations_two_types_comma_sep ( ) -> TestResult {
292- let input = "\
293- def run [t: table<name: string, age: int>] { $t };
294- run [[name, age]; [nushell, 3]] | describe" ;
295- let expected = "table<name: string, age: int>" ;
296- run_test ( input, expected)
297- }
298-
299- #[ test]
300- fn table_annotations_key_with_no_type ( ) -> TestResult {
301- let input = "def run [t: table<name>] { $t }; run [[name]; [nushell]] | describe" ;
302- let expected = "table<name: string>" ;
303- run_test ( input, expected)
304- }
305-
306- #[ test]
307- fn table_annotations_two_types_one_with_no_type ( ) -> TestResult {
308- let input = "\
309- def run [t: table<name: string, age>] { $t };
310- run [[name, age]; [nushell, 3]] | describe" ;
311- let expected = "table<name: string, age: int>" ;
312- run_test ( input, expected)
313- }
314-
315- #[ test]
316- fn table_annotations_two_types_both_with_no_types ( ) -> TestResult {
317- let input = "\
318- def run [t: table<name, age>] { $t };
319- run [[name, age]; [nushell, 3]] | describe" ;
320- let expected = "table<name: string, age: int>" ;
321- run_test ( input, expected)
322- }
323-
324- #[ test]
325- fn table_annotations_type_inference_1 ( ) -> TestResult {
326- let input = "def run [t: table<age: any>] { $t }; run [[age]; [2wk]] | describe" ;
327- let expected = "table<age: duration>" ;
328- run_test ( input, expected)
329- }
330-
331- #[ test]
332- fn table_annotations_type_inference_2 ( ) -> TestResult {
333- let input = "def run [t: table<size>] { $t }; run [[size]; [2mb]] | describe" ;
334- let expected = "table<size: filesize>" ;
335- run_test ( input, expected)
274+ #[ rstest]
275+ fn table_annotations (
276+ #[ values( true , false ) ] list_annotation : bool ,
277+ #[ values(
278+ ( "age: int" , "age: int" , "[[age]; [3]]" ) ,
279+ ( "name: string age: int" , "name: string, age: int" , "[[name, age]; [nushell, 3]]" ) ,
280+ ( "name: string, age: int" , "name: string, age: int" , "[[name, age]; [nushell, 3]]" ) ,
281+ ( "name" , "name: string" , "[[name]; [nushell]]" ) ,
282+ ( "name: string, age" , "name: string, age: int" , "[[name, age]; [nushell, 3]]" ) ,
283+ ( "name, age" , "name: string, age: int" , "[[name, age]; [nushell, 3]]" ) ,
284+ ( "age: any" , "age: duration" , "[[age]; [2wk]]" ) ,
285+ ( "size" , "size: filesize" , "[[size]; [2mb]]" )
286+ ) ]
287+ record_annotation_data : ( & str , & str , & str ) ,
288+ ) -> TestResult {
289+ let ( record_annotation, inferred_type, data) = record_annotation_data;
290+
291+ let type_annotation = match list_annotation {
292+ true => format ! ( "list<record<{record_annotation}>>" ) ,
293+ false => format ! ( "table<{record_annotation}>" ) ,
294+ } ;
295+ let input = format ! ( "def run [t: {type_annotation}] {{ $t }}; run {data} | describe" ) ;
296+ let expected = format ! ( "table<{inferred_type}>" ) ;
297+ run_test ( & input, & expected)
336298}
337299
338300#[ test]
0 commit comments