MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / writeFixture

Function writeFixture

__tests__/c-fnptr-kernel-sweep.test.ts:67–160  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65 };
66
67 const writeFixture = () => {
68 // The git shape + designated init + assignment registration.
69 write('cmd.c', `
70struct cmd { const char *name; int (*fn)(int argc); };
71static int cmd_add(int argc) { return argc + 1; }
72static int cmd_rm(int argc) { return argc - 1; }
73static struct cmd commands[] = {
74 { "add", cmd_add },
75 { "rm", cmd_rm },
76};
77int run(int i, int argc) { return commands[i].fn(argc); }
78`);
79 // Macro-built table with an object-macro struct alias and a non-indexed
80 // include, redis-style; plus a typedef'd fn-TYPE field.
81 write('table.c', `
82#include "table.h"
83#include "cmds.def"
84int dispatch(struct client *c, int a) { return c->cur->proc(a); }
85`);
86 write('table.h', `
87typedef int cmdProc(int a);
88#define TBL_STRUCT redisCmd
89struct redisCmd { const char *name; cmdProc *proc; };
90struct client { struct redisCmd *cur; };
91#define MK(nm, fn) { nm, fn }
92static int getCmd(int a);
93static int setCmd(int a);
94`);
95 write('cmds.def', `
96struct TBL_STRUCT tbl[] = {
97 MK("get", getCmd),
98 MK("set", setCmd),
99};
100`);
101 write('impl.c', `
102#include "table.h"
103static int getCmd(int a) { return a; }
104static int setCmd(int a) { return a + 1; }
105`);
106 // #ifdef-guarded inline struct table + parenthesized subscript dispatch
107 // (the vim shape), switched on by the includer.
108 write('ex.c', `
109#define WANT_TABLE
110#include "ex_cmds.h"
111int exec(int i, int a) { return (cmdtab[i].cmd_fn)(a); }
112`);
113 write('ex_cmds.h', `
114#ifdef WANT_TABLE
115static int ex_quit(int a);
116struct excmd { char *nm; int (*cmd_fn)(int); } cmdtab[] = { { "q", ex_quit } };
117#endif
118`);
119 write('ex_impl.c', `static int ex_quit(int a) { return -a; }\n`);
120 // Bare arrays: fn-TYPE typedef with star, casts, index designators, and a
121 // same-named file-local collision (the SameBoy/Zend shapes).
122 write('ops.c', `
123typedef int op_t(int);
124static int nop(int x) { return x; }

Callers 1

Calls 2

writeFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected