From 93b57f88b792646fdec5f02f0577c0d323b8f1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?AshGrey=F0=9F=A5=95?= Date: Tue, 1 Jul 2025 09:25:10 +0800 Subject: [PATCH 1/5] :sparkles: feat(array-methods): add `Array.LastIndexOf` method, similar to `Array.prototype.lastIndexOf` --- lib/Array/index.d.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/Array/index.d.ts b/lib/Array/index.d.ts index 4a8fc9e..198867a 100644 --- a/lib/Array/index.d.ts +++ b/lib/Array/index.d.ts @@ -260,6 +260,31 @@ export type IndexOf< : IndexOf : -1; +/** + * This method returns the last encounter index of element `T` in array `Arr`. + * + * @param Arr The array to be checked. + * @param T The element to check the last encounter index. + * @param Count Middle variable to store the scanning state. + * @returns The last encounter index of element `T` in array `Arr`. + * + * @example + * type LastIndex1 = Array.LastIndexOf<[1, 2, 1, 22, 3], 1>; // 2 + * type LastIndex2 = Array.LastIndexOf<[], 1>; // -1 + * type LastIndex3 = Array.LastIndexOf<[1], 1>; // 0 + */ +export type LastIndexOf< + Arr extends unknown[], + T extends unknown, + Count extends 0[] = CreateArrayFromLength +> = Arr extends [...infer Rest, infer L] + ? Equal extends true + ? Integer.Dec + : Count extends [...infer RestCount extends 0[], 0] + ? LastIndexOf + : -1 + : -1; + /** * This method is like `Array.prototype.join`, it creates and returns a new string by * concatenating all of the elements in this array, separated by commas or a specified From 27dbdad2b4aab68f51d7bf2ea930f6fa9a65799e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?AshGrey=F0=9F=A5=95?= Date: Tue, 1 Jul 2025 09:28:28 +0800 Subject: [PATCH 2/5] :test_tube: test(Array.LastIndexOf): add passed tests for `Array.LastIndexOf` method --- test/lib-Array.test.ts | 6 ++++++ test/script/lib-gen.sh | 1 + 2 files changed, 7 insertions(+) diff --git a/test/lib-Array.test.ts b/test/lib-Array.test.ts index 61d0d4f..6e42a53 100644 --- a/test/lib-Array.test.ts +++ b/test/lib-Array.test.ts @@ -89,4 +89,10 @@ type CaseLibArray = [ Expect, never>>, Expect, never>>, + // Array.LastIndexOf + Expect, 4>>, + Expect, -1>>, + Expect, -1>>, + Expect, 1>>, + ] diff --git a/test/script/lib-gen.sh b/test/script/lib-gen.sh index cf1d0ee..a9f3589 100644 --- a/test/script/lib-gen.sh +++ b/test/script/lib-gen.sh @@ -32,6 +32,7 @@ declare -A test_cases=( ["Array.Flat"]="[1,2,3]:[1,2,3] [1,2,3,[]]:[1,2,3] [1,2,[3]]:[1,2,3] [1,2,[3,[0]]]:[1,2,3,0] []:[] [[]]:[] [[[1]]]:[1]" ["Array.Includes"]="[1,2,3]|1:true [1,2,3]|-1:false []|\"\":false [\"\"]|\"\":true [[]]|[]:true [[1]]|1:false" ["Array.IndexOf"]="[1,2,3]|1:0 [1,[2],3]|[2]:1 []|0:-1 [1,2,3]|4:-1 [1,2,1]|1:0" + ["Array.LastIndexOf"]="[1,2,1,2,1,3,4]|1:4 []|1:-1 [1,2,3]|0:-1 [[],[[]],[],[]]|[[]]:1" ["Array.Join"]="[1,2,3]:\"1,2,3\" [-1,\".\",9]|\"-\":\"-1-.-9\" [1,2,3]|\"\":\"123\"" ["Array.Pop"]="[1,2,3]:[1,2] [1]|\"get-rest\":[] []|\"get-rest\":never [1,2,3]|\"get-pop-element\":3 [1]|\"get-pop-element\":1 []|\"get-pop-element\":never" ["Array.Push"]="[1,2,3]|\"1\":[1,2,3,\"1\"] []|1:[1] []|[]:[[]]" From c25fbe2104836ad431505d3cc6532bf9c5bb920c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?AshGrey=F0=9F=A5=95?= Date: Tue, 1 Jul 2025 09:33:42 +0800 Subject: [PATCH 3/5] :memo: doc(changelog): add `Array.LastIndexOf` method to next version --- changelog/next.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog/next.md b/changelog/next.md index 49f514f..05218c5 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -43,6 +43,11 @@ + `Array.Pop` + `Array.Push` +### 2025-07-01 (feature/array-methods → main) + ++ Add a new method of `Array` namespace: + + `Array.LastIndexOf` + ## ⚡ Improvements ## 🐦‍🔥 No longer broken \ No newline at end of file From 3dc5d0bfe3145e235301717915a5ad98403ce503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?AshGrey=F0=9F=A5=95?= Date: Tue, 1 Jul 2025 09:48:33 +0800 Subject: [PATCH 4/5] =?UTF-8?q?:bug:=20fix(test-script):=20fix=20the=20par?= =?UTF-8?q?am=20separators=20from=20`|`=20to=20`=E2=80=96`,=20the=20param?= =?UTF-8?q?=20and=20returned=20separators=20from=20`:`=20to=20`=E2=88=B7`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/script/lib-gen.sh | 114 ++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/test/script/lib-gen.sh b/test/script/lib-gen.sh index a9f3589..19c31d7 100644 --- a/test/script/lib-gen.sh +++ b/test/script/lib-gen.sh @@ -4,61 +4,61 @@ ROOT_DIR=$(dirname "$(realpath "$0")")/../.. TEST_DIR="${ROOT_DIR}/test" declare -A test_cases=( - ["Integer.IsNegative"]="-2:true 0:false 9:false" - ["Integer.IsPositive"]="-2:false 0:false 9:true" - ["Integer.IsZero"]="-2:false 0:true 9:false" - ["Integer.Opposite"]="-2:2 0:0 20:-20" - ["Integer.Lower"]="2|1:false 1|2:true 2|-1:false -1|2:true -3|-2:true -2|-3:false -1|0:true 2|0:false 0|3:true 0|-3:false 0|0:false 2|2:false -2|-2:false" - ["Integer.Greater"]="2|1:true 1|2:false 2|-1:true -1|2:false -3|-2:false -2|-3:true -1|0:false 2|0:true 0|3:false 0|-3:true 0|0:false 2|2:false -2|-2:false" - ["Integer.Eq"]="2|1:false 1|2:false 2|-1:false -1|2:false -3|-2:false -2|-3:false -1|0:false 2|0:false 0|3:false 0|-3:false 0|0:true 2|2:true -2|-2:true" - ["Integer.Neq"]="2|1:true 1|2:true 2|-1:true -1|2:true -3|-2:true -2|-3:true -1|0:true 2|0:true 0|3:true 0|-3:true 0|0:false 2|2:false -2|-2:false" - ["Integer.LowerEq"]="2|1:false 1|2:true 2|-1:false -1|2:true -3|-2:true -2|-3:false -1|0:true 2|0:false 0|3:true 0|-3:false 0|0:true 2|2:true -2|-2:true" - ["Integer.GreaterEq"]="2|1:true 1|2:false 2|-1:true -1|2:false -3|-2:false -2|-3:true -1|0:false 2|0:true 0|3:false 0|-3:true 0|0:true 2|2:true -2|-2:true" - ["Integer.Add"]="2|3:5 -2|2:0 -2|-6:-8 3|-3:0 3|-2:1 -2|1:-1 0|0:0 -2|0:-2 2|0:2 0|20:20 0|-30:-30" - ["Integer.Inc"]="2:3 0:1 -1:0 -30:-29" - ["Integer.Sub"]="2|3:-1 3|2:1 -2|3:-5 -2|-3:1 -9|-2:-7 2|0:2 -3|0:-3 0|2:-2 0|-3:3 0|0:0 2|2:0 -3|-3:0" - ["Integer.Dec"]="2:1 0:-1 1:0 -3:-4" - ["Integer.Divide"]="2|3:0 4|2:2 9|-3:-3 9|-2:-4 9|0:never -2|-3:0 -4|2:-2 4|4:1 4|-4:-1 -4|-4:1" - ["Integer.Mod"]="2|2:0 3|2:1 -3|-2:1 -3|2:-1 9|5:4" - ["Integer.IsOdd"]="1:true 2:false 0:false -3:true -19:true 20:false" - ["Integer.IsEven"]="1:false 0:true -22:true 19:false" - - ["Array.CreateArrayFromLength"]="2:[undefined,undefined] 3|string:[string,string,string] 0:[] -1:[]" - ["Array.At"]="[1,2,3]|2:3 [1,2,3,4]|0|:1 []|1:never []|-1:never []|0:never" - ["Array.Concat"]="[1,2,3]|[2,3,1]:[1,2,3,2,3,1]" - ["Array.MultipleConcat"]="[[1,2,3],[4,2,3],[undefined,true]]:[1,2,3,4,2,3,undefined,true] [[],[1],[],[2]]:[1,2] [[[2]],[1]]:[[2],1]" - ["Array.Fill"]="[1,2,3]|\"3\":[\"3\",\"3\",\"3\"] [0,9,1]|\"1\"|1|2:[0,\"1\",1] [\"head\",9,1]|true|1:[\"head\",true,true] [1,2,3]|\"3\"|2|1:[1,2,3] [1,2,3]|\"3\"|-4|2:[\"3\",\"3\",3] [1,2,3]|\"3\"|-2|3:[1,\"3\",\"3\"] [1,2,3]|\"3\"|7|2:[1,2,3] [1,2,3]|\"3\"|1|-1:[1,\"3\",3]" - ["Array.IsFlatten"]="[1,2,3]:true []:true [[]]:false [1,[2],3]:false [[],1,2]:false [1,[1,2,[]],undefined]:false" - ["Array.Flat"]="[1,2,3]:[1,2,3] [1,2,3,[]]:[1,2,3] [1,2,[3]]:[1,2,3] [1,2,[3,[0]]]:[1,2,3,0] []:[] [[]]:[] [[[1]]]:[1]" - ["Array.Includes"]="[1,2,3]|1:true [1,2,3]|-1:false []|\"\":false [\"\"]|\"\":true [[]]|[]:true [[1]]|1:false" - ["Array.IndexOf"]="[1,2,3]|1:0 [1,[2],3]|[2]:1 []|0:-1 [1,2,3]|4:-1 [1,2,1]|1:0" - ["Array.LastIndexOf"]="[1,2,1,2,1,3,4]|1:4 []|1:-1 [1,2,3]|0:-1 [[],[[]],[],[]]|[[]]:1" - ["Array.Join"]="[1,2,3]:\"1,2,3\" [-1,\".\",9]|\"-\":\"-1-.-9\" [1,2,3]|\"\":\"123\"" - ["Array.Pop"]="[1,2,3]:[1,2] [1]|\"get-rest\":[] []|\"get-rest\":never [1,2,3]|\"get-pop-element\":3 [1]|\"get-pop-element\":1 []|\"get-pop-element\":never" - ["Array.Push"]="[1,2,3]|\"1\":[1,2,3,\"1\"] []|1:[1] []|[]:[[]]" - - ["BigInteger.ToString"]="2n:\"2\" -2n:\"-2\" 0n:\"0\"" - ["BigInteger.IsNegative"]="-23n:true 26n:false 0n:false" - ["BigInteger.IsPositive"]="90n:true 0n:false -8n:false" - ["BigInteger.IsZero"]="0n:true 29n:false -2n:false" - ["BigInteger.Opposite"]="0n:0n 23n:-23n -12n:12n" - ["BigInteger.Eq"]="0n|0n:true -12n|-12n:true 23n|22n:false 23n|-23n:false" - ["BigInteger.Lower"]="23n|123n:true 23n|23n:false 1234n|1235n:true -123n|90n:true 123n|-90n:false 0n|0n:false -2n|-2n:false 12345n|12345n:false" - - ["String.Length"]="\"abs\":3 \"\":0 \"2222_2222_2222_2222_2222\":24" - ["String.At"]="\"123456789\"|0:\"1\" \"123456789\"|2:\"3\" \"123456789\"|-3:\"7\" \"123456789\"|100:never" - ["String.Concat"]="[\"12\",\"ab\"]:\"12ab\" [\"love\"]:\"love\" []:\"\"" - ["String.SubString"]="\"LoveYouHuaier\":\"LoveYouHuaier\" \"LoveYouHuaier\"|4:\"YouHuaier\" \"LoveYouHuaier\"|4|9:\"YouHu\" \"LoveYouHuaier\"|3|-2:\"eYouHuai\" \"LoveYouHuaier\"|-7|-2:\"uHuai\" \"LoveYouHuaier\"|0|0:\"\" \"LoveYouHuaier\"|-1|-1:\"\" \"LoveYouHuaier\"|8|7:\"\"" - ["String.EndsWith"]="\"What?\"|\"?\":true \"What?\"|\"What?\":true \"What?\"|\"SoWhat?\":false \"What?\"|\"t?\":true \"What?\"|\"W?\":false \"What?\"|\"\":true \"\"|\"test\":false \"\"|\"\":true \"What?\"|\"?\"|5:true \"What?\"|\"t?\"|3:false \"\"|\"\"|2:true" - ["String.Includes"]="\"AshGrey\"|\"Ash\":true \"AshGrey\"|\"A\":true \"AshGrey\"|\"a\":false \"AshGrey\"|\"\":true \"AshGrey\"|\"Ash\"|0:true \"AshGrey\"|\"Ash\"|1:false \"AshGrey\"|\"Ash\"|-1:true" - - ["Boolean.And"]="false|false:false false|true:false true|false:false true|true:true" - ["Boolean.Or"]="false|false:false false|true:true true|false:true true|true:true" - ["Boolean.Nor"]="false:true true:false" - ["Boolean.Nand"]="false|false:true false|true:true true|false:true true|true:false" - ["Boolean.Nor"]="false|false:true false|true:false true|false:false true|true:false" - ["Boolean.MultipleAnd"]="[true,true,true]:true [true,false,true]:false [false,false,false]:false" - ["Boolean.MultipleOr"]="[true,true,true]:true [true,false,false]:true [false,false,false]:false" + ["Integer.IsNegative"]="-2∷true 0∷false 9∷false" + ["Integer.IsPositive"]="-2∷false 0∷false 9∷true" + ["Integer.IsZero"]="-2∷false 0∷true 9∷false" + ["Integer.Opposite"]="-2∷2 0∷0 20∷-20" + ["Integer.Lower"]="2‖1∷false 1‖2∷true 2‖-1∷false -1‖2∷true -3‖-2∷true -2‖-3∷false -1‖0∷true 2‖0∷false 0‖3∷true 0‖-3∷false 0‖0∷false 2‖2∷false -2‖-2∷false" + ["Integer.Greater"]="2‖1∷true 1‖2∷false 2‖-1∷true -1‖2∷false -3‖-2∷false -2‖-3∷true -1‖0∷false 2‖0∷true 0‖3∷false 0‖-3∷true 0‖0∷false 2‖2∷false -2‖-2∷false" + ["Integer.Eq"]="2‖1∷false 1‖2∷false 2‖-1∷false -1‖2∷false -3‖-2∷false -2‖-3∷false -1‖0∷false 2‖0∷false 0‖3∷false 0‖-3∷false 0‖0∷true 2‖2∷true -2‖-2∷true" + ["Integer.Neq"]="2‖1∷true 1‖2∷true 2‖-1∷true -1‖2∷true -3‖-2∷true -2‖-3∷true -1‖0∷true 2‖0∷true 0‖3∷true 0‖-3∷true 0‖0∷false 2‖2∷false -2‖-2∷false" + ["Integer.LowerEq"]="2‖1∷false 1‖2∷true 2‖-1∷false -1‖2∷true -3‖-2∷true -2‖-3∷false -1‖0∷true 2‖0∷false 0‖3∷true 0‖-3∷false 0‖0∷true 2‖2∷true -2‖-2∷true" + ["Integer.GreaterEq"]="2‖1∷true 1‖2∷false 2‖-1∷true -1‖2∷false -3‖-2∷false -2‖-3∷true -1‖0∷false 2‖0∷true 0‖3∷false 0‖-3∷true 0‖0∷true 2‖2∷true -2‖-2∷true" + ["Integer.Add"]="2‖3∷5 -2‖2∷0 -2‖-6∷-8 3‖-3∷0 3‖-2∷1 -2‖1∷-1 0‖0∷0 -2‖0∷-2 2‖0∷2 0‖20∷20 0‖-30∷-30" + ["Integer.Inc"]="2∷3 0∷1 -1∷0 -30∷-29" + ["Integer.Sub"]="2‖3∷-1 3‖2∷1 -2‖3∷-5 -2‖-3∷1 -9‖-2∷-7 2‖0∷2 -3‖0∷-3 0‖2∷-2 0‖-3∷3 0‖0∷0 2‖2∷0 -3‖-3∷0" + ["Integer.Dec"]="2∷1 0∷-1 1∷0 -3∷-4" + ["Integer.Divide"]="2‖3∷0 4‖2∷2 9‖-3∷-3 9‖-2∷-4 9‖0∷never -2‖-3∷0 -4‖2∷-2 4‖4∷1 4‖-4∷-1 -4‖-4∷1" + ["Integer.Mod"]="2‖2∷0 3‖2∷1 -3‖-2∷1 -3‖2∷-1 9‖5∷4" + ["Integer.IsOdd"]="1∷true 2∷false 0∷false -3∷true -19∷true 20∷false" + ["Integer.IsEven"]="1∷false 0∷true -22∷true 19∷false" + + ["Array.CreateArrayFromLength"]="2∷[undefined,undefined] 3‖string∷[string,string,string] 0∷[] -1∷[]" + ["Array.At"]="[1,2,3]‖2∷3 [1,2,3,4]‖0‖∷1 []‖1∷never []‖-1∷never []‖0∷never" + ["Array.Concat"]="[1,2,3]‖[2,3,1]∷[1,2,3,2,3,1]" + ["Array.MultipleConcat"]="[[1,2,3],[4,2,3],[undefined,true]]∷[1,2,3,4,2,3,undefined,true] [[],[1],[],[2]]∷[1,2] [[[2]],[1]]∷[[2],1]" + ["Array.Fill"]="[1,2,3]‖\"3\"∷[\"3\",\"3\",\"3\"] [0,9,1]‖\"1\"‖1‖2∷[0,\"1\",1] [\"head\",9,1]‖true‖1∷[\"head\",true,true] [1,2,3]‖\"3\"‖2‖1∷[1,2,3] [1,2,3]‖\"3\"‖-4‖2∷[\"3\",\"3\",3] [1,2,3]‖\"3\"‖-2‖3∷[1,\"3\",\"3\"] [1,2,3]‖\"3\"‖7‖2∷[1,2,3] [1,2,3]‖\"3\"‖1‖-1∷[1,\"3\",3]" + ["Array.IsFlatten"]="[1,2,3]∷true []∷true [[]]∷false [1,[2],3]∷false [[],1,2]∷false [1,[1,2,[]],undefined]∷false" + ["Array.Flat"]="[1,2,3]∷[1,2,3] [1,2,3,[]]∷[1,2,3] [1,2,[3]]∷[1,2,3] [1,2,[3,[0]]]∷[1,2,3,0] []∷[] [[]]∷[] [[[1]]]∷[1]" + ["Array.Includes"]="[1,2,3]‖1∷true [1,2,3]‖-1∷false []‖\"\"∷false [\"\"]‖\"\"∷true [[]]‖[]∷true [[1]]‖1∷false" + ["Array.IndexOf"]="[1,2,3]‖1∷0 [1,[2],3]‖[2]∷1 []‖0∷-1 [1,2,3]‖4∷-1 [1,2,1]‖1∷0" + ["Array.LastIndexOf"]="[1,2,1,2,1,3,4]‖1∷4 []‖1∷-1 [1,2,3]‖0∷-1 [[],[[]],[],[]]‖[[]]∷1" + ["Array.Join"]="[1,2,3]∷\"1,2,3\" [-1,\".\",9]‖\"-\"∷\"-1-.-9\" [1,2,3]‖\"\"∷\"123\"" + ["Array.Pop"]="[1,2,3]∷[1,2] [1]‖\"get-rest\"∷[] []‖\"get-rest\"∷never [1,2,3]‖\"get-pop-element\"∷3 [1]‖\"get-pop-element\"∷1 []‖\"get-pop-element\"∷never" + ["Array.Push"]="[1,2,3]‖\"1\"∷[1,2,3,\"1\"] []‖1∷[1] []‖[]∷[[]]" + + ["BigInteger.ToString"]="2n∷\"2\" -2n∷\"-2\" 0n∷\"0\"" + ["BigInteger.IsNegative"]="-23n∷true 26n∷false 0n∷false" + ["BigInteger.IsPositive"]="90n∷true 0n∷false -8n∷false" + ["BigInteger.IsZero"]="0n∷true 29n∷false -2n∷false" + ["BigInteger.Opposite"]="0n∷0n 23n∷-23n -12n∷12n" + ["BigInteger.Eq"]="0n‖0n∷true -12n‖-12n∷true 23n‖22n∷false 23n‖-23n∷false" + ["BigInteger.Lower"]="23n‖123n∷true 23n‖23n∷false 1234n‖1235n∷true -123n‖90n∷true 123n‖-90n∷false 0n‖0n∷false -2n‖-2n∷false 12345n‖12345n∷false" + + ["String.Length"]="\"abs\"∷3 \"\"∷0 \"2222_2222_2222_2222_2222\"∷24" + ["String.At"]="\"123456789\"‖0∷\"1\" \"123456789\"‖2∷\"3\" \"123456789\"‖-3∷\"7\" \"123456789\"‖100∷never" + ["String.Concat"]="[\"12\",\"ab\"]∷\"12ab\" [\"love\"]∷\"love\" []∷\"\"" + ["String.SubString"]="\"LoveYouHuaier\"∷\"LoveYouHuaier\" \"LoveYouHuaier\"‖4∷\"YouHuaier\" \"LoveYouHuaier\"‖4‖9∷\"YouHu\" \"LoveYouHuaier\"‖3‖-2∷\"eYouHuai\" \"LoveYouHuaier\"‖-7‖-2∷\"uHuai\" \"LoveYouHuaier\"‖0‖0∷\"\" \"LoveYouHuaier\"‖-1‖-1∷\"\" \"LoveYouHuaier\"‖8‖7∷\"\"" + ["String.EndsWith"]="\"What?\"‖\"?\"∷true \"What?\"‖\"What?\"∷true \"What?\"‖\"SoWhat?\"∷false \"What?\"‖\"t?\"∷true \"What?\"‖\"W?\"∷false \"What?\"‖\"\"∷true \"\"‖\"test\"∷false \"\"‖\"\"∷true \"What?\"‖\"?\"‖5∷true \"What?\"‖\"t?\"‖3∷false \"\"‖\"\"‖2∷true" + ["String.Includes"]="\"AshGrey\"‖\"Ash\"∷true \"AshGrey\"‖\"A\"∷true \"AshGrey\"‖\"a\"∷false \"AshGrey\"‖\"\"∷true \"AshGrey\"‖\"Ash\"‖0∷true \"AshGrey\"‖\"Ash\"‖1∷false \"AshGrey\"‖\"Ash\"‖-1∷true" + + ["Boolean.And"]="false‖false∷false false‖true∷false true‖false∷false true‖true∷true" + ["Boolean.Or"]="false‖false∷false false‖true∷true true‖false∷true true‖true∷true" + ["Boolean.Nor"]="false∷true true∷false" + ["Boolean.Nand"]="false‖false∷true false‖true∷true true‖false∷true true‖true∷false" + ["Boolean.Nor"]="false‖false∷true false‖true∷false true‖false∷false true‖true∷false" + ["Boolean.MultipleAnd"]="[true,true,true]∷true [true,false,true]∷false [false,false,false]∷false" + ["Boolean.MultipleOr"]="[true,true,true]∷true [true,false,false]∷true [false,false,false]∷false" ) function repeat { @@ -97,8 +97,8 @@ for test_name in "${!test_cases[@]}"; do echo " // ${test_name}" >> "$output_file" for pair in ${test_cases[$test_name]}; do - IFS=":" read -r params expect <<< "$pair" - IFS="|" read -ra args <<< "$params" + IFS="∷" read -r params expect <<< "$pair" + IFS="‖" read -ra args <<< "$params" # echo "🐵 Check Middle Args ${args[@]}" From d324535225fb2c9908ad5031981521daf2ea145a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?AshGrey=F0=9F=A5=95?= Date: Tue, 1 Jul 2025 11:19:35 +0800 Subject: [PATCH 5/5] :test_tube: test(Array.LastIndexOf): add functions and objects array test --- test/lib-Array.test.ts | 2 ++ test/script/lib-gen.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/lib-Array.test.ts b/test/lib-Array.test.ts index 6e42a53..ff9f391 100644 --- a/test/lib-Array.test.ts +++ b/test/lib-Array.test.ts @@ -94,5 +94,7 @@ type CaseLibArray = [ Expect, -1>>, Expect, -1>>, Expect, 1>>, + Expect{},(a:string)=>{},(b:string)=>{},()=>{}], (c:string)=>{}>, 2>>, + Expect, 1>>, ] diff --git a/test/script/lib-gen.sh b/test/script/lib-gen.sh index 19c31d7..96049b8 100644 --- a/test/script/lib-gen.sh +++ b/test/script/lib-gen.sh @@ -32,7 +32,7 @@ declare -A test_cases=( ["Array.Flat"]="[1,2,3]∷[1,2,3] [1,2,3,[]]∷[1,2,3] [1,2,[3]]∷[1,2,3] [1,2,[3,[0]]]∷[1,2,3,0] []∷[] [[]]∷[] [[[1]]]∷[1]" ["Array.Includes"]="[1,2,3]‖1∷true [1,2,3]‖-1∷false []‖\"\"∷false [\"\"]‖\"\"∷true [[]]‖[]∷true [[1]]‖1∷false" ["Array.IndexOf"]="[1,2,3]‖1∷0 [1,[2],3]‖[2]∷1 []‖0∷-1 [1,2,3]‖4∷-1 [1,2,1]‖1∷0" - ["Array.LastIndexOf"]="[1,2,1,2,1,3,4]‖1∷4 []‖1∷-1 [1,2,3]‖0∷-1 [[],[[]],[],[]]‖[[]]∷1" + ["Array.LastIndexOf"]="[1,2,1,2,1,3,4]‖1∷4 []‖1∷-1 [1,2,3]‖0∷-1 [[],[[]],[],[]]‖[[]]∷1 [()=>{},(a:string)=>{},(b:string)=>{},()=>{}]‖(c:string)=>{}∷2 [{a:string},{},{b:string}]‖{}∷1" ["Array.Join"]="[1,2,3]∷\"1,2,3\" [-1,\".\",9]‖\"-\"∷\"-1-.-9\" [1,2,3]‖\"\"∷\"123\"" ["Array.Pop"]="[1,2,3]∷[1,2] [1]‖\"get-rest\"∷[] []‖\"get-rest\"∷never [1,2,3]‖\"get-pop-element\"∷3 [1]‖\"get-pop-element\"∷1 []‖\"get-pop-element\"∷never" ["Array.Push"]="[1,2,3]‖\"1\"∷[1,2,3,\"1\"] []‖1∷[1] []‖[]∷[[]]"