forked from GitHub/gf-core
Unmarshalling for floats and strings, but strings crashes after multiple invocations
This commit is contained in:
@@ -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],
|
const lflt = ffi.Callback(PgfLiteral, [PgfUnmarshaller, ref.types.double],
|
||||||
function (self, val: number): Pointer<Literal> {
|
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],
|
const lstr = ffi.Callback(PgfLiteral, [PgfUnmarshaller, PgfTextPtr],
|
||||||
function (self, val: Pointer<any>): Pointer<Literal> {
|
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)],
|
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
|
return 0 as any
|
||||||
})
|
})
|
||||||
|
|
||||||
const free_ref = ffi.Callback(ref.types.void, [PgfUnmarshaller, ref.refType(ref.types.void)],
|
const free_ref = ffi.Callback(ref.types.void, [PgfUnmarshaller, ref.refType(ref.types.Object)],
|
||||||
function (self, x: any): void {
|
function (self, x: Pointer<any>): void {
|
||||||
})
|
})
|
||||||
|
|
||||||
const un_vtbl = new PgfUnmarshallerVtbl({
|
const un_vtbl = new PgfUnmarshallerVtbl({
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ describe('abstract syntax', () => {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
describe('expressions', () => {
|
describe.only('expressions', () => {
|
||||||
test('small integer', () => {
|
test('small integer', () => {
|
||||||
const e1 = PGF.readExpr('123')
|
const e1 = PGF.readExpr('123')
|
||||||
const e2 = new PGF.ExprLit(123)
|
const e2 = new PGF.ExprLit(123)
|
||||||
@@ -253,4 +253,36 @@ describe('expressions', () => {
|
|||||||
expect(e1).toEqual(e2)
|
expect(e1).toEqual(e2)
|
||||||
expect(e1).not.toEqual(e3)
|
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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user