-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathtest_scope.c
More file actions
78 lines (55 loc) · 1.54 KB
/
test_scope.c
File metadata and controls
78 lines (55 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <assert.h>
#include "express/scope.h"
/* core */
#include "express/hash.h"
#include "express/linklist.h"
/* non-core */
#include "driver.h"
#include "fff.h"
/*
* mock globals
*/
char * EXPRESSprogram_name;
int yylineno;
int __SCOPE_search_id;
int ENTITY_MARK;
Dictionary EXPRESSbuiltins;
/*
* mock functions
*/
DEFINE_FFF_GLOBALS
FAKE_VALUE_FUNC(int, EXPRESS_fail, Express)
void setup() {
RESET_FAKE(EXPRESS_fail);
}
int test_scope_find() {
Schema scope;
Type sel, ent_base, chk_sel;
Entity ent, chk_ent;
Symbol *ent_id, *sel_id;
scope = SCHEMAcreate();
ent_id = SYMBOLcreate("ent", 1, "test_4");
sel_id = SYMBOLcreate("sel_typ", 1, "test_4");
ent_base = TYPEcreate_name(ent_id);
ent_base->superscope = scope;
ent = ENTITYcreate(ent_id);
ent->superscope = scope;
sel = TYPEcreate(select_);
sel->symbol = *sel_id;
sel->u.type->body->list = LISTcreate();
sel->superscope = scope;
LISTadd_last(sel->u.type->body->list, ent_base);
DICTdefine(scope->symbol_table, ent_id->name, ent, ent_id, OBJ_ENTITY);
DICTdefine(scope->symbol_table, sel_id->name, sel, sel_id, OBJ_TYPE);
scope->search_id = -1;
chk_sel = SCOPE_find(scope, "sel_typ", SCOPE_FIND_ENTITY | SCOPE_FIND_TYPE);
scope->search_id = -1;
chk_ent = SCOPE_find(scope, "ent", SCOPE_FIND_ENTITY | SCOPE_FIND_TYPE);
assert(chk_sel == sel);
assert(chk_ent == ent);
return 0;
}
struct test_def tests[] = {
{"scope_find", test_scope_find},
{NULL}
};