MCPcopy Create free account
hub / github.com/dop251/goja / TestGoReflectEmbeddedStruct

Function TestGoReflectEmbeddedStruct

object_goreflect_test.go:466–554  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

464}
465
466func TestGoReflectEmbeddedStruct(t *testing.T) {
467 const SCRIPT = `
468 if (o.ParentField2 !== "ParentField2") {
469 throw new Error("ParentField2 = " + o.ParentField2);
470 }
471
472 if (o.Parent.ParentField2 !== 2) {
473 throw new Error("o.Parent.ParentField2 = " + o.Parent.ParentField2);
474 }
475
476 if (o.ParentField1 !== 1) {
477 throw new Error("o.ParentField1 = " + o.ParentField1);
478
479 }
480
481 if (o.ChildField !== 3) {
482 throw new Error("o.ChildField = " + o.ChildField);
483 }
484
485 var keys = {};
486 for (var k in o) {
487 if (keys[k]) {
488 throw new Error("Duplicate key: " + k);
489 }
490 keys[k] = true;
491 }
492
493 var expectedKeys = ["ParentField2", "ParentField1", "Parent", "ChildField"];
494 for (var i in expectedKeys) {
495 if (!keys[expectedKeys[i]]) {
496 throw new Error("Missing key in enumeration: " + expectedKeys[i]);
497 }
498 delete keys[expectedKeys[i]];
499 }
500
501 var remainingKeys = Object.keys(keys);
502 if (remainingKeys.length > 0) {
503 throw new Error("Unexpected keys: " + remainingKeys);
504 }
505
506 o.ParentField2 = "ParentField22";
507 o.Parent.ParentField2 = 22;
508 o.ParentField1 = 11;
509 o.ChildField = 33;
510 `
511
512 type Parent struct {
513 ParentField1 int
514 ParentField2 int
515 }
516
517 type Child struct {
518 ParentField2 string
519 Parent
520 ChildField int
521 }
522
523 vm := New()

Callers

nothing calls this directly

Calls 3

NewFunction · 0.85
RunStringMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…