Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/typegpu/tests/bufferUsage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,31 @@
`);
});

it('cannot be mutated (primitive)', ({ root }) => {
const foo = root.createUniform(d.f32);

const main = () => {
'use gpu';
// @ts-expect-error
foo.$ += 1;
};

expect(() => tgpu.resolve([main])).toThrowErrorMatchingInlineSnapshot();
});

it('cannot be mutated (non-primitive)', ({ root }) => {
const foo = root.createUniform(d.vec3f);

const main = () => {
'use gpu';
foo.$.x += 1;
};

expect(() => tgpu.resolve([main])).toThrowErrorMatchingInlineSnapshot();
});

describe('simulate mode', () => {
it('allows accessing .$ in simulate mode', ({ root }) => {

Check failure on line 172 in packages/typegpu/tests/bufferUsage.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

tests/bufferUsage.test.ts > TgpuBufferMutable > cannot be mutated (primitive)

Error: snapshot function didn't throw ❯ tests/bufferUsage.test.ts:172:40
const buffer = root.createBuffer(d.u32, 0).$usage('storage');
const mutable = buffer.as('mutable');

Expand All @@ -157,7 +180,7 @@
});

const result = tgpu['~unstable'].simulate(() => {
incrementThreeTimes();

Check failure on line 183 in packages/typegpu/tests/bufferUsage.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

tests/bufferUsage.test.ts > TgpuBufferMutable > cannot be mutated (non-primitive)

Error: snapshot function didn't throw ❯ tests/bufferUsage.test.ts:183:40
return mutable.$;
});
expect(result.value).toBe(3);
Expand Down Expand Up @@ -260,6 +283,29 @@
`);
});

it('cannot be mutated (primitive)', ({ root }) => {
const foo = root.createReadonly(d.f32);

const main = () => {
'use gpu';
// @ts-expect-error
foo.$ += 1;
};

expect(() => tgpu.resolve([main])).toThrowErrorMatchingInlineSnapshot();
});

it('cannot be mutated (non-primitive)', ({ root }) => {
const foo = root.createReadonly(d.vec3f);

const main = () => {
'use gpu';
foo.$.x += 1;
};

expect(() => tgpu.resolve([main])).toThrowErrorMatchingInlineSnapshot();
});

describe('simulate mode', () => {
it('allows accessing .$ in simulate mode', ({ root }) => {
const buffer = root.createBuffer(d.f32, 123).$usage('storage');
Expand All @@ -276 +322 @@
});
Loading