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

Commit 9283527

Browse files
author
runrevali
committed
[[ StdMlc ]] Add array testing
1 parent b48400b commit 9283527

File tree

6 files changed

+37
-13
lines changed

6 files changed

+37
-13
lines changed

libscript/src/array.mlc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,8 @@ output: Either locates the element container with the given key for
120120
syntax SingletonElementOf is postfix operator with precedence 1
121121
<Target: Expression> "[" <Key: Expression> "]"
122122
begin
123-
// FetchElementOfCaseSensitive(Target, Key, output)
124123
MCArrayFetchElementOfCaseless(Target, Key, output)
125-
//FetchElementOfNumeric(Target, Key, output)
126-
//FetchElementOfMatrix(Target, Key, output)
127-
// StoreElementOfCaseSensitive(input, Target, Key)
128124
MCArrayStoreElementOfCaseless(input, Target, Key)
129-
//StoreElementOfNumeric(input, Target, Key)
130-
//StoreElementOfMatrix(input, Target, Key)
131125
end syntax
132126

133127
--

libscript/src/char.mlc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public foreign handler MCCharEvalOffsetOfChars(in IsLast as bool, in Needle as s
2020
public foreign handler MCCharEvalOffsetOfCharsBefore(in IsLast as bool, in Needle as string, in Before as index, in Target as string, out Offset as index) as undefined binds to "<builtin>"
2121
public foreign handler MCCharEvalOffsetOfCharsAfter(in IsFirst as bool, in Needle as string, in After as index, in Target as string, out Offset as index) as undefined binds to "<builtin>"
2222

23+
public foreign handler MCCharEvalContains(in Source as string, in Needle as string, out Result as bool) as undefined binds to "<builtin>"
2324
public foreign handler MCCharEvalBeginsWith(in Source as string, in Prefix as string, out Result as bool) as undefined binds to "<builtin>"
2425
public foreign handler MCCharEvalEndsWith(in Source as string, in Suffix as string, out Result as bool) as undefined binds to "<builtin>"
2526

@@ -283,7 +284,7 @@ Description:
283284
syntax ContainsChars is neutral binary operator with precedence 1
284285
<Source: Expression> "contains" <Needle: Expression>
285286
begin
286-
MCCharEvalIsAmongTheCharsOf(Source, Needle, output)
287+
MCCharEvalContains(Source, Needle, output)
287288
end syntax
288289

289290
--

libscript/src/list.mlc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,6 @@ output: Either locates the element container at the given index for
222222
as the source of another operation.
223223
*/
224224

225-
--public handler MCListFetchElementOfReversed(in pTarget as list, in pIndex as int, out rElement) as undefined
226-
--MCListFetchElementOf(pIndex, pTarget, rElement)
227-
--end handler
228-
229225
syntax SingletonArrElementOf is postfix operator with precedence 1
230226
<Target: Expression> "[" <Index: Expression> "]"
231227
begin

libscript/src/module-array.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extern "C" void MCArrayEvalIsAmongTheKeysOf(MCStringRef p_needle, bool p_is_not,
104104
r_output = !r_output;
105105
}
106106

107-
extern "C" void MCArrayFetchElementOf(MCArrayRef p_target, MCStringRef p_key, MCValueRef& r_output)
107+
extern "C" void MCArrayFetchElementOfCaseless(MCArrayRef p_target, MCStringRef p_key, MCValueRef& r_output)
108108
{
109109
MCNewAutoNameRef t_key;
110110

@@ -117,7 +117,7 @@ extern "C" void MCArrayFetchElementOf(MCArrayRef p_target, MCStringRef p_key, MC
117117
}
118118
}
119119

120-
extern "C" void MCArrayStoreElementOf(MCValueRef p_value, MCArrayRef& x_target, MCStringRef p_key)
120+
extern "C" void MCArrayStoreElementOfCaseless(MCValueRef p_value, MCArrayRef& x_target, MCStringRef p_key)
121121
{
122122
MCNewAutoNameRef t_key;
123123
MCAutoArrayRef t_array;

libscript/src/module-char.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ extern "C" void MCCharEvalOffsetOfCharsBefore(bool p_is_first, MCStringRef p_nee
146146
MCCharEvalOffsetOfCharsInRange(!p_is_first, p_needle, p_target, MCRangeMake(0, p_before), r_output);
147147
}
148148

149+
extern "C" void MCCharEvalContains(MCStringRef p_source, MCStringRef p_needle, bool& r_result)
150+
{
151+
r_result = MCStringContains(p_source, p_needle, kMCStringOptionCompareExact);
152+
}
153+
149154
extern "C" void MCCharEvalBeginsWith(MCStringRef p_source, MCStringRef p_prefix, bool& r_result)
150155
{
151156
r_result = MCStringBeginsWith(p_source, p_prefix, kMCStringOptionCompareExact);

toolchain/lc-compile/test.mlc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public handler test()
1313
testArithmetic(tResults)
1414
testChar(tResults)
1515
testBitwise(tResults)
16+
testArray(tResults)
1617

1718
variable tResultString as string
1819
put the empty string into tResultString
@@ -37,6 +38,30 @@ public handler boolWithSideEffect(in tResult as bool, inout tVar as string) as b
3738
return tResult
3839
end handler
3940

41+
public handler testArray(inout xResults as list)
42+
variable tArray as array
43+
put the empty array into tArray
44+
45+
46+
47+
--put "value1" into tArray[ "key1" ]
48+
--put "value2" into tArray["key2"]
49+
--put "value3" into tArray["key3"]
50+
51+
variable tKeys as list
52+
put the keys of tArray into tKeys
53+
54+
variable tKeysString as string
55+
combine tKeys with "," into tKeysString
56+
57+
testLog("", "", tKeysString is the empty string, xResults)
58+
59+
--testLog("Array", "ArrayKeysOf", tKeysString contains "key1", xResults)
60+
--testLog("Array", "ArrayKeysOf", tKeysString contains "key2", xResults)
61+
--testLog("Array", "ArrayKeysOf", tKeysString contains "key3", xResults)
62+
63+
end handler
64+
4065
public handler testBitwise(inout xResults as list)
4166
variable tVar as integer
4267

@@ -252,6 +277,9 @@ public handler testList(inout xResults as list) as undefined
252277
testLog("List", "SpliceAfter", the tail of tSubList is 1, xResults)
253278
testLog("List", "SpliceAfter", tSubList contains tTestList, xResults)
254279

280+
--put "ZZZZ" into tTestList[1]
281+
--testLog("List", "SingletonElement", tTestList[1] is "ZZZZ", xResults)
282+
255283
end handler
256284

257285
public handler testSort(inout xResults as list) as undefined

0 commit comments

Comments
 (0)