Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

62
LINES

< > BotCompany Repo | #1029630 // test_cset_with_Ref (OK)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (15396L/98K).

concept Bla {
  new Ref<Bla> ref;
}

svoid test_cset_with_Ref() {
  // unlisted concepts do not track back references
  
  Bla a = unlisted Bla();
  Bla b = unlisted Bla();
  assertEqualsVerbose(1, cset(a, ref := b));
  assertSame(a.ref!, b);
  assertEmptyVerbose(findBackRefs Bla(b));
  
  new Concepts cc;
  // test with registered concepts
  a = cnew(cc, Bla);
  b = cnew(cc, Bla);
  assertEqualsVerbose(1, cset(a, ref := b));
  assertSame(a.ref!, b);
  assertEqualsVerbose(ll(a), findBackRefs Bla(b));

  assertEqualsVerbose(1, cset(a, ref := null));
  assertNull(a.ref!); // make sure the Ref object itself is not deleted
  assertEqualsVerbose(ll(), findBackRefs Bla(b)); // test that back ref is gone
  
  // Now test a "dynamic" (undeclared) field
  
  assertEqualsVerbose(1, cset(a, ref2 := b));
  assertEqualsVerbose(0, cset(a, ref2 := b));
  assertSame(cget ref2(a), b);
  assertEqualsVerbose(ll(a), findBackRefs Bla(b));
  assertEqualsVerbose(1, cset(a, ref2 := null));
  assertEqualsVerbose(0, cset(a, ref2 := null));
  assertNull(cget ref2(a));
  assertEqualsVerbose(ll(), findBackRefs Bla(b)); // test that back ref is gone
  
  assertEmptyVerbose(ConceptsRefChecker(cc).run());
  
  // overwrite reference with string 
  assertEqualsVerbose(1, cset(a, ref2 := b));
  assertEqualsVerbose(1, cset(a, ref2 := ""));
  assertEqualsVerbose(0, cset(a, ref2 := ""));
  assertEqualsVerbose(cget(a, "ref2"), "");
  
  assertEmptyVerbose(ConceptsRefChecker(cc).run());
  
  // overwrite string with reference
  assertEqualsVerbose(1, cset(a, ref2 := b));
  assertEqualsVerbose(cget(a, "ref2"), b);
  
  assertEmptyVerbose(ConceptsRefChecker(cc).run());
  
  // check that a list concepts in dynamic field is converted to RefL
  
  assertEqualsVerbose(1, cset(b, dynList := ll(a));
  assertEqualsVerbose(0, cset(b, dynList := ll(a));
  Concept.RefL refL = cast getOpt dynList(b);
  assertEqualsVerbose(1, l(refL));
  assertEquals(a, first(refL));
  
  // TODO: check updating/overwriting RefL
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029630
Snippet name: test_cset_with_Ref (OK)
Eternal ID of this version: #1029630/14
Text MD5: acb959e550b6f1ffb4dbbfe97a744f2c
Transpilation MD5: 60a5c6a1a14f16b2569dbc2fcda92968
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-04-09 16:39:08
Source code size: 2058 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 238 / 398
Version history: 13 change(s)
Referenced in: [show references]