@@ -264,85 +264,6 @@ bool ps_ast_test_assignment()
264264 return true;
265265}
266266
267- /**
268- * @brief Test Hello Pascal program
269- * 0 1 2 3
270- * L/C 123456789012345678901234567890
271- * 1 Program Hello;
272- * 2 Begin
273- * 3 WriteLn('Hello, World!');
274- * 4 WriteLn(-42);
275- * 5 End.
276- */
277- bool ps_ast_test_hello ()
278- {
279- bool result ;
280-
281- ps_ast_block * block_program = ps_ast_test_create_block_program ("HELLO" );
282- ASSERT_RETURN_FALSE (block_program != NULL );
283-
284- ps_interpreter * interpreter = ps_ast_test_create_interpreter (block_program );
285- ASSERT_RETURN_FALSE (interpreter != NULL );
286-
287- ps_ast_debug_line (0 , "Create a statement list with 2 statements" );
288- block_program -> statement_list = ps_ast_create_statement_list (3 , 5 , 2 );
289- ASSERT_RETURN_FALSE (block_program -> statement_list != NULL );
290-
291- ps_ast_debug_line (0 , "Create the first by value argument" );
292- ps_string * hello = ps_string_heap_create (interpreter -> string_heap , "Hello, World!" );
293- ASSERT_RETURN_FALSE (hello != NULL );
294- ps_value value_hello = {.allocated = false, .type = & ps_system_string , .data .s = hello };
295- ps_ast_value * argument_hello = ps_ast_create_rvalue_const (3 , 13 , value_hello );
296- ASSERT_RETURN_FALSE (argument_hello != NULL );
297-
298- ps_ast_debug_line (0 , "Create the first by value argument" );
299- ps_value value_i_42 = {.allocated = false, .type = & ps_system_integer , .data .i = -42 };
300- ps_ast_value * argument_i_42 = ps_ast_create_rvalue_const (4 , 13 , value_i_42 );
301- ASSERT_RETURN_FALSE (argument_i_42 != NULL );
302-
303- ps_ast_debug_line (0 , "Create the argument list for the procedure call" );
304- ps_ast_node * * args1 = ps_memory_calloc (PS_MEMORY_AST , 1 , sizeof (ps_ast_node * ));
305- ASSERT_RETURN_FALSE (args1 != NULL );
306- args1 [0 ] = (ps_ast_node * )argument_hello ;
307-
308- ps_ast_debug_line (0 , "Create the first PROCEDURE CALL statement" );
309- ps_ast_call * statement1 = ps_ast_create_call (3 , 5 , PS_AST_PROCEDURE_CALL , & ps_system_procedure_writeln , 1 , args1 );
310- ASSERT_RETURN_FALSE (statement1 != NULL );
311-
312- ps_ast_debug_line (0 , "Create the argument list for the second procedure call" );
313- ps_ast_node * * args2 = ps_memory_calloc (PS_MEMORY_AST , 1 , sizeof (ps_ast_node * ));
314- ASSERT_RETURN_FALSE (args2 != NULL );
315- args2 [0 ] = (ps_ast_node * )argument_i_42 ;
316-
317- ps_ast_debug_line (0 , "Create the second PROCEDURE CALL statement" );
318- ps_ast_call * statement2 = ps_ast_create_call (3 , 5 , PS_AST_PROCEDURE_CALL , & ps_system_procedure_writeln , 1 , args2 );
319- ASSERT_RETURN_FALSE (statement2 != NULL );
320-
321- ps_ast_debug_line (0 , "Add the statements to the statement list" );
322- block_program -> statement_list -> statements [0 ] = (ps_ast_node * )statement1 ;
323- block_program -> statement_list -> statements [1 ] = (ps_ast_node * )statement2 ;
324-
325- ps_ast_debug_line (0 , "Debug print the program" );
326- ps_ast_debug = true;
327- ps_ast_debug_line (0 , "================================================================" );
328- ps_ast_debug_node (0 , (ps_ast_node * )block_program );
329- ps_ast_debug_line (0 , "================================================================" );
330-
331- ps_ast_debug_line (0 , "Run the program and check that it returns true" );
332- result = ps_ast_run_program (interpreter , block_program );
333- if (!result )
334- {
335- ps_ast_debug_line (0 , "Error running the program: %s (%d)" , interpreter -> error ,
336- ps_error_get_message (interpreter -> error ));
337- }
338-
339- ps_ast_test_delete_interpreter (interpreter , block_program );
340-
341- ps_ast_test_delete_block_program (block_program );
342-
343- return true;
344- }
345-
346267/**
347268 * @brief Test If-Then-Else Pascal program
348269 * L/C 123456789012345678901234567890123456789012345678901234567890
@@ -705,23 +626,102 @@ bool ps_ast_test_for_do()
705626 return true;
706627}
707628
629+ /**
630+ * @brief Test Hello Pascal program
631+ * 0 1 2 3
632+ * L/C 123456789012345678901234567890
633+ * 1 Program Hello;
634+ * 2 Begin
635+ * 3 WriteLn('Hello, World!');
636+ * 4 WriteLn(-42);
637+ * 5 End.
638+ */
639+ bool ps_ast_test_hello ()
640+ {
641+ bool result ;
642+
643+ ps_ast_block * block_program = ps_ast_test_create_block_program ("HELLO" );
644+ ASSERT_RETURN_FALSE (block_program != NULL );
645+
646+ ps_interpreter * interpreter = ps_ast_test_create_interpreter (block_program );
647+ ASSERT_RETURN_FALSE (interpreter != NULL );
648+
649+ ps_ast_debug_line (0 , "Create a statement list with 2 statements" );
650+ block_program -> statement_list = ps_ast_create_statement_list (3 , 5 , 2 );
651+ ASSERT_RETURN_FALSE (block_program -> statement_list != NULL );
652+
653+ ps_ast_debug_line (0 , "Create the first by value argument" );
654+ ps_string * hello = ps_string_heap_create (interpreter -> string_heap , "Hello, World!" );
655+ ASSERT_RETURN_FALSE (hello != NULL );
656+ ps_value value_hello = {.allocated = false, .type = & ps_system_string , .data .s = hello };
657+ ps_ast_value * argument_hello = ps_ast_create_rvalue_const (3 , 13 , value_hello );
658+ ASSERT_RETURN_FALSE (argument_hello != NULL );
659+
660+ ps_ast_debug_line (0 , "Create the first by value argument" );
661+ ps_value value_i_42 = {.allocated = false, .type = & ps_system_integer , .data .i = -42 };
662+ ps_ast_value * argument_i_42 = ps_ast_create_rvalue_const (4 , 13 , value_i_42 );
663+ ASSERT_RETURN_FALSE (argument_i_42 != NULL );
664+
665+ ps_ast_debug_line (0 , "Create the argument list for the procedure call" );
666+ ps_ast_node * * args1 = ps_memory_calloc (PS_MEMORY_AST , 1 , sizeof (ps_ast_node * ));
667+ ASSERT_RETURN_FALSE (args1 != NULL );
668+ args1 [0 ] = (ps_ast_node * )argument_hello ;
669+
670+ ps_ast_debug_line (0 , "Create the first PROCEDURE CALL statement" );
671+ ps_ast_call * statement1 = ps_ast_create_call (3 , 5 , PS_AST_PROCEDURE_CALL , & ps_system_procedure_writeln , 1 , args1 );
672+ ASSERT_RETURN_FALSE (statement1 != NULL );
673+
674+ ps_ast_debug_line (0 , "Create the argument list for the second procedure call" );
675+ ps_ast_node * * args2 = ps_memory_calloc (PS_MEMORY_AST , 1 , sizeof (ps_ast_node * ));
676+ ASSERT_RETURN_FALSE (args2 != NULL );
677+ args2 [0 ] = (ps_ast_node * )argument_i_42 ;
678+
679+ ps_ast_debug_line (0 , "Create the second PROCEDURE CALL statement" );
680+ ps_ast_call * statement2 = ps_ast_create_call (3 , 5 , PS_AST_PROCEDURE_CALL , & ps_system_procedure_writeln , 1 , args2 );
681+ ASSERT_RETURN_FALSE (statement2 != NULL );
682+
683+ ps_ast_debug_line (0 , "Add the statements to the statement list" );
684+ block_program -> statement_list -> statements [0 ] = (ps_ast_node * )statement1 ;
685+ block_program -> statement_list -> statements [1 ] = (ps_ast_node * )statement2 ;
686+
687+ ps_ast_debug_line (0 , "Debug print the program" );
688+ ps_ast_debug = true;
689+ ps_ast_debug_line (0 , "================================================================" );
690+ ps_ast_debug_node (0 , (ps_ast_node * )block_program );
691+ ps_ast_debug_line (0 , "================================================================" );
692+
693+ ps_ast_debug_line (0 , "Run the program and check that it returns true" );
694+ result = ps_ast_run_program (interpreter , block_program );
695+ if (!result )
696+ {
697+ ps_ast_debug_line (0 , "Error running the program: %s (%d)" , interpreter -> error ,
698+ ps_error_get_message (interpreter -> error ));
699+ }
700+
701+ ps_ast_test_delete_interpreter (interpreter , block_program );
702+
703+ ps_ast_test_delete_block_program (block_program );
704+
705+ return true;
706+ }
707+
708708bool ps_ast_test ()
709709{
710710 bool result = true;
711711
712- // ps_ast_debug_line(0, "****************************************************************");
713- // result &= ps_ast_test_minimal();
714- // ps_ast_debug_line(0, "****************************************************************");
715- // result &= ps_ast_test_assignment();
716- // ps_ast_debug_line(0, "****************************************************************");
717- // result &= ps_ast_test_hello();
718- // ps_ast_debug_line(0, "****************************************************************");
719- // result &= ps_ast_test_if_then_else();
720- // ps_ast_debug_line(0, "****************************************************************");
721- // result &= ps_ast_test_while_do();
712+ ps_ast_debug_line (0 , "****************************************************************" );
713+ result &= ps_ast_test_minimal ();
714+ ps_ast_debug_line (0 , "****************************************************************" );
715+ result &= ps_ast_test_assignment ();
716+ ps_ast_debug_line (0 , "****************************************************************" );
717+ result &= ps_ast_test_if_then_else ();
718+ ps_ast_debug_line (0 , "****************************************************************" );
719+ result &= ps_ast_test_while_do ();
722720 ps_ast_debug_line (0 , "****************************************************************" );
723721 result &= ps_ast_test_for_do ();
724722 ps_ast_debug_line (0 , "****************************************************************" );
723+ result &= ps_ast_test_hello ();
724+ ps_ast_debug_line (0 , "****************************************************************" );
725725
726726 return result ;
727727}
0 commit comments