Unmarshalling for floats and strings, but strings crashes after multiple invocations

This commit is contained in:
John J. Camilleri
2021-10-07 23:25:25 +02:00
parent 16ee006735
commit 0d43ec8971
2 changed files with 44 additions and 5 deletions

View File

@@ -236,12 +236,19 @@ const lint = ffi.Callback(PgfLiteral, [PgfUnmarshaller, ref.types.size_t, ref.re
const lflt = ffi.Callback(PgfLiteral, [PgfUnmarshaller, ref.types.double],
function (self, val: number): Pointer<Literal> {
return 0 as any
const obj = new Literal(val)
const buf = ref.alloc(ref.types.Object) as Pointer<Literal>
ref.writeObject(buf, 0, obj)
return buf
})
const lstr = ffi.Callback(PgfLiteral, [PgfUnmarshaller, PgfTextPtr],
function (self, val: Pointer<any>): Pointer<Literal> {
return 0 as any
const jsval = PgfText_AsString(val)
const obj = new Literal(jsval)
const buf = ref.alloc(ref.types.Object) as Pointer<Literal>
ref.writeObject(buf, 0, obj)
return buf
})
const dtyp = ffi.Callback(PgfType, [PgfUnmarshaller, ref.types.int, PgfTypeHypoPtr, PgfTextPtr, ref.types.int, ref.refType(PgfExpr)],
@@ -249,8 +256,8 @@ const dtyp = ffi.Callback(PgfType, [PgfUnmarshaller, ref.types.int, PgfTypeHypoP
return 0 as any
})
const free_ref = ffi.Callback(ref.types.void, [PgfUnmarshaller, ref.refType(ref.types.void)],
function (self, x: any): void {
const free_ref = ffi.Callback(ref.types.void, [PgfUnmarshaller, ref.refType(ref.types.Object)],
function (self, x: Pointer<any>): void {
})
const un_vtbl = new PgfUnmarshallerVtbl({

View File

@@ -209,7 +209,7 @@ describe('abstract syntax', () => {
// ----------------------------------------------------------------------------
describe('expressions', () => {
describe.only('expressions', () => {
test('small integer', () => {
const e1 = PGF.readExpr('123')
const e2 = new PGF.ExprLit(123)
@@ -253,4 +253,36 @@ describe('expressions', () => {
expect(e1).toEqual(e2)
expect(e1).not.toEqual(e3)
})
test('float', () => {
const e1 = PGF.readExpr('3.142')
const e2 = new PGF.ExprLit(3.142)
const e3 = new PGF.ExprLit(2.014)
expect(e1).toEqual(e2)
expect(e1).not.toEqual(e3)
})
test('negative float', () => {
const e1 = PGF.readExpr('-3.142')
const e2 = new PGF.ExprLit(-3.142)
const e3 = new PGF.ExprLit(-2.014)
expect(e1).toEqual(e2)
expect(e1).not.toEqual(e3)
})
test('string', () => {
const e1 = PGF.readExpr('"abc"')
const e2 = new PGF.ExprLit('abc')
const e3 = new PGF.ExprLit('def')
expect(e1).toEqual(e2)
expect(e1).not.toEqual(e3)
})
test('string unicode', () => {
const e1 = PGF.readExpr('"açġħ"')
const e2 = new PGF.ExprLit('açġħ')
const e3 = new PGF.ExprLit('acgh')
expect(e1).toEqual(e2)
expect(e1).not.toEqual(e3)
})
})