Skip to content

Commit 2e93e6f

Browse files
More textDecoder tests
1 parent 3794fde commit 2e93e6f

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Tests/UnitTests/Scripts/tests.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,21 @@ describe("XMLHTTPRequest", function () {
196196
var response = new Uint8Array(xhr.response);
197197
expect(response).to.eql(expected);
198198
});
199+
200+
it("should load a PLY file and parse vertex count from header using TextDecoder", async function () {
201+
this.timeout(30000);
202+
const xhr = await createRequest("GET", "https://assets.babylonjs.com/splats/Halo_Believe.ply", undefined, "arraybuffer");
203+
expect(xhr.status).to.equal(200);
204+
205+
const ubuf = new Uint8Array(xhr.response);
206+
const header = new TextDecoder().decode(ubuf.slice(0, 1024 * 10));
207+
const headerEnd = "end_header\n";
208+
const headerEndIndex = header.indexOf(headerEnd);
209+
expect(headerEndIndex).to.be.greaterThan(0);
210+
211+
const vertexCount = parseInt(/element vertex (\d+)\n/.exec(header)![1]);
212+
expect(vertexCount).to.equal(345217);
213+
});
199214
});
200215

201216
describe("setTimeout", function () {
@@ -1268,6 +1283,14 @@ describe("TextDecoder", function () {
12681283
const result = decoder.decode(sub);
12691284
expect(result).to.equal("Hi");
12701285
});
1286+
1287+
it("should decode a Uint8Array containing a null byte", function () {
1288+
const decoder = new TextDecoder();
1289+
const encoded = new Uint8Array([72, 0, 105]); // "H\0i"
1290+
const result = decoder.decode(encoded);
1291+
expect(result).to.equal("H\0i");
1292+
expect(result.length).to.equal(3);
1293+
});
12711294
});
12721295

12731296
function runTests() {

0 commit comments

Comments
 (0)