Skip to content

Commit edb2266

Browse files
committed
Start writing some tests for the parsing part
1 parent f9a706f commit edb2266

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

include/Parse.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
#include "BalancedBinaryTree.h"
1414
#include <stdlib.h>
1515
#include <errno.h>
16+
#include "Vars.h"
1617

1718
LinkedList P_parse(const char*);
19+
char* P_matchingBracket(const char*, const char , const char, int*);
20+
char* P_getInBetween(const char*, char, int*);
21+
char* P_getNextWord(const char*, int, int*);
22+
char* P_process_string(const char*);
23+
Var* P_porcess(const char* word);
1824

1925
#endif

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ comp: $(src)/comp.o $(lib)/liblang.a
1313
tests: $(tests)/testMain.o $(lib)/libtests.a $(lib)/liblang.a
1414
$(cc) $(ldtestflags) -o testMain $^
1515

16-
$(lib)/libtests.a: $(tests)/LinkedList_tests.o
16+
$(lib)/libtests.a: $(tests)/LinkedList_tests.o $(tests)/Parse_tests.o
1717
ar -r $@ $^
1818

1919
$(lib)/liblang.a: $(src)/Parse.o $(src)/LinkedList.o $(src)/Identifiers.o $(src)/Eval.o $(src)/Vars.o $(src)/BalancedBinaryTree.o $(src)/Type.o

tests/Parse_tests.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "Parse.h"
2+
#include "Parse_tests.h"
3+
#include <stdlib.h>
4+
#include <stdbool.h>
5+
#include <CUnit/Basic.h>
6+
7+
int clean_P_suite_success(void) {
8+
return EXIT_SUCCESS;
9+
}
10+
11+
int init_P_suite_success(void) {
12+
return EXIT_SUCCESS;
13+
}
14+
void P_matchingBracket_test(void) {
15+
const char* a = "(defkjv 4 + 5s4) 45 65 645 ";
16+
int pos = 0;
17+
char* res = P_matchingBracket(a, '(', ')', &pos);
18+
19+
CU_ASSERT_STRING_EQUAL(res, "(defkjv 4 + 5s4");
20+
CU_ASSERT_EQUAL(pos, 17);
21+
CU_ASSERT_STRING_EQUAL(a, "(defkjv 4 + 5s4) 45 65 645 ");
22+
}

tests/Parse_tests.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef PARSE_TESTS_H
2+
#define PARSE_TESTS_H
3+
4+
void P_matchingBracket_test(void);
5+
int clean_P_suite_success(void);
6+
int init_P_suite_success(void);
7+
8+
#endif

tests/testMain.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
#include <CUnit/Basic.h>
44

55
#include "LinkedList_tests.h"
6+
#include "Parse_tests.h"
67

78
int main(int argc, char** argv){
89
CU_pSuite LL_suite = NULL;
10+
CU_pSuite P_suite = NULL;
911

1012
/* initialisation du registre de tests */
1113
if (CUE_SUCCESS != CU_initialize_registry())
@@ -17,6 +19,12 @@ int main(int argc, char** argv){
1719
CU_cleanup_registry();
1820
return CU_get_error();
1921
}
22+
23+
P_suite = CU_add_suite("Parse", init_P_suite_success, clean_P_suite_success);
24+
if (NULL == P_suite) {
25+
CU_cleanup_registry();
26+
return CU_get_error();
27+
}
2028

2129
/* Ajout des tests à la suite de tests boite noire */
2230
if ((NULL == CU_add_test(LL_suite, "LL_add", test_add))
@@ -25,6 +33,7 @@ int main(int argc, char** argv){
2533
|| (NULL == CU_add_test(LL_suite, "LL_getValue", test_getValue))
2634
|| (NULL == CU_add_test(LL_suite, "LL_setNext", test_setNext))
2735
|| (NULL == CU_add_test(LL_suite, "LL_setValue", test_setValue))
36+
|| (NULL == CU_add_test(P_suite, "P_matchingBracket", P_matchingBracket_test))
2837
)
2938
{
3039
CU_cleanup_registry();

0 commit comments

Comments
 (0)