@@ -121,9 +121,6 @@ describe('not', () => {
121121
122122 expect ( tgpu . resolve ( [ f ] ) ) . toMatchInlineSnapshot ( `
123123 "fn f() -> i32 {
124- if (((false && true) && false)) {
125- return 1;
126- }
127124 return -1;
128125 }"
129126 ` ) ;
@@ -153,4 +150,110 @@ describe('not', () => {
153150 }"
154151 ` ) ;
155152 } ) ;
153+
154+ it ( 'converts numeric vectors to boolean vectors and negates component-wise' , ( ) => {
155+ expect ( not ( d . vec2f ( 0.0 , 1.0 ) ) ) . toStrictEqual ( d . vec2b ( true , false ) ) ;
156+ expect ( not ( d . vec3i ( 0 , 5 , - 1 ) ) ) . toStrictEqual ( d . vec3b ( true , false , false ) ) ;
157+ expect ( not ( d . vec4u ( 0 , 0 , 1 , 0 ) ) ) . toStrictEqual ( d . vec4b ( true , true , false , true ) ) ;
158+ expect ( not ( d . vec4h ( 0 , 3.14 , 0 , - 2.5 ) ) ) . toStrictEqual ( d . vec4b ( true , false , true , false ) ) ;
159+ } ) ;
160+
161+ it ( 'negates truthiness check' , ( ) => {
162+ const s = { } ;
163+ expect ( not ( null ) ) . toBe ( true ) ;
164+ expect ( not ( undefined ) ) . toBe ( true ) ;
165+ expect ( not ( s ) ) . toBe ( false ) ;
166+ } ) ;
167+
168+ it ( 'mimics WGSL behavior on NaN' , ( ) => {
169+ expect ( not ( NaN ) ) . toBe ( false ) ;
170+ } ) ;
171+
172+ it ( 'generates correct WGSL on a boolean runtime-known argument' , ( ) => {
173+ const testFn = tgpu . fn (
174+ [ d . bool ] ,
175+ d . bool ,
176+ ) ( ( v ) => {
177+ return not ( v ) ;
178+ } ) ;
179+ expect ( tgpu . resolve ( [ testFn ] ) ) . toMatchInlineSnapshot ( `
180+ "fn testFn(v: bool) -> bool {
181+ return !v;
182+ }"
183+ ` ) ;
184+ } ) ;
185+
186+ it ( 'generates correct WGSL on a numeric runtime-known argument' , ( ) => {
187+ const testFn = tgpu . fn (
188+ [ d . i32 ] ,
189+ d . bool ,
190+ ) ( ( v ) => {
191+ return not ( v ) ;
192+ } ) ;
193+ expect ( tgpu . resolve ( [ testFn ] ) ) . toMatchInlineSnapshot ( `
194+ "fn testFn(v: i32) -> bool {
195+ return !bool(v);
196+ }"
197+ ` ) ;
198+ } ) ;
199+
200+ it ( 'generates correct WGSL on a boolean vector runtime-known argument' , ( ) => {
201+ const testFn = tgpu . fn (
202+ [ d . vec3b ] ,
203+ d . vec3b ,
204+ ) ( ( v ) => {
205+ return not ( v ) ;
206+ } ) ;
207+ expect ( tgpu . resolve ( [ testFn ] ) ) . toMatchInlineSnapshot ( `
208+ "fn testFn(v: vec3<bool>) -> vec3<bool> {
209+ return !(v);
210+ }"
211+ ` ) ;
212+ } ) ;
213+
214+ it ( 'generates correct WGSL on a numeric vector runtime-known argument' , ( ) => {
215+ const testFn = tgpu . fn (
216+ [ d . vec3f ] ,
217+ d . vec3b ,
218+ ) ( ( v ) => {
219+ return not ( v ) ;
220+ } ) ;
221+ expect ( tgpu . resolve ( [ testFn ] ) ) . toMatchInlineSnapshot ( `
222+ "fn testFn(v: vec3f) -> vec3<bool> {
223+ return !(vec3<bool>(v));
224+ }"
225+ ` ) ;
226+ } ) ;
227+
228+ it ( 'generates correct WGSL on a numeric vector comptime-known argument' , ( ) => {
229+ const f = ( ) => {
230+ 'use gpu' ;
231+ const v = not ( d . vec4f ( Infinity , - Infinity , 0 , NaN ) ) ;
232+ } ;
233+
234+ expect ( tgpu . resolve ( [ f ] ) ) . toMatchInlineSnapshot ( `
235+ "fn f() {
236+ var v = vec4<bool>(false, false, true, false);
237+ }"
238+ ` ) ;
239+ } ) ;
240+
241+ it ( 'evaluates at compile time for comptime-known arguments' , ( ) => {
242+ const getN = tgpu . comptime ( ( ) => 42 ) ;
243+ const slot = tgpu . slot < { a ?: number } > ( { } ) ;
244+
245+ const f = ( ) => {
246+ 'use gpu' ;
247+ if ( not ( getN ( ) ) && not ( slot . $ . a ) && not ( d . vec4f ( 1 , 8 , 8 , 2 ) ) . x ) {
248+ return 1 ;
249+ }
250+ return - 1 ;
251+ } ;
252+
253+ expect ( tgpu . resolve ( [ f ] ) ) . toMatchInlineSnapshot ( `
254+ "fn f() -> i32 {
255+ return -1;
256+ }"
257+ ` ) ;
258+ } ) ;
156259} ) ;
0 commit comments