diff --git a/packages/typegpu/tests/bufferUsage.test.ts b/packages/typegpu/tests/bufferUsage.test.ts index 224d4c877c..ab7c537854 100644 --- a/packages/typegpu/tests/bufferUsage.test.ts +++ b/packages/typegpu/tests/bufferUsage.test.ts @@ -145,6 +145,29 @@ describe('TgpuBufferMutable', () => { `); }); + 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 }) => { const buffer = root.createBuffer(d.u32, 0).$usage('storage'); @@ -260,6 +283,29 @@ describe('TgpuBufferReadonly', () => { `); }); + 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');