javascript 0.1.13

A JavaScript engine implementation in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
use javascript::Value;
use javascript::evaluate_script;

// Initialize logger for this integration test binary so `RUST_LOG` is honored.
// Using `ctor` ensures initialization runs before tests start.
#[ctor::ctor]
fn __init_test_logger() {
    let _ = env_logger::Builder::from_env(env_logger::Env::default()).is_test(true).try_init();
}

#[cfg(test)]
mod number_tests {
    use super::*;

    #[test]
    fn test_number_max_value() {
        let script = "Number.MAX_VALUE";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, f64::MAX);
            }
            _ => panic!("Expected Number.MAX_VALUE to be f64::MAX, got {:?}", result),
        }
    }

    #[test]
    fn test_number_min_value() {
        let script = "Number.MIN_VALUE";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, f64::MIN_POSITIVE);
            }
            _ => panic!("Expected Number.MIN_VALUE to be f64::MIN_POSITIVE, got {:?}", result),
        }
    }

    #[test]
    fn test_number_nan() {
        let script = "Number.NaN";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert!(n.is_nan());
            }
            _ => panic!("Expected Number.NaN to be NaN, got {:?}", result),
        }
    }

    #[test]
    fn test_number_positive_infinity() {
        let script = "Number.POSITIVE_INFINITY";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, f64::INFINITY);
            }
            _ => panic!("Expected Number.POSITIVE_INFINITY to be f64::INFINITY, got {:?}", result),
        }
    }

    #[test]
    fn test_number_negative_infinity() {
        let script = "Number.NEGATIVE_INFINITY";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, f64::NEG_INFINITY);
            }
            _ => panic!("Expected Number.NEGATIVE_INFINITY to be f64::NEG_INFINITY, got {:?}", result),
        }
    }

    #[test]
    fn test_number_epsilon() {
        let script = "Number.EPSILON";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, f64::EPSILON);
            }
            _ => panic!("Expected Number.EPSILON to be f64::EPSILON, got {:?}", result),
        }
    }

    #[test]
    fn test_number_max_safe_integer() {
        let script = "Number.MAX_SAFE_INTEGER";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, 9007199254740991.0);
            }
            _ => panic!("Expected Number.MAX_SAFE_INTEGER to be 9007199254740991.0, got {:?}", result),
        }
    }

    #[test]
    fn test_number_min_safe_integer() {
        let script = "Number.MIN_SAFE_INTEGER";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, -9007199254740991.0);
            }
            _ => panic!("Expected Number.MIN_SAFE_INTEGER to be -9007199254740991.0, got {:?}", result),
        }
    }

    #[test]
    fn test_number_is_nan() {
        // Test with NaN
        let script = "Number.isNaN(NaN)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(b),
            _ => panic!("Expected Number.isNaN(NaN) to be true, got {:?}", result),
        }

        // Test with number
        let script = "Number.isNaN(42)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isNaN(42) to be false, got {:?}", result),
        }

        // Test with string that parses to NaN
        let script = "Number.isNaN('not a number')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b), // String is not NaN, it's just a string
            _ => panic!("Expected Number.isNaN('not a number') to be false, got {:?}", result),
        }

        // Test with undefined
        let script = "Number.isNaN(undefined)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isNaN(undefined) to be false, got {:?}", result),
        }
    }

    #[test]
    fn test_number_is_finite() {
        // Test with finite number
        let script = "Number.isFinite(42)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(b),
            _ => panic!("Expected Number.isFinite(42) to be true, got {:?}", result),
        }

        // Test with Infinity
        let script = "Number.isFinite(Infinity)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isFinite(Infinity) to be false, got {:?}", result),
        }

        // Test with NaN
        let script = "Number.isFinite(NaN)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isFinite(NaN) to be false, got {:?}", result),
        }

        // Test with string
        let script = "Number.isFinite('42')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isFinite('42') to be false, got {:?}", result),
        }
    }

    #[test]
    fn test_number_is_integer() {
        // Test with integer
        let script = "Number.isInteger(42)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(b),
            _ => panic!("Expected Number.isInteger(42) to be true, got {:?}", result),
        }

        // Test with float
        let script = "Number.isInteger(42.5)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isInteger(42.5) to be false, got {:?}", result),
        }

        // Test with Infinity
        let script = "Number.isInteger(Infinity)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isInteger(Infinity) to be false, got {:?}", result),
        }

        // Test with NaN
        let script = "Number.isInteger(NaN)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isInteger(NaN) to be false, got {:?}", result),
        }

        // Test with string
        let script = "Number.isInteger('42')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isInteger('42') to be false, got {:?}", result),
        }
    }

    #[test]
    fn test_number_is_safe_integer() {
        // Test with safe integer
        let script = "Number.isSafeInteger(42)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(b),
            _ => panic!("Expected Number.isSafeInteger(42) to be true, got {:?}", result),
        }

        // Test with MAX_SAFE_INTEGER
        let script = "Number.isSafeInteger(9007199254740991)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(b),
            _ => panic!("Expected Number.isSafeInteger(9007199254740991) to be true, got {:?}", result),
        }

        // Test with MIN_SAFE_INTEGER
        let script = "Number.isSafeInteger(-9007199254740991)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(b),
            _ => panic!("Expected Number.isSafeInteger(-9007199254740991) to be true, got {:?}", result),
        }

        // Test with unsafe integer (too large)
        let script = "Number.isSafeInteger(9007199254740992)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isSafeInteger(9007199254740992) to be false, got {:?}", result),
        }

        // Test with float
        let script = "Number.isSafeInteger(42.5)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isSafeInteger(42.5) to be false, got {:?}", result),
        }

        // Test with Infinity
        let script = "Number.isSafeInteger(Infinity)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Boolean(b)) => assert!(!b),
            _ => panic!("Expected Number.isSafeInteger(Infinity) to be false, got {:?}", result),
        }
    }

    #[test]
    fn test_number_parse_float() {
        // Test with valid float string
        let script = "Number.parseFloat('3.16')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 3.16),
            _ => panic!("Expected Number.parseFloat('3.16') to be 3.16, got {:?}", result),
        }

        // Test with integer string
        let script = "Number.parseFloat('42')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 42.0),
            _ => panic!("Expected Number.parseFloat('42') to be 42.0, got {:?}", result),
        }

        // Test with invalid string
        let script = "Number.parseFloat('not a number')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert!(n.is_nan()),
            _ => panic!("Expected Number.parseFloat('not a number') to be NaN, got {:?}", result),
        }

        // Test with number
        let script = "Number.parseFloat(42.5)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 42.5),
            _ => panic!("Expected Number.parseFloat(42.5) to be 42.5, got {:?}", result),
        }

        // Test with whitespace
        let script = "Number.parseFloat('  3.16  ')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 3.16),
            _ => panic!("Expected Number.parseFloat('  3.16  ') to be 3.16, got {:?}", result),
        }
    }

    #[test]
    fn test_shift_edge_cases_and_bigint_mixing() {
        // Left shift with large shift amount (masked by 0x1f)
        let res = evaluate_script("let a = 1; a <<= 33; a", None::<&std::path::Path>).unwrap();
        match res {
            Value::Number(n) => assert_eq!(n, 2.0),
            _ => panic!("Expected 2.0 for 1 <<= 33, got {:?}", res),
        }

        // Left shift with negative shift amount -> ToUint32(-1) & 0x1f == 31
        let res = evaluate_script("let a = 1; a <<= -1; a", None::<&std::path::Path>).unwrap();
        match res {
            Value::Number(n) => assert_eq!(n, -2147483648.0),
            _ => panic!("Expected -2147483648.0 for 1 <<= -1, got {:?}", res),
        }

        // Unsigned right shift on negative number
        let res = evaluate_script("let a = -1; a >>>= 1; a", None::<&std::path::Path>).unwrap();
        match res {
            Value::Number(n) => assert_eq!(n, 2147483647.0),
            _ => panic!("Expected 2147483647.0 for -1 >>>= 1, got {:?}", res),
        }

        // Mixing BigInt with Number in shift should throw TypeError
        let res = evaluate_script("let a = 1n; let b = 2; a <<= b", None::<&std::path::Path>);
        match res {
            Err(err) => match err.kind() {
                javascript::JSErrorKind::TypeError { message, .. } => assert!(message.contains("Cannot mix BigInt")),
                _ => panic!("Expected TypeError for mixing BigInt and Number in <<=, got {:?}", err),
            },
            other => panic!("Expected TypeError for mixing BigInt and Number in <<=, got {:?}", other),
        }

        // Unsigned right shift on BigInt should throw TypeError with specific message
        let res = evaluate_script("let a = 1n; a >>>= 1n", None::<&std::path::Path>);
        match res {
            Err(err) => match err.kind() {
                javascript::JSErrorKind::TypeError { message, .. } => assert!(message.contains("Unsigned right shift")),
                _ => panic!("Expected TypeError for BigInt >>>=, got {:?}", err),
            },
            other => panic!("Expected TypeError for BigInt >>>=, got {:?}", other),
        }
    }

    #[test]
    fn test_bigint_shift_and_bitwise_mixing_errors() {
        // Huge BigInt shift amount should produce an evaluation error (invalid bigint shift)
        let res = evaluate_script(
            "let a = 1n; a <<= 100000000000000000000000000000000000000n",
            None::<&std::path::Path>,
        );
        match res {
            Err(err) => match err.kind() {
                javascript::JSErrorKind::EvaluationError { message, .. } => {
                    assert!(
                        message.contains("invalid bigint shift") || message.contains("invalid bigint"),
                        "message={}",
                        message
                    )
                }
                _ => panic!("Expected EvaluationError for huge BigInt shift, got {:?}", err),
            },
            other => panic!("Expected EvaluationError for huge BigInt shift, got {:?}", other),
        }

        // Negative BigInt shift (e.g. -1n) should also error when converting to usize
        let res = evaluate_script("let a = 1n; a <<= -1n", None::<&std::path::Path>);
        match res {
            Err(err) => match err.kind() {
                javascript::JSErrorKind::EvaluationError { message, .. } => {
                    assert!(
                        message.contains("invalid bigint shift") || message.contains("invalid bigint"),
                        "message={}",
                        message
                    )
                }
                _ => panic!("Expected EvaluationError for negative BigInt shift, got {:?}", err),
            },
            other => panic!("Expected EvaluationError for negative BigInt shift, got {:?}", other),
        }

        // Mixing BigInt and Number in bitwise XOR should throw TypeError
        let res = evaluate_script("let a = 1n; let b = 2; a ^= b", None::<&std::path::Path>);
        match res {
            Err(err) => match err.kind() {
                javascript::JSErrorKind::TypeError { message, .. } => assert!(message.contains("Cannot mix BigInt")),
                _ => panic!("Expected TypeError for BigInt ^ Number mixing, got {:?}", err),
            },
            other => panic!("Expected TypeError for BigInt ^ Number mixing, got {:?}", other),
        }
    }

    #[test]
    fn test_number_parse_int() {
        // Test with valid integer string
        let script = "Number.parseInt('42')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 42.0),
            _ => panic!("Expected Number.parseInt('42') to be 42.0, got {:?}", result),
        }

        // Test with float string (should truncate)
        let script = "Number.parseInt('42.5')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 42.0),
            _ => panic!("Expected Number.parseInt('42.5') to be 42.0, got {:?}", result),
        }

        // Test with invalid string
        let script = "Number.parseInt('not a number')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert!(n.is_nan()),
            _ => panic!("Expected Number.parseInt('not a number') to be NaN, got {:?}", result),
        }

        // Test with radix
        let script = "Number.parseInt('101', 2)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 5.0), // 101 in binary is 5
            _ => panic!("Expected Number.parseInt('101', 2) to be 5.0, got {:?}", result),
        }

        // Test with hex
        let script = "Number.parseInt('FF', 16)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 255.0),
            _ => panic!("Expected Number.parseInt('FF', 16) to be 255.0, got {:?}", result),
        }

        // Test with number
        let script = "Number.parseInt(42.7)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 42.0),
            _ => panic!("Expected Number.parseInt(42.7) to be 42.0, got {:?}", result),
        }
    }

    #[test]
    fn test_number_constructor_no_args() {
        let script = "Number()";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 0.0),
            _ => panic!("Expected Number() to be 0.0, got {:?}", result),
        }
    }

    #[test]
    fn test_number_constructor_with_number() {
        let script = "Number(42.5)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 42.5),
            _ => panic!("Expected Number(42.5) to be 42.5, got {:?}", result),
        }
    }

    #[test]
    fn test_number_constructor_with_string() {
        let script = "Number('42.5')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 42.5),
            _ => panic!("Expected Number('42.5') to be 42.5, got {:?}", result),
        }
    }

    #[test]
    fn test_number_constructor_with_boolean() {
        let script = "Number(true)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 1.0),
            _ => panic!("Expected Number(true) to be 1.0, got {:?}", result),
        }

        let script = "Number(false)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert_eq!(n, 0.0),
            _ => panic!("Expected Number(false) to be 0.0, got {:?}", result),
        }
    }

    #[test]
    fn test_number_constructor_with_invalid_string() {
        let script = "Number('not a number')";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert!(n.is_nan()),
            _ => panic!("Expected Number('not a number') to be NaN, got {:?}", result),
        }
    }

    #[test]
    fn test_number_constructor_with_undefined() {
        let script = "Number(undefined)";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => assert!(n.is_nan()),
            _ => panic!("Expected Number(undefined) to be NaN, got {:?}", result),
        }
    }

    #[test]
    fn test_number_object_properties_exist() {
        // Test that all expected properties exist on the Number object
        let properties = vec![
            "MAX_VALUE",
            "MIN_VALUE",
            "NaN",
            "POSITIVE_INFINITY",
            "NEGATIVE_INFINITY",
            "EPSILON",
            "MAX_SAFE_INTEGER",
            "MIN_SAFE_INTEGER",
            "isNaN",
            "isFinite",
            "isInteger",
            "isSafeInteger",
            "parseFloat",
            "parseInt",
        ];

        for prop in properties {
            let script = format!("typeof Number.{}", prop);
            let result = evaluate_script(&script, None::<&std::path::Path>);
            match result {
                Ok(Value::String(s)) => {
                    let type_str = String::from_utf16_lossy(&s);
                    assert_ne!(type_str, "undefined", "Number.{} should exist", prop);
                }
                _ => panic!("Expected typeof Number.{} to return a string, got {:?}", prop, result),
            }
        }
    }

    #[test]
    fn test_bitwise_xor_numbers() {
        let script = "5 ^ 3";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, 6.0); // 5 ^ 3 = 6
            }
            _ => panic!("Expected 5 ^ 3 to evaluate to 6, got {:?}", result),
        }
    }

    #[test]
    fn test_bitwise_xor_negative_numbers() {
        let script = "-5 ^ 3";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, -8.0); // -5 ^ 3 = -8
            }
            _ => panic!("Expected -5 ^ 3 to evaluate to -8, got {:?}", result),
        }
    }

    #[test]
    fn test_bitwise_xor_assignment() {
        let script = "let a = 5; a ^= 3; a";
        let result = evaluate_script(script, None::<&std::path::Path>);
        match result {
            Ok(Value::Number(n)) => {
                assert_eq!(n, 6.0); // a = 5; a ^= 3; a = 6
            }
            _ => panic!("Expected a ^= 3 to evaluate to 6, got {:?}", result),
        }
    }

    #[test]
    fn test_bitwise_compound_assignments() {
        // Test bitwise AND assignment (&=)
        let script1 = "let a = 5; a &= 3; a";
        let result1 = evaluate_script(script1, None::<&std::path::Path>);
        assert!(
            result1.is_ok(),
            "evaluate_script(script1, None::<&std::path::Path>) failed: {:?}",
            result1
        );
        match result1 {
            Ok(Value::Number(n)) => assert_eq!(n, 1.0), // 5 & 3 = 1
            _ => panic!("Expected 1.0, got {:?}", result1),
        }

        // Test bitwise OR assignment (|=)
        let script2 = "let b = 5; b |= 3; b";
        let result2 = evaluate_script(script2, None::<&std::path::Path>);
        assert!(
            result2.is_ok(),
            "evaluate_script(script2, None::<&std::path::Path>) failed: {:?}",
            result2
        );
        match result2 {
            Ok(Value::Number(n)) => assert_eq!(n, 7.0), // 5 | 3 = 7
            _ => panic!("Expected 7.0, got {:?}", result2),
        }

        // Test bitwise XOR assignment (^=)
        let script3 = "let c = 5; c ^= 3; c";
        let result3 = evaluate_script(script3, None::<&std::path::Path>);
        assert!(
            result3.is_ok(),
            "evaluate_script(script3, None::<&std::path::Path>) failed: {:?}",
            result3
        );
        match result3 {
            Ok(Value::Number(n)) => assert_eq!(n, 6.0), // 5 ^ 3 = 6
            _ => panic!("Expected 6.0, got {:?}", result3),
        }

        // Test left shift assignment (<<=)
        let script4 = "let d = 5; d <<= 1; d";
        let result4 = evaluate_script(script4, None::<&std::path::Path>);
        assert!(
            result4.is_ok(),
            "evaluate_script(script4, None::<&std::path::Path>) failed: {:?}",
            result4
        );
        match result4 {
            Ok(Value::Number(n)) => assert_eq!(n, 10.0), // 5 << 1 = 10
            _ => panic!("Expected 10.0, got {:?}", result4),
        }

        // Test right shift assignment (>>=)
        let script5 = "let e = 5; e >>= 1; e";
        let result5 = evaluate_script(script5, None::<&std::path::Path>);
        assert!(
            result5.is_ok(),
            "evaluate_script(script5, None::<&std::path::Path>) failed: {:?}",
            result5
        );
        match result5 {
            Ok(Value::Number(n)) => assert_eq!(n, 2.0), // 5 >> 1 = 2
            _ => panic!("Expected 2.0, got {:?}", result5),
        }

        // Test unsigned right shift assignment (>>>=)
        let script6 = "let f = -5; f >>>= 1; f";
        let result6 = evaluate_script(script6, None::<&std::path::Path>);
        assert!(
            result6.is_ok(),
            "evaluate_script(script6, None::<&std::path::Path>) failed: {:?}",
            result6
        );
        match result6 {
            Ok(Value::Number(n)) => assert_eq!(n, 2147483645.0), // -5 >>> 1 = 2147483645
            _ => panic!("Expected 2147483645.0, got {:?}", result6),
        }
    }
}