Skip to content

Commit d066465

Browse files
committed
pdc: breaking changes; namespaced key expression is removed, fixes when used with scoped variables
1 parent 2b7d209 commit d066465

2 files changed

Lines changed: 67 additions & 87 deletions

File tree

scripts/libs/pdc.sk

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ local function coerce_pdt_value(pdt: object, value: object) :: object:
7272
return {_none}
7373

7474

75-
expression [devdinc] %namespacedkey% [with]in %object%[ for %-object%]:
75+
expression [devdinc] [namespaced]( |-)key %string% [with]in %object%[ for %-object%]:
7676
parse:
77-
set {_key} to expr-1
7877
set {_pdt} to expr-3
79-
78+
8079
if any:
8180
"%{_pdt}%" contains "[devdinc] (pdt|[persistent data ]type)"
8281
"%{_pdt}%" contains "PersistentDataType"
@@ -86,7 +85,7 @@ expression [devdinc] %namespacedkey% [with]in %object%[ for %-object%]:
8685
continue
8786

8887
get:
89-
set {_key} to expr-1
88+
set {_key} to NamespacedKey.fromString(expr-1, null)
9089
set {_pdc} to expr-2.getPersistentDataContainer() if expr-2 is instance of PersistentDataHolder else expr-2
9190
set {_pdt} to expr-3
9291

@@ -102,7 +101,7 @@ expression [devdinc] %namespacedkey% [with]in %object%[ for %-object%]:
102101
loop scoped {-primitives::str::*}:
103102
if {_typeId} is loop-value:
104103
set {_pdt} to {_i}th element of scoped {-primitives::pdt::*}
105-
return {_pdc}.get({_key}, {_pdt})
104+
return try {_pdc}.get({_key}, {_pdt}) # try is used for if the key does not exist
106105
add 1 to {_i}
107106

108107
else:
@@ -117,9 +116,8 @@ expression [devdinc] %namespacedkey% [with]in %object%[ for %-object%]:
117116
else:
118117
return {_pdc}.get({_key}, {_pdt})
119118

120-
121119
set:
122-
set {_key} to expr-1
120+
set {_key} to NamespacedKey.fromString(expr-1, null)
123121
set {_pdc} to expr-2.getPersistentDataContainer() if expr-2 is instance of PersistentDataHolder else expr-2
124122
set {_pdt} to expr-3
125123

@@ -167,7 +165,7 @@ expression [devdinc] %namespacedkey% [with]in %object%[ for %-object%]:
167165

168166

169167
delete:
170-
set {_key} to expr-1
168+
set {_key} to NamespacedKey.fromString(expr-1, null)
171169
set {_pdc} to expr-2.getPersistentDataContainer() if expr-2 is instance of PersistentDataHolder else expr-2
172170
set {_pdt} to expr-3
173171

@@ -178,13 +176,6 @@ expression [devdinc] %namespacedkey% [with]in %object%[ for %-object%]:
178176
{_pdc}.remove({_key})
179177

180178

181-
expression [devdinc] [namespaced]( |-)key %string%:
182-
parse:
183-
continue
184-
get:
185-
return NamespacedKey.fromString(expr-1, null)
186-
187-
188179
object property p[ersistent ]d[ata ]c[ontainer]:
189180
parse:
190181
continue

tests/pdc.sk

Lines changed: 61 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,125 +2,114 @@ import:
22
java.util.HashMap
33

44
on load:
5-
set scoped {-key} to namespaced-key "plugin:test_pdt"
5+
set scoped {-key} to "plugin:test_pdt"
66

77
after each test:
8-
delete scoped {-key} within test-world if scoped {-key} is set
9-
10-
test "pdc basic set/get with typed pdt":
11-
12-
set scoped {-key} within test-world for pdt integer to 42
13-
assert scoped {-key} within test-world for pdt integer is 42 with "typed pdt get failed"
14-
8+
event-script is current script
9+
delete namespaced-key scoped {-key} within test-world if scoped {-key} is set
10+
11+
# since we use after each test we have to use devdinc test pattern here
1512

16-
test "pdc overwrite typed value":
13+
devdinc test "pdc basic set/get with typed pdt":
1714

