Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit e187852

Browse files
author
livecodealex
committed
[[ Bug 21705 ]] Added some test cases
1 parent d632901 commit e187852

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

tests/lcs/core/strings/offset.livecodescript

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,89 @@ on TestOffsetSingleUnicodeChar
2929
set the caseSensitive to false
3030
TestAssert "offset of native needle in unicode string - caseless", offset(tNeedle, tHaystack) is 3
3131
end TestOffsetSingleUnicodeChar
32+
33+
// Function provided by Bernd Niggemann as part of bug report
34+
// #21704
35+
function allOffsets pDelim, pString, pCaseSensitive, pNoOverlap
36+
local tNewPos, tPos, tResult, tLen
37+
38+
set the caseSensitive to pCaseSensitive is true
39+
40+
put 0 into tPos
41+
if pNoOverlap then
42+
put the len of pDelim - 1 into tLen
43+
repeat forever
44+
put offset(pDelim, pString, tPos) into tNewPos
45+
if tNewPos = 0 then exit repeat
46+
add tNewPos to tPos
47+
put tPos,"" after tResult
48+
add tLen to tPos
49+
end repeat
50+
else
51+
repeat forever
52+
put offset(pDelim, pString, tPos) into tNewPos
53+
if tNewPos = 0 then exit repeat
54+
add tNewPos to tPos
55+
put tPos,"" after tResult
56+
end repeat
57+
end if
58+
59+
if tResult is empty then return 0
60+
else return char 1 to -2 of tResult
61+
end allOffsets
62+
63+
// Test whether we can correctly detect offsets in strings that contain
64+
// native unicode chars, in a case sensitive manner
65+
on TestOffsetMultipleUnicodeCharsSensitiveText1
66+
local tNeedle, tHaystack
67+
68+
put "aaaaaaa" into tNeedle
69+
put "𠜎aa𠜎aaa ばいしんせい ばいしんせい aaaaaaaaaaaaaaaaaaa c aaaaaaaaaaaaaaaaaaa" into tHaystack
70+
71+
local tExpectedOffsets
72+
put "23,24,25,26,27,28,29,30,31,32,33,34,35,45,46,47,48,49,50,51,52,53,54,55,56,57" into tExpectedOffsets
73+
74+
TestAssert "the offsets match the expected offsets", tExpectedOffsets is allOffsets(tNeedle, tHaystack, true, false)
75+
end TestOffsetMultipleUnicodeCharsSensitiveText1
76+
77+
// Test whether we can correctly detect offsets in strings that contain
78+
// native unicode chars, in a case in-sensitive manner, in a different text
79+
on TestOffsetMultipleUnicodeCharsInSensitiveText2
80+
local tNeedle, tHaystack
81+
82+
put "aaa" into tNeedle
83+
put "aa 𠜎 aaaaaaaaaaaaa↘𠜎aaaa" into tHaystack
84+
85+
local tExpectedOffsets
86+
put "6,7,8,9,10,11,12,13,14,15,16,21,22" into tExpectedOffsets
87+
88+
TestAssert "the offsets match the expected offsets", tExpectedOffsets is allOffsets(tNeedle, tHaystack, true, false)
89+
end TestOffsetMultipleUnicodeCharsInSensitiveText2
90+
91+
// Test whether we can correctly detect offsets in strings that contain
92+
// native unicode chars, in a case in-sensitive manner
93+
on TestOffsetMultipleUnicodeCharsInSensitive2
94+
local tNeedle, tHaystack
95+
96+
put "aaa" into tNeedle
97+
put "aa 𠜎 aaaaaaaaAAAaa↘𠜎aaaa" into tHaystack
98+
99+
local tExpectedOffsets
100+
put "6,7,8,9,10,11,12,13,14,15,16,21,22" into tExpectedOffsets
101+
102+
TestAssert "the offsets match the expected offsets", tExpectedOffsets is allOffsets(tNeedle, tHaystack, false, false)
103+
end TestOffsetMultipleUnicodeCharsInSensitive2
104+
105+
// Test whether we can correctly detect offsets in strings that contain
106+
// native unicode chars, in a case sensitive manner
107+
on TestOffsetMultipleUnicodeCharsInSensitive3
108+
local tNeedle, tHaystack
109+
110+
put "𐀁" into tNeedle
111+
put "𐀁𐀁𐀁𐀁𐀁𐀁" into tHaystack
112+
113+
local tExpectedOffsets
114+
put "1,2,3,4,5,6" into tExpectedOffsets
115+
116+
TestAssert "the offsets match the expected offsets", tExpectedOffsets is allOffsets(tNeedle, tHaystack, true, false)
117+
end TestOffsetMultipleUnicodeCharsInSensitive3

0 commit comments

Comments
 (0)