0
0
Fork 0
mirror of https://github.com/ZDoom/Raze.git synced 2024-12-25 19:50:55 +00:00
raze/polymer/eduke32/source/lunatic/test/qsubstr.con
helixhorned 3493302e6c LunaCON: implement 'qsubstr' command. Add source/lunatic/test/qsubstr.con.
In C-CON's qsubstr, error if <start> is not in [0 .. MAXQUOTELEN-1]
or <length> is negative.

git-svn-id: https://svn.eduke32.com/eduke32@4583 1a8010ca-5511-0410-912e-c29ae57300e0
2014-08-31 11:15:22 +00:00

71 lines
1.9 KiB
Text

// Tests for the qsubstr command.
// This one should be safe to run in C-CON.
// overlong string at definition (should warn)
define QSRC 400
definequote QSRC -123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789=123456789
define QSRC_SHORT 401
definequote QSRC_SHORT -123456789
define QDST 500
definequote QDST
// for gettimedate
gamevar sec 0 0
gamevar x 0 0
onevent EVENT_ENTERLEVEL
// first, a plain, non-border-case call
qsubstr QDST QSRC 10 10 // -> "-123456789"
userquote QDST
// length zero yields the empty string
qsubstr QDST QSRC 20 0 // -> ""
userquote QDST
// start+length > strlen of source: no error
qsubstr QDST QSRC_SHORT 8 6 // -> "89"
userquote QDST
// start == strlen of source
qsubstr QDST QSRC_SHORT 10 1 // -> ""
userquote QDST
// Make QDST contain
// -123456789<NUL>123456789-...
qstrcpy QDST QSRC_SHORT
qstrcpy QSRC_SHORT QSRC
qstrcpy QSRC_SHORT QDST
userquote QSRC_SHORT // -> "-123456789"
// start == strlen of source, trailing bytes after source <NUL>
qsubstr QDST QSRC_SHORT 10 2 // -> ""
userquote QDST
// start is beyond-<NUL> of the source
qsubstr QDST QSRC_SHORT 11 9 // -> ""
userquote QDST
// copy whole string (127 chars + 1 <NUL> == MAXQUOTELEN)
qsubstr QDST QSRC 0 1000 // -> "-123456789-123456789-...=123456"
userquote QDST
/** TESTS FOR source == dest **/
qsubstr QDST QDST 0 20 // -> "-123456789-123456789"
userquote QDST
qsubstr QDST QDST 5 10 // -> "56789-1234"
userquote QDST
/** TESTS FOR invalid input **/
gettimedate sec x x x x x x x
ifvarand sec 1
qsubstr QDST QSRC -1 10 // invalid start
else
qsubstr QDST QSRC 0 -1 // invalid length
// Reached only in C-CON:
qsubstr QDST QSRC 128 0 // invalid start
endevent