18-
set scoped {-key} within test-world for pdt string to "a"
19-
set scoped {-key} within test-world for pdt string to "b"
15+
set namespaced-key scoped {-key} within test-world for pdt integer to 42
16+
assert namespaced-key scoped {-key} within test-world for pdt integer is 42 with "typed pdt get failed"
2017

21-
assert scoped {-key} within test-world for pdt string is "b" with "overwrite failed"
18+
devdinc test "pdc overwrite typed value":
2219

20+
set namespaced-key scoped {-key} within test-world for pdt string to "a"
21+
set namespaced-key scoped {-key} within test-world for pdt string to "b"
2322

24-
test "pdc delete typed value":
25-
set scoped {-key} within test-world for pdt long to 100
26-
delete scoped {-key} within test-world for pdt long
23+
assert namespaced-key scoped {-key} within test-world for pdt string is "b" with "overwrite failed"
2724

28-
assert scoped {-key} within test-world for pdt long is not set with "delete failed"
25+
devdinc test "pdc delete typed value":
26+
set namespaced-key scoped {-key} within test-world for pdt long to 100
27+
delete namespaced-key scoped {-key} within test-world for pdt long
2928

29+
assert namespaced-key scoped {-key} within test-world for pdt long is not set with "delete failed"
3030

31-
test "pdc object serialization (byte_array implicit)":
31+
devdinc test "pdc object serialization (byte_array implicit)":
3232

3333
set {_obj} to new HashMap()
3434
{_obj}.put("a", 1)
3535
{_obj}.put("b", 2)
3636

37-
set scoped {-key} within test-world to {_obj}
37+
set namespaced-key scoped {-key} within test-world to {_obj}
3838

39-
set {_out} to scoped {-key} within test-world
39+
set {_out} to namespaced-key scoped {-key} within test-world
4040
assert {_out}.get("a") is 1 with "object deserialize failed (a)"
4141
assert {_out}.get("b") is 2 with "object deserialize failed (b)"
4242

43+
devdinc test "pdc remove object via null":
4344

44-
test "pdc remove object via null":
45+
set namespaced-key scoped {-key} within test-world to "temp"
46+
set namespaced-key scoped {-key} within test-world to null
4547

46-
set scoped {-key} within test-world to "temp"
47-
set scoped {-key} within test-world to null
48+
assert namespaced-key scoped {-key} within test-world is not set with "object remove via null failed"
4849

49-
assert scoped {-key} within test-world is not set with "object remove via null failed"
50-
51-
52-
test "pdc holder vs direct pdc equivalence":
50+
devdinc test "pdc holder vs direct pdc equivalence":
5351
set {_pdc} to test-world's pdc
5452

55-
set scoped {-key} within test-world for pdt byte to 7
56-
assert scoped {-key} within {_pdc} for pdt byte is 7 with "direct pdc access failed"
57-
58-
59-
test "pdc boolean pdt":
53+
set namespaced-key scoped {-key} within test-world for pdt byte to 7
54+
assert namespaced-key scoped {-key} within {_pdc} for pdt byte is 7 with "direct pdc access failed"
6055

61-
set scoped {-key} within test-world for pdt boolean to true
62-
assert scoped {-key} within test-world for pdt boolean is true with "boolean pdt failed"
56+
devdinc test "pdc boolean pdt":
6357

58+
set namespaced-key scoped {-key} within test-world for pdt boolean to true
59+
assert namespaced-key scoped {-key} within test-world for pdt boolean is true with "boolean pdt failed"
6460

65-
test "pdc default object missing returns none":
61+
devdinc test "pdc default object missing returns none":
6662

67-
assert scoped {-key} within test-world is not set with "missing object did not return none"
63+
assert namespaced-key scoped {-key} within test-world is not set with "missing object did not return none"
6864

69-
test "pdc unspecified pdt boolean":
65+
devdinc test "pdc unspecified pdt boolean":
7066

71-
set scoped {-key} within test-world to true
72-
assert scoped {-key} within test-world is true with "unspecified boolean failed"
67+
set namespaced-key scoped {-key} within test-world to true
68+
assert namespaced-key scoped {-key} within test-world is true with "unspecified boolean failed"
7369

