Libraryless. Click here for Pure Java version (15396L/98K).
1 | concept Bla { |
2 | new Ref<Bla> ref; |
3 | } |
4 | |
5 | svoid test_cset_with_Ref() { |
6 | // unlisted concepts do not track back references |
7 | |
8 | Bla a = unlisted Bla(); |
9 | Bla b = unlisted Bla(); |
10 | assertEqualsVerbose(1, cset(a, ref := b)); |
11 | assertSame(a.ref!, b); |
12 | assertEmptyVerbose(findBackRefs Bla(b)); |
13 | |
14 | new Concepts cc; |
15 | // test with registered concepts |
16 | a = cnew(cc, Bla); |
17 | b = cnew(cc, Bla); |
18 | assertEqualsVerbose(1, cset(a, ref := b)); |
19 | assertSame(a.ref!, b); |
20 | assertEqualsVerbose(ll(a), findBackRefs Bla(b)); |
21 | |
22 | assertEqualsVerbose(1, cset(a, ref := null)); |
23 | assertNull(a.ref!); // make sure the Ref object itself is not deleted |
24 | assertEqualsVerbose(ll(), findBackRefs Bla(b)); // test that back ref is gone |
25 | |
26 | // Now test a "dynamic" (undeclared) field |
27 | |
28 | assertEqualsVerbose(1, cset(a, ref2 := b)); |
29 | assertEqualsVerbose(0, cset(a, ref2 := b)); |
30 | assertSame(cget ref2(a), b); |
31 | assertEqualsVerbose(ll(a), findBackRefs Bla(b)); |
32 | assertEqualsVerbose(1, cset(a, ref2 := null)); |
33 | assertEqualsVerbose(0, cset(a, ref2 := null)); |
34 | assertNull(cget ref2(a)); |
35 | assertEqualsVerbose(ll(), findBackRefs Bla(b)); // test that back ref is gone |
36 | |
37 | assertEmptyVerbose(ConceptsRefChecker(cc).run()); |
38 | |
39 | // overwrite reference with string |
40 | assertEqualsVerbose(1, cset(a, ref2 := b)); |
41 | assertEqualsVerbose(1, cset(a, ref2 := "")); |
42 | assertEqualsVerbose(0, cset(a, ref2 := "")); |
43 | assertEqualsVerbose(cget(a, "ref2"), ""); |
44 | |
45 | assertEmptyVerbose(ConceptsRefChecker(cc).run()); |
46 | |
47 | // overwrite string with reference |
48 | assertEqualsVerbose(1, cset(a, ref2 := b)); |
49 | assertEqualsVerbose(cget(a, "ref2"), b); |
50 | |
51 | assertEmptyVerbose(ConceptsRefChecker(cc).run()); |
52 | |
53 | // check that a list concepts in dynamic field is converted to RefL |
54 | |
55 | assertEqualsVerbose(1, cset(b, dynList := ll(a)); |
56 | assertEqualsVerbose(0, cset(b, dynList := ll(a)); |
57 | Concept.RefL refL = cast getOpt dynList(b); |
58 | assertEqualsVerbose(1, l(refL)); |
59 | assertEquals(a, first(refL)); |
60 | |
61 | // TODO: check updating/overwriting RefL |
62 | } |
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: | 239 / 401 |
Version history: | 13 change(s) |
Referenced in: | [show references] |