Skip to content

Commit 406867e

Browse files
fhackettlemmy
authored andcommitted
Add new string deserialize test
Signed-off-by: fhackett <fhackett.py@gmail.com>
1 parent 99115df commit 406867e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
49 Bytes
Binary file not shown.

tests/IOUtilsTests.tla

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,35 @@ TXTDeserializeResult == Deserialize(file, [format |-> "TXT", charset |-> "UTF-8"
165165
ASSUME(LET ret == TXTDeserializeResult IN /\ ret.exitValue = 0
166166
/\ ret.stdout = payloadTXT
167167
/\ ret.stderr = "")
168+
169+
---------------------------------------------------------------------------------------------------------------------------
170+
171+
\* Simple round-trip test with a variety of different small structures
172+
173+
file2 == "/tmp/bin-serialize-test.vos"
174+
payloadBIN == <<
175+
"foo",
176+
{"bar"},
177+
42,
178+
1..3,
179+
[x |-> 1, y |-> 2]
180+
>>
181+
182+
ASSUME /\ IOSerialize(payloadBIN, file2, FALSE)
183+
/\ LET value == IODeserialize(file2, FALSE)
184+
IN value = payloadBIN
185+
186+
\* Test: can we read a string TLC has never encountered before?
187+
\* !Danger: writing the string literal at any point in the TLA+ breaks the test!
188+
189+
\* The bug this tests for is that TLC can only read string values that are already interned in its
190+
\* in-memory string table. If the string is so much as in the spec at all, TLC can load it.
191+
\* If the string has was never interned however, then TLC would crash when accessing the value
192+
\* (e.g., printing it), because the string table gives `null` on lookup.
193+
\* The weird long name is chosen to avoid any other tests mentioning this string.
194+
ASSUME LET strValue == IODeserialize("tests/Hippopotomonstrosesquippedaliophobia.vos", FALSE)
195+
IN /\ PrintT(strValue)
196+
\* Intended value (in a comment, so not "seen" by TLC)
197+
\* /\ strValue = "Hippopotomonstrosesquippedaliophobia"
168198

169199
=============================================================================

0 commit comments

Comments
 (0)