7 #ifndef _CEPTR_TEST_PROFILE_EXAMPLE_H
8 #define _CEPTR_TEST_PROFILE_EXAMPLE_H
10 #include "../src/ceptr.h"
11 #include "../src/receptor.h"
12 #include "../src/def.h"
13 #include "../src/semtrex.h"
37 void _setupProfileDefs() {
40 SY(r,FIRST_NAME,CSTRING);
41 SY(r,LAST_NAME,CSTRING);
46 SY(r,PROFILE_NAME,NAME);
48 SY(r,STREET_ADDRESS,CSTRING);
52 SY(r,COUNTRY,CSTRING);
61 SY(r,PROFILE_ADDRESS,ADDRESS);
63 SY(r,PROFILE_EMAIL,CSTRING);
68 SY(r,USER_PROFILE,PROFILE);
70 SY(r,MAILING_LABEL,CSTRING);
73 void _cleanupProfileDefs() {
77 void testProfileExample() {
80 T *n = _t_newr(t,PROFILE_NAME);
81 T *a = _t_newr(t,PROFILE_ADDRESS);
82 T *e = _t_new_str(t,PROFILE_EMAIL,
"test@example.com");
83 _t_new_str(n,FIRST_NAME,
"Jane");
84 _t_new_str(n,LAST_NAME,
"Smith");
85 _t_new_str(a,STREET_ADDRESS,
"126 Main Street");
86 _t_new_str(a,CITY,
"Smallville");
87 _t_new_str(a,STATE,
"CA");
88 _t_new_str(a,ZIP,
"12345");
89 _t_new_str(a,COUNTRY,
"USA");
92 wjson(sem,t,
"user_profile",-1);
94 spec_is_str_equal(t2s(t),
"(USER_PROFILE (PROFILE_NAME (FIRST_NAME:Jane) (LAST_NAME:Smith)) (PROFILE_ADDRESS (STREET_ADDRESS:126 Main Street) (CITY:Smallville) (STATE:CA) (ZIP:12345) (COUNTRY:USA)) (PROFILE_EMAIL:test@example.com))");
96 T *signature = __p_make_signature(
"result",SIGNATURE_SYMBOL,NULL_SYMBOL,
97 "mailing_profile",SIGNATURE_STRUCTURE,CSTRING,
98 "the_int?",SIGNATURE_STRUCTURE,INTEGER,
99 "the_profile",SIGNATURE_STRUCTURE,PROFILE,
104 int pt1[] = {2,1,1,1,TREE_PATH_TERMINATOR};
105 int pt2[] = {2,1,1,2,TREE_PATH_TERMINATOR};
106 int pt3[] = {2,1,2,1,TREE_PATH_TERMINATOR};
107 int pt4[] = {2,1,2,2,TREE_PATH_TERMINATOR};
108 int pt5[] = {2,1,2,3,TREE_PATH_TERMINATOR};
109 int pt6[] = {2,1,2,4,TREE_PATH_TERMINATOR};
111 _t_news(code,RESULT_SYMBOL,MAILING_LABEL);
112 T *c = _t_newr(code,CONCAT_STR);
114 _t_new(c,PARAM_REF,pt1,
sizeof(
int)*5);
115 _t_new_str(c,TEST_STR_SYMBOL,
" ");
116 _t_new(c,PARAM_REF,pt2,
sizeof(
int)*5);
117 _t_new_str(code,TEST_STR_SYMBOL,
"\\n");
118 _t_new(code,PARAM_REF,pt3,
sizeof(
int)*5);
119 _t_new_str(code,TEST_STR_SYMBOL,
"\\n");
120 c = _t_newr(code,CONCAT_STR);
122 _t_new(c,PARAM_REF,pt4,
sizeof(
int)*5);
123 _t_new_str(c,TEST_STR_SYMBOL,
", ");
124 _t_new(c,PARAM_REF,pt5,
sizeof(
int)*5);
125 _t_new_str(c,TEST_STR_SYMBOL,
" ");
126 _t_new(c,PARAM_REF,pt6,
sizeof(
int)*5);
130 Process p =
_d_define_process(sem,code,
"profileToMailingLabel",
"given a profile produce a mailing label",signature,NULL,test_profile_receptor->
context);
136 wjson(sem,r,
"profile",0);
140 startVisdump(
"profile");
141 spec_is_equal(
_p_reduce(sem,r),noReductionErr);
142 int pt[] = {TREE_PATH_TERMINATOR};
147 spec_is_str_equal(t2s(
_t_child(r,1)),
"(MAILING_LABEL:Jane Smith\\n126 Main Street\\nSmallville, CA 12345)");
150 _cleanupProfileDefs();
T * _t_new_root(Symbol symbol)
Process _d_define_process(SemTable *sem, T *code, char *name, char *intention, T *signature, T *link, Context c)
void _r_free(Receptor *r)
T * _t_child(T *t, int i)
Context context
the context this receptor's definition creates
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
Error _p_reduce(SemTable *sem, T *rt)
T * _p_make_run_tree(SemTable *sem, Process p, T *params, T *sem_map)