Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
theweipeng committed Jan 23, 2024
1 parent 902ee0c commit a107c92
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 82 deletions.
51 changes: 21 additions & 30 deletions javascript/test/reader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,33 @@
* under the License.
*/

import { alloc } from '@furyjs/fury/lib/platformBuffer';
import { BinaryReader } from '@furyjs/fury/lib/reader';
import { Config } from '@furyjs/fury/lib/type';
import { BinaryWriter } from '@furyjs/fury/lib/writer';
import { alloc } from '../packages/fury/lib/platformBuffer';
import { BinaryReader } from '../packages/fury/lib/reader';
import { BinaryWriter } from '../packages/fury/lib/writer';
import { describe, expect, test } from '@jest/globals';
const hps = process.env.enableHps ? require('@furyjs/hps') : null;


describe('writer', () => {
test('should uint8 work', () => {
const writer = BinaryWriter({});
{
writer.uint8(10);
var ab = writer.dump();
expect(ab.byteLength).toBe(1);
expect(ab[0]).toBe(10);
expect(writer.getCursor()).toBe(1);
}

[
{
hps,
}
].forEach((config: Config) => {
describe('writer', () => {
test('should uint8 work', () => {
const writer = BinaryWriter(config);
{
writer.uint8(10);
var ab = writer.dump();
expect(ab.byteLength).toBe(1);
expect(ab[0]).toBe(10);
expect(writer.getCursor()).toBe(1);
}
{
writer.uint8(256);
var ab = writer.dump();

{
writer.uint8(256);
var ab = writer.dump();

expect(ab.byteLength).toBe(2);
expect(ab[1]).toBe(0);
expect(writer.getCursor()).toBe(2);
}
});
expect(ab.byteLength).toBe(2);
expect(ab[1]).toBe(0);
expect(writer.getCursor()).toBe(2);
}
});
})
});


describe('reader', () => {
Expand Down
91 changes: 41 additions & 50 deletions javascript/test/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,47 @@

import Fury, { TypeDescription, InternalSerializerType, Type } from '../packages/fury/index';
import {describe, expect, test} from '@jest/globals';
const hps = require('@furyjs/hps');
[
{
hps,
},
{
hps: null,
}
].forEach(config => {
describe('string', () => {
test('should latin1 string work', () => {

const fury = new Fury(config);
const input = fury.serialize("123")
const result = fury.deserialize(
input
);
expect(result).toEqual("123")
});

test('should utf8 string work', () => {

const fury = new Fury(config);
const input = fury.serialize("我是Fury, 你好!😁א")
const result = fury.deserialize(
input
);
expect(result).toEqual("我是Fury, 你好!😁א")
});

test('should long latin1 string work', () => {
const str = new Array(100).fill("123").join();
const fury = new Fury(config);
const input = fury.serialize(str)
const result = fury.deserialize(
input
);
expect(result).toEqual(str)
});

test('should long utf8 string work', () => {
const str = new Array(10).fill("我是Fury, 你好!😁א").join();
const fury = new Fury(config);
const input = fury.serialize(str)
const result = fury.deserialize(
input
);
expect(result).toEqual(str)
});
const config = {};

describe('string', () => {
test('should latin1 string work', () => {

const fury = new Fury(config);
const input = fury.serialize("123")
const result = fury.deserialize(
input
);
expect(result).toEqual("123")
});

test('should utf8 string work', () => {

const fury = new Fury(config);
const input = fury.serialize("我是Fury, 你好!😁א")
const result = fury.deserialize(
input
);
expect(result).toEqual("我是Fury, 你好!😁א")
});

})

test('should long latin1 string work', () => {
const str = new Array(100).fill("123").join();
const fury = new Fury(config);
const input = fury.serialize(str)
const result = fury.deserialize(
input
);
expect(result).toEqual(str)
});

test('should long utf8 string work', () => {
const str = new Array(10).fill("我是Fury, 你好!😁א").join();
const fury = new Fury(config);
const input = fury.serialize(str)
const result = fury.deserialize(
input
);
expect(result).toEqual(str)
});
});
4 changes: 2 additions & 2 deletions javascript/test/writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { OwnershipError } from '@furyjs/fury/lib/error';
import { BinaryWriter } from '@furyjs/fury/lib/writer';
import { OwnershipError } from '../packages/fury/lib/error';
import { BinaryWriter } from '../packages/fury/lib/writer';
import { describe, expect, test } from '@jest/globals';

describe('writer', () => {
Expand Down

0 comments on commit a107c92

Please sign in to comment.