@@ -416,3 +416,156 @@ fn to_string_tag() {
416
416
)
417
417
. test ( ) ;
418
418
}
419
+
420
+ #[ test]
421
+ fn for_ ( ) {
422
+ project ( )
423
+ . file (
424
+ "src/lib.rs" ,
425
+ r#"
426
+ #![feature(proc_macro, wasm_custom_section)]
427
+
428
+ extern crate wasm_bindgen;
429
+ use wasm_bindgen::prelude::*;
430
+ use wasm_bindgen::js;
431
+
432
+ #[wasm_bindgen]
433
+ pub fn symbol_for(key: &js::JsString) -> js::Symbol {
434
+ js::Symbol::for_(key)
435
+ }
436
+
437
+ "# ,
438
+ )
439
+ . file (
440
+ "test.js" ,
441
+ r#"
442
+ import * as assert from "assert";
443
+ import * as wasm from "./out";
444
+
445
+ export function test() {
446
+ assert.strictEqual(wasm.symbol_for("bar"), wasm.symbol_for("bar"));
447
+ assert.strictEqual(wasm.symbol_for("bar"), Symbol.for("bar"));
448
+
449
+ assert.notStrictEqual(wasm.symbol_for("foo"), Symbol("bar"));
450
+ assert.notStrictEqual(wasm.symbol_for("foo"), wasm.symbol_for("bar"));
451
+
452
+ var sym = wasm.symbol_for("mario");
453
+ assert.equal(sym.toString(), "Symbol(mario)");
454
+ }
455
+ "# ,
456
+ )
457
+ . test ( ) ;
458
+ }
459
+
460
+ #[ test]
461
+ fn key_for ( ) {
462
+ project ( )
463
+ . file (
464
+ "src/lib.rs" ,
465
+ r#"
466
+ #![feature(proc_macro, wasm_custom_section)]
467
+
468
+ extern crate wasm_bindgen;
469
+ use wasm_bindgen::prelude::*;
470
+ use wasm_bindgen::js;
471
+
472
+ #[wasm_bindgen]
473
+ pub fn symbol_key_for(sym: &js::Symbol) -> js::JsString {
474
+ js::Symbol::key_for(sym)
475
+ }
476
+
477
+ "# ,
478
+ )
479
+ . file (
480
+ "test.js" ,
481
+ r#"
482
+ import * as assert from "assert";
483
+ import * as wasm from "./out";
484
+
485
+ export function test() {
486
+ var globalSym = Symbol.for("foo");
487
+ assert.strictEqual(wasm.symbol_key_for(globalSym), 'foo');
488
+
489
+ var localSym = Symbol();
490
+ assert.strictEqual(wasm.symbol_key_for(localSym), undefined);
491
+
492
+ assert.strictEqual(wasm.symbol_key_for(Symbol.iterator), undefined);
493
+ }
494
+ "# ,
495
+ )
496
+ . test ( ) ;
497
+ }
498
+
499
+ #[ test]
500
+ fn to_string ( ) {
501
+ project ( )
502
+ . file (
503
+ "src/lib.rs" ,
504
+ r#"
505
+ #![feature(proc_macro, wasm_custom_section)]
506
+
507
+ extern crate wasm_bindgen;
508
+ use wasm_bindgen::prelude::*;
509
+ use wasm_bindgen::js;
510
+
511
+ #[wasm_bindgen]
512
+ pub fn symbol_to_string(this: &js::Symbol) -> js::JsString {
513
+ js::Symbol::to_string(this)
514
+ }
515
+
516
+ "# ,
517
+ )
518
+ . file (
519
+ "test.js" ,
520
+ r#"
521
+ import * as assert from "assert";
522
+ import * as wasm from "./out";
523
+
524
+ export function test() {
525
+ assert.strictEqual(wasm.symbol_to_string(Symbol('desc')), 'Symbol(desc)');
526
+
527
+ assert.strictEqual(wasm.symbol_to_string(Symbol.iterator), 'Symbol(Symbol.iterator)');
528
+
529
+ assert.strictEqual(wasm.symbol_to_string(Symbol.for('foo')), 'Symbol(foo)');
530
+ }
531
+ "# ,
532
+ )
533
+ . test ( ) ;
534
+ }
535
+
536
+ #[ test]
537
+ fn value_of ( ) {
538
+ project ( )
539
+ . file (
540
+ "src/lib.rs" ,
541
+ r#"
542
+ #![feature(proc_macro, wasm_custom_section)]
543
+
544
+ extern crate wasm_bindgen;
545
+ use wasm_bindgen::prelude::*;
546
+ use wasm_bindgen::js;
547
+
548
+ #[wasm_bindgen]
549
+ pub fn symbol_value_of(this: &js::Symbol) -> js::Symbol {
550
+ js::Symbol::value_of(this)
551
+ }
552
+
553
+ "# ,
554
+ )
555
+ . file (
556
+ "test.js" ,
557
+ r#"
558
+ import * as assert from "assert";
559
+ import * as wasm from "./out";
560
+
561
+ export function test() {
562
+ var globalSym = Symbol.for("foo");
563
+ assert.strictEqual(wasm.symbol_value_of(globalSym), globalSym);
564
+
565
+ var localSym = Symbol();
566
+ assert.strictEqual(wasm.symbol_value_of(localSym), localSym);
567
+ }
568
+ "# ,
569
+ )
570
+ . test ( ) ;
571
+ }
0 commit comments