do not copy string chunk
This commit is contained in:
parent
592ae7779a
commit
77c4f3ba94
@ -16,14 +16,16 @@ describe('basic', () => {
|
||||
});
|
||||
it('fail: foo bar', done => {
|
||||
const cxt = lib.init();
|
||||
expect(lib.execute(cxt, ' foo bar ???', '')).to.eq(1);
|
||||
expect(lib.execute(cxt, Buffer.from(' foo bar ???'))).to.eq(1);
|
||||
expect(lib.getError(cxt)).to.eq(1);
|
||||
expect(lib.getReason(cxt)).to.eq('Expected declaration command');
|
||||
done();
|
||||
});
|
||||
it('$comment', done => {
|
||||
const cxt = lib.init();
|
||||
expect(lib.execute(cxt, ' \n $comment some text $end $comment more text $end ???', '')).to.eq(1);
|
||||
expect(lib.execute(cxt, Buffer.from(
|
||||
' \n $comment some text $end $comment more text $end ???'
|
||||
))).to.eq(1);
|
||||
expect(lib.getError(cxt)).to.eq(1);
|
||||
expect(lib.getReason(cxt)).to.eq('Expected declaration command');
|
||||
expect(lib.getCommand(cxt)).to.eq(1);
|
||||
@ -32,7 +34,7 @@ describe('basic', () => {
|
||||
});
|
||||
it('$version', done => {
|
||||
const cxt = lib.init();
|
||||
expect(lib.execute(cxt, `
|
||||
expect(lib.execute(cxt, Buffer.from(`
|
||||
$version Generated by VerilatedVcd $end
|
||||
$date Wed Sep 18 22:59:07 2019
|
||||
$end
|
||||
@ -43,7 +45,9 @@ $timescale 1ns $end
|
||||
$scope module leaf $end
|
||||
$var wire 64 "}> counter [63:0] $end
|
||||
$upscope $end
|
||||
`, null)).to.eq(1); expect(lib.execute(cxt, `
|
||||
|
||||
`))).to.eq(1); expect(lib.execute(cxt, Buffer.from(`
|
||||
|
||||
$upscope $end
|
||||
|
||||
$enddefinitions $end
|
||||
@ -55,7 +59,7 @@ $enddefinitions $end
|
||||
#3
|
||||
0"}G
|
||||
|
||||
`, null)).to.eq(1);
|
||||
`))).to.eq(1);
|
||||
expect(lib.getError(cxt)).to.eq(1);
|
||||
// expect(lib.getReason(cxt)).to.eq('Expected simulation command');
|
||||
// expect(lib.getCommand(cxt)).to.eq(100);
|
||||
|
37
vcd.c
37
vcd.c
@ -32,21 +32,6 @@
|
||||
} \
|
||||
}
|
||||
|
||||
#define ASSERT_STRING(name, var) \
|
||||
char var[4096]; \
|
||||
{ \
|
||||
napi_value tmp; \
|
||||
if (napi_coerce_to_string(env, name, &tmp) != napi_ok) { \
|
||||
napi_throw(env, name); \
|
||||
return 0; \
|
||||
} \
|
||||
size_t result; \
|
||||
if (napi_get_value_string_latin1(env, tmp, var, 4096, &result) != napi_ok) { \
|
||||
napi_throw(env, name); \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ASSERT_EXTERNAL(name, var) { \
|
||||
napi_valuetype valuetype; \
|
||||
if (napi_typeof(env, name, &valuetype) != napi_ok) { \
|
||||
@ -63,6 +48,21 @@
|
||||
} \
|
||||
}
|
||||
|
||||
#define ASSERT_BUFFER(name, var) \
|
||||
const char * var; \
|
||||
size_t len; \
|
||||
{ \
|
||||
bool result; \
|
||||
if(napi_is_buffer(env, name, &result) != napi_ok) { \
|
||||
napi_throw(env, name); \
|
||||
return 0; \
|
||||
} \
|
||||
if (napi_get_buffer_info(env, name, (void **)&var, &len) != napi_ok) { \
|
||||
napi_throw(env, name); \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
METHOD(init) {
|
||||
struct vcd_parser_s *state = malloc(sizeof *state);
|
||||
|
||||
@ -78,13 +78,12 @@ METHOD(init) {
|
||||
}
|
||||
|
||||
METHOD(execute) {
|
||||
ASSERT_ARGC(3)
|
||||
ASSERT_ARGC(2)
|
||||
struct vcd_parser_s *state;
|
||||
ASSERT_EXTERNAL(args[0], state)
|
||||
ASSERT_STRING(args[1], p)
|
||||
ASSERT_STRING(args[2], endp)
|
||||
ASSERT_BUFFER(args[1], p)
|
||||
|
||||
const int32_t error = vcd_parser_execute(state, p, endp);
|
||||
const int32_t error = vcd_parser_execute(state, p, NULL);
|
||||
|
||||
napi_value res;
|
||||
ASSERT(res, napi_create_int32(env, error, &res))
|
||||
|
Loading…
x
Reference in New Issue
Block a user