77from .. import transform as tf
88from ..dependency_store import DependencyStore , PlcProjectMetadata
99from ..parse import parse_source_code
10- from ..summary import (CodeSummary , DeclarationSummary , FunctionBlockSummary ,
11- MethodSummary , PropertySummary )
10+ from ..summary import (ActionSummary , CodeSummary , DeclarationSummary ,
11+ FunctionBlockSummary , FunctionSummary , MethodSummary ,
12+ PropertySummary , text_outline )
1213
1314
1415@dataclass
@@ -21,8 +22,7 @@ class DeclarationCheck:
2122
2223
2324def check_declarations (
24- container : dict [str , DeclarationSummary ],
25- checks : list [DeclarationCheck ]
25+ container : dict [str , DeclarationSummary ], checks : list [DeclarationCheck ]
2626):
2727 """
2828 Check that ``container`` has the listed declarations - and only those.
@@ -63,12 +63,13 @@ def check_declarations(
6363def project_a (store : DependencyStore ) -> PlcProjectMetadata :
6464 # This is project a from the git submodule included with the blark test
6565 # suite
66- proj , = store .get_dependency ("project_a" )
66+ ( proj ,) = store .get_dependency ("project_a" )
6767 return proj
6868
6969
7070def test_project_a_summary (project_a : PlcProjectMetadata ):
7171 summary = project_a .summary
72+ print (text_outline (summary ))
7273
7374 assert list (summary .function_blocks ) == ["FB_ProjectA" ]
7475
@@ -96,12 +97,13 @@ def test_project_a_summary(project_a: PlcProjectMetadata):
9697def project_b (store : DependencyStore ) -> PlcProjectMetadata :
9798 # This is project b from the git submodule included with the blark test
9899 # suite
99- proj , = store .get_dependency ("project_b" )
100+ ( proj ,) = store .get_dependency ("project_b" )
100101 return proj
101102
102103
103104def test_project_b_summary (project_b : PlcProjectMetadata ):
104105 summary = project_b .summary
106+ print (text_outline (summary ))
105107
106108 st_projectb = summary .data_types ["ST_ProjectB" ]
107109 assert list (st_projectb .declarations ) == ["iProjectB" ]
@@ -124,12 +126,14 @@ def twincat_general_281(store: DependencyStore) -> PlcProjectMetadata:
124126 # included with the blark test suite.
125127 # This is *not* the full version from pcdshub/lcls-twincat-general, but
126128 # rather a part of it for the purposes of the blark test suite.
127- proj , = store .get_dependency ("LCLS_General" , "v2.8.1" )
129+ ( proj ,) = store .get_dependency ("LCLS_General" , "v2.8.1" )
128130 return proj
129131
130132
131133def test_twincat_general (twincat_general_281 : PlcProjectMetadata ):
132134 summary = twincat_general_281 .summary
135+ print (text_outline (summary ))
136+
133137 assert list (summary .function_blocks ) == ["FB_LogHandler" ]
134138 loghandler = summary .function_blocks ["FB_LogHandler" ]
135139
@@ -151,7 +155,7 @@ def test_twincat_general(twincat_general_281: PlcProjectMetadata):
151155 base_type = "UINT" ,
152156 value = "5" ,
153157 ),
154- ]
158+ ],
155159 )
156160 # Ensure comments transferred over
157161 assert loghandler .implementation is None
@@ -179,7 +183,7 @@ def test_twincat_general(twincat_general_281: PlcProjectMetadata):
179183 value = "3" ,
180184 comments = ["// Maximum number of ports (4) on ESC" ],
181185 ),
182- ]
186+ ],
183187 )
184188
185189 defaults = summary .globals ["DefaultGlobals" ]
@@ -196,7 +200,7 @@ def test_twincat_general(twincat_general_281: PlcProjectMetadata):
196200 name = "fTimeStamp" ,
197201 base_type = "LREAL" ,
198202 ),
199- ]
203+ ],
200204 )
201205
202206 system = summary .data_types ["ST_System" ]
@@ -240,7 +244,7 @@ def test_twincat_general(twincat_general_281: PlcProjectMetadata):
240244 location = "%I*" ,
241245 comments = [
242246 "{attribute 'naming' := 'omit'}" ,
243- "(* AMS Net ID used for FB_EcatDiag, among others *)"
247+ "(* AMS Net ID used for FB_EcatDiag, among others *)" ,
244248 ],
245249 ),
246250 ],
@@ -249,6 +253,8 @@ def test_twincat_general(twincat_general_281: PlcProjectMetadata):
249253
250254def test_twincat_general_interface (twincat_general_281 : PlcProjectMetadata ):
251255 summary = twincat_general_281 .summary
256+ print (text_outline (summary ))
257+
252258 assert set (str (itf ) for itf in summary .interfaces ) == {"I_Base" , "I_Interface" }
253259 base = summary .interfaces ["I_Base" ]
254260 itf = summary .interfaces ["I_Interface" ]
@@ -261,7 +267,7 @@ def test_twincat_general_interface(twincat_general_281: PlcProjectMetadata):
261267 base_type = "INT" ,
262268 value = None ,
263269 ),
264- ]
270+ ],
265271 )
266272
267273 check_declarations (
@@ -294,7 +300,7 @@ def test_twincat_general_interface(twincat_general_281: PlcProjectMetadata):
294300 base_type = "INT" ,
295301 value = None ,
296302 ),
297- ]
303+ ],
298304 )
299305
300306 assert {prop .name for prop in base .properties } == {"BaseProperty" }
@@ -320,6 +326,8 @@ def test_twincat_general_interface(twincat_general_281: PlcProjectMetadata):
320326 assert isinstance (method1 , MethodSummary )
321327 assert method1 .return_type == "BOOL"
322328
329+ assert list (method1 .declarations_by_block ) == []
330+
323331
324332def test_isolated_summary ():
325333 declarations = textwrap .dedent (
@@ -354,13 +362,17 @@ def test_isolated_summary():
354362
355363 parsed = parse_source_code (declarations )
356364 summary = CodeSummary .from_parse_results (parsed , squash = True )
365+ print ("Parsed summary:" )
366+ print (str (summary ))
357367
358368 fb_test = summary ["FB_Test" ]
359369 assert isinstance (fb_test , FunctionBlockSummary )
360370 assert fb_test .name == "FB_Test"
361371 assert fb_test .declarations ["iValue" ].base_type == "INT"
362372
363373 st_struct = fb_test .declarations ["stStruct" ]
374+ assert fb_test ["stStruct" ] is st_struct
375+
364376 assert st_struct .base_type == "StructureType"
365377 assert summary .find_code_object_by_dotted_name ("FB_Test.stStruct" ) is st_struct
366378
@@ -402,3 +414,81 @@ def test_isolated_summary():
402414 assert runner .base_type == "FB_Runner"
403415 assert runner .type == "ARRAY [1..2] OF FB_Runner[(name := 'one'), (name := 'two')]"
404416 assert runner .value == "None"
417+
418+
419+ def test_function_summary ():
420+ declarations = textwrap .dedent (
421+ """\
422+ FUNCTION F_Test : INT
423+ VAR_INPUT
424+ iValue : INT;
425+ END_VAR
426+ END_FUNCTION
427+ """
428+ )
429+
430+ parsed = parse_source_code (declarations )
431+ summary = CodeSummary .from_parse_results (parsed , squash = True )
432+ print ("Parsed summary:" )
433+ print (str (summary ))
434+
435+ f_test = summary ["F_Test" ]
436+ assert isinstance (f_test , FunctionSummary )
437+ assert f_test .name == "F_Test"
438+ assert f_test .return_type == "INT"
439+ assert f_test ["iValue" ].base_type == "INT"
440+
441+
442+ def test_action_summary ():
443+ declarations = textwrap .dedent (
444+ """\
445+ FUNCTION_BLOCK fbName
446+ END_FUNCTION_BLOCK
447+ ACTION ActName :
448+ iValue := iValue + 2;
449+ END_ACTION
450+ """
451+ )
452+
453+ parsed = parse_source_code (declarations )
454+ summary = CodeSummary .from_parse_results (parsed , squash = True )
455+ print ("Parsed summary:" )
456+ print (str (summary ))
457+
458+ fb = summary ["fbName" ]
459+ (act ,) = fb .actions
460+ assert isinstance (act , ActionSummary )
461+ assert act .name == "ActName"
462+ assert str (act .item .body ) == "iValue := iValue + 2;"
463+
464+
465+ def test_fb_extends_summary ():
466+ declarations = textwrap .dedent (
467+ """\
468+ FUNCTION_BLOCK fbBase
469+ VAR_INPUT
470+ iBase : INT := 1;
471+ END_VAR
472+ END_FUNCTION_BLOCK
473+ FUNCTION_BLOCK fbExtended EXTENDS fbBase
474+ VAR_INPUT
475+ iExtended : INT := 2;
476+ END_VAR
477+ END_FUNCTION_BLOCK
478+ """
479+ )
480+
481+ parsed = parse_source_code (declarations )
482+ summary = CodeSummary .from_parse_results (parsed , squash = True )
483+ print ("Parsed summary:" )
484+ print (str (summary ))
485+
486+ base = summary ["fbBase" ]
487+ assert base .declarations ["iBase" ].base_type == "INT"
488+ assert base .declarations ["iBase" ].value == "1"
489+
490+ extended = summary ["fbExtended" ]
491+ assert extended .declarations ["iBase" ].base_type == "INT"
492+ assert extended .declarations ["iBase" ].value == "1"
493+ assert extended .declarations ["iExtended" ].base_type == "INT"
494+ assert extended .declarations ["iExtended" ].value == "2"
0 commit comments