@@ -294,101 +294,97 @@ def validate_toon_completeness(toon_data):
294294
295295 return all_present
296296
297+ def _run_single_file_mode (file_path : Path ) -> int :
298+ """Single file mode - validate TOON format structure only."""
299+ if not file_path .exists ():
300+ print (f"Error: { file_path } not found" )
301+ return 1
302+
303+ print (f"🔍 Validating TOON format: { file_path .name } " )
304+ print ("=" * 60 )
305+
306+ data = load_file (file_path )
307+ if not data :
308+ print ("Error: Could not load file" )
309+ return 1
310+
311+ is_valid = validate_toon_completeness (data )
312+
313+ print ("\n " + "=" * 60 )
314+ print ("📋 TOON FORMAT VALIDATION SUMMARY:" )
315+ print ("=" * 60 )
316+
317+ status = "✅ PASS" if is_valid else "❌ FAIL"
318+ print (f"{ status } TOON Structure" )
319+ print ("\n " + ("🎉 TOON FORMAT VALID!" if is_valid else "⚠️ TOON FORMAT ISSUES!" ))
320+
321+ return 0 if is_valid else 1
322+
323+
324+ def _run_comparison_mode (yaml_path : Path , toon_path : Path ) -> int :
325+ """Comparison mode - compare YAML vs TOON."""
326+ if not yaml_path .exists ():
327+ print (f"Error: { yaml_path } not found" )
328+ return 1
329+
330+ if not toon_path .exists ():
331+ print (f"Error: { toon_path } not found" )
332+ return 1
333+
334+ print (f"🔍 Validating: { yaml_path .name } vs { toon_path .name } " )
335+ print ("=" * 60 )
336+
337+ yaml_data = load_yaml (yaml_path )
338+ toon_data = load_file (toon_path )
339+
340+ if not yaml_data or not toon_data :
341+ print ("Error: Could not load one or both files" )
342+ return 1
343+
344+ results = _compare_all_aspects (yaml_data , toon_data )
345+ _print_comparison_summary (results )
346+
347+ return 0 if all (passed for _ , passed in results ) else 1
348+
349+
350+ def _compare_all_aspects (yaml_data , toon_data ) -> list :
351+ """Compare all aspects of YAML vs TOON data."""
352+ return [
353+ ("Basic Statistics" , compare_basic_stats (yaml_data , toon_data )),
354+ ("Functions" , compare_functions (yaml_data , toon_data )),
355+ ("Classes" , compare_classes (yaml_data , toon_data )),
356+ ("Modules" , compare_modules (yaml_data , toon_data )),
357+ ("TOON Structure" , validate_toon_completeness (toon_data ))
358+ ]
359+
360+
361+ def _print_comparison_summary (results : list ) -> None :
362+ """Print comparison summary report."""
363+ print ("\n " + "=" * 60 )
364+ print ("📋 FINAL VALIDATION SUMMARY:" )
365+ print ("=" * 60 )
366+
367+ all_passed = True
368+ for test_name , passed in results :
369+ status = "✅ PASS" if passed else "❌ FAIL"
370+ print (f"{ status } { test_name } " )
371+ if not passed :
372+ all_passed = False
373+
374+ print ("\n " + ("🎉 ALL TESTS PASSED!" if all_passed else "⚠️ SOME TESTS FAILED!" ))
375+
376+
297377def main ():
298378 """Main validation function."""
299379 if len (sys .argv ) == 2 :
300- # Single file mode - validate TOON format structure only
301- file_path = Path (sys .argv [1 ])
302-
303- if not file_path .exists ():
304- print (f"Error: { file_path } not found" )
305- sys .exit (1 )
306-
307- print (f"🔍 Validating TOON format: { file_path .name } " )
308- print ("=" * 60 )
309-
310- # Load file (auto-detect format)
311- data = load_file (file_path )
312-
313- if not data :
314- print ("Error: Could not load file" )
315- sys .exit (1 )
316-
317- # Validate structure
318- is_valid = validate_toon_completeness (data )
319-
320- # Final summary
321- print ("\n " + "=" * 60 )
322- print ("📋 TOON FORMAT VALIDATION SUMMARY:" )
323- print ("=" * 60 )
324-
325- status = "✅ PASS" if is_valid else "❌ FAIL"
326- print (f"{ status } TOON Structure" )
327-
328- print ("\n " + ("🎉 TOON FORMAT VALID!" if is_valid else "⚠️ TOON FORMAT ISSUES!" ))
329-
330- return 0 if is_valid else 1
331-
380+ return _run_single_file_mode (Path (sys .argv [1 ]))
332381 elif len (sys .argv ) == 3 :
333- # Comparison mode - compare YAML vs TOON
334- yaml_path = Path (sys .argv [1 ])
335- toon_path = Path (sys .argv [2 ])
336-
337- if not yaml_path .exists ():
338- print (f"Error: { yaml_path } not found" )
339- sys .exit (1 )
340-
341- if not toon_path .exists ():
342- print (f"Error: { toon_path } not found" )
343- sys .exit (1 )
344-
345- print (f"🔍 Validating: { yaml_path .name } vs { toon_path .name } " )
346- print ("=" * 60 )
347-
348- # Load both files
349- yaml_data = load_yaml (yaml_path )
350- toon_data = load_file (toon_path ) # Auto-detect TOON format
351-
352- if not yaml_data or not toon_data :
353- print ("Error: Could not load one or both files" )
354- sys .exit (1 )
355-
356- # Compare all aspects
357- stats_match = compare_basic_stats (yaml_data , toon_data )
358- functions_match = compare_functions (yaml_data , toon_data )
359- classes_match = compare_classes (yaml_data , toon_data )
360- modules_match = compare_modules (yaml_data , toon_data )
361- toon_valid = validate_toon_completeness (toon_data )
362-
363- # Final summary
364- print ("\n " + "=" * 60 )
365- print ("📋 FINAL VALIDATION SUMMARY:" )
366- print ("=" * 60 )
367-
368- results = [
369- ("Basic Statistics" , stats_match ),
370- ("Functions" , functions_match ),
371- ("Classes" , classes_match ),
372- ("Modules" , modules_match ),
373- ("TOON Structure" , toon_valid )
374- ]
375-
376- all_passed = True
377- for test_name , passed in results :
378- status = "✅ PASS" if passed else "❌ FAIL"
379- print (f"{ status } { test_name } " )
380- if not passed :
381- all_passed = False
382-
383- print ("\n " + ("🎉 ALL TESTS PASSED!" if all_passed else "⚠️ SOME TESTS FAILED!" ))
384-
385- return 0 if all_passed else 1
386-
382+ return _run_comparison_mode (Path (sys .argv [1 ]), Path (sys .argv [2 ]))
387383 else :
388384 print ("Usage:" )
389385 print (" python validate_toon.py <analysis.toon> # Validate TOON only" )
390386 print (" python validate_toon.py <analysis.yaml> <analysis.toon> # Compare both formats" )
391- sys . exit ( 1 )
387+ return 1
392388
393389if __name__ == '__main__' :
394390 sys .exit (main ())
0 commit comments