give buffer length to parser

This commit is contained in:
Aliaksei Chapyzhenka 2019-10-21 12:15:06 -07:00
parent 77c4f3ba94
commit 6311eeee17
2 changed files with 12 additions and 11 deletions

View File

@ -34,7 +34,8 @@ describe('basic', () => {
}); });
it('$version', done => { it('$version', done => {
const cxt = lib.init(); const cxt = lib.init();
expect(lib.execute(cxt, Buffer.from(` expect(lib.execute(cxt, Buffer.from(
`
$version Generated by VerilatedVcd $end $version Generated by VerilatedVcd $end
$date Wed Sep 18 22:59:07 2019 $date Wed Sep 18 22:59:07 2019
$end $end
@ -45,12 +46,12 @@ $timescale 1ns $end
$scope module leaf $end $scope module leaf $end
$var wire 64 "}> counter [63:0] $end $var wire 64 "}> counter [63:0] $end
$upscope $end $upscope $end
`))).to.eq(1); expect(lib.execute(cxt, Buffer.from(`
$upscope $end $upscope $end
$enddefinitions $end $enddefinitions $end
`
))).to.eq(0); expect(lib.execute(cxt, Buffer.from(
`
#1 #1
0"}G 0"}G
@ -58,9 +59,9 @@ $enddefinitions $end
1"}G 1"}G
#3 #3
0"}G 0"}G
`
`))).to.eq(1); ))).to.eq(0);
expect(lib.getError(cxt)).to.eq(1); expect(lib.getError(cxt)).to.eq(0);
// expect(lib.getReason(cxt)).to.eq('Expected simulation command'); // expect(lib.getReason(cxt)).to.eq('Expected simulation command');
// expect(lib.getCommand(cxt)).to.eq(100); // expect(lib.getCommand(cxt)).to.eq(100);
done(); done();

6
vcd.c
View File

@ -48,7 +48,7 @@
} \ } \
} }
#define ASSERT_BUFFER(name, var) \ #define ASSERT_BUFFER(name, var, len) \
const char * var; \ const char * var; \
size_t len; \ size_t len; \
{ \ { \
@ -81,9 +81,9 @@ METHOD(execute) {
ASSERT_ARGC(2) ASSERT_ARGC(2)
struct vcd_parser_s *state; struct vcd_parser_s *state;
ASSERT_EXTERNAL(args[0], state) ASSERT_EXTERNAL(args[0], state)
ASSERT_BUFFER(args[1], p) ASSERT_BUFFER(args[1], p, plen)
const int32_t error = vcd_parser_execute(state, p, NULL); const int32_t error = vcd_parser_execute(state, p, p + plen);
napi_value res; napi_value res;
ASSERT(res, napi_create_int32(env, error, &res)) ASSERT(res, napi_create_int32(env, error, &res))