70+
devdinc test "pdc unspecified pdt byte":
7471

75-
test "pdc unspecified pdt byte":
72+
set namespaced-key scoped {-key} within test-world to 5
73+
assert namespaced-key scoped {-key} within test-world is 5 with "unspecified byte failed"
7674

77-
set scoped {-key} within test-world to 5
78-
assert scoped {-key} within test-world is 5 with "unspecified byte failed"
75+
devdinc test "pdc unspecified pdt short":
7976

77+
set namespaced-key scoped {-key} within test-world to 12
78+
assert namespaced-key scoped {-key} within test-world is 12 with "unspecified short failed"
8079

81-
test "pdc unspecified pdt short":
80+
devdinc test "pdc unspecified pdt integer":
8281

83-
set scoped {-key} within test-world to 12
84-
assert scoped {-key} within test-world is 12 with "unspecified short failed"
82+
set namespaced-key scoped {-key} within test-world to 123
83+
assert namespaced-key scoped {-key} within test-world is 123 with "unspecified integer failed"
8584

85+
devdinc test "pdc unspecified pdt long":
8686

87-
test "pdc unspecified pdt integer":
87+
set namespaced-key scoped {-key} within test-world to 123
88+
assert namespaced-key scoped {-key} within test-world is 123 with "unspecified long failed"
8889

89-
set scoped {-key} within test-world to 123
90-
assert scoped {-key} within test-world is 123 with "unspecified integer failed"
90+
devdinc test "pdc unspecified pdt float":
9191

92+
set namespaced-key scoped {-key} within test-world to 1.5
93+
assert namespaced-key scoped {-key} within test-world is 1.5 with "unspecified float failed"
9294

93-
test "pdc unspecified pdt long":
94-
95-
set scoped {-key} within test-world to 123
96-
assert scoped {-key} within test-world is 123 with "unspecified long failed"
97-
98-
99-
test "pdc unspecified pdt float":
100-
101-
set scoped {-key} within test-world to 1.5
102-
assert scoped {-key} within test-world is 1.5 with "unspecified float failed"
103-
104-
105-
test "pdc unspecified pdt double":
95+
devdinc test "pdc unspecified pdt double":
10696

107-
set scoped {-key} within test-world to 2.75
108-
assert scoped {-key} within test-world is 2.75 with "unspecified double failed"
109-
97+
set namespaced-key scoped {-key} within test-world to 2.75
98+
assert namespaced-key scoped {-key} within test-world is 2.75 with "unspecified double failed"
11099

111-
test "pdc unspecified pdt string":
112100

113-
set scoped {-key} within test-world to "hello"
114-
assert scoped {-key} within test-world is "hello" with "unspecified string failed"
101+
devdinc test "pdc unspecified pdt string":
115102

103+
set namespaced-key scoped {-key} within test-world to "hello"
104+
assert namespaced-key scoped {-key} within test-world is "hello" with "unspecified string failed"
116105

117-
test "pdc unspecified pdt tag_container":
106+
devdinc test "pdc unspecified pdt tag_container":
118107

119108
set {_inner-pdc} to new pdc from test-world
120-
set {_inner-key} to namespaced-key "plugin:inner_key"
121-
set {_inner-key} within {_inner-pdc} for pdt integer to 9
109+
set {_inner-key} to "plugin:inner_key"
110+
set namespaced-key {_inner-key} within {_inner-pdc} for pdt integer to 9
122111

123-
set scoped {-key} within test-world to {_inner-pdc}
112+
set namespaced-key scoped {-key} within test-world to {_inner-pdc}
124113

125-
set {_out-pdc} to scoped {-key} within test-world
126-
assert {_inner-key} within {_out-pdc} for pdt integer is 9 with "unspecified tag_container failed"
114+
set {_out-pdc} to namespaced-key scoped {-key} within test-world
115+
assert namespaced-key {_inner-key} within {_out-pdc} for pdt integer is 9 with "unspecified tag_container failed"

0 commit comments

Comments
 (0)