From f4942524262413484b87519a0cbb9b5a41b2399e Mon Sep 17 00:00:00 2001 From: Banaanae <83927639+Banaanae@users.noreply.github.com> Date: Fri, 4 Oct 2024 08:27:18 +1000 Subject: [PATCH] improve #298; added failing test added f tests for #294 #295 #296 #298 #299 #300 #301 cleanup return tests --- ConvertFuncs.ahk | 4 ++-- tests/Failed conversions/ByRef_ex3.ah1 | 8 ++++++++ tests/Failed conversions/ByRef_ex3.ah2 | 8 ++++++++ .../Failed conversions/DblQuoteMsgBox_ex1.ah1 | 7 +++++++ .../Failed conversions/DblQuoteMsgBox_ex1.ah2 | 7 +++++++ tests/Failed conversions/DllCall_ex12.ah1 | 18 ++++++++++++++++++ tests/Failed conversions/DllCall_ex12.ah2 | 18 ++++++++++++++++++ tests/Failed conversions/GlobalGui_ex1.ah1 | 7 +++++++ tests/Failed conversions/GlobalGui_ex1.ah2 | 9 +++++++++ tests/Failed conversions/MsgBox_ex7.ah1 | 18 ++++++++++++++++++ tests/Failed conversions/MsgBox_ex7.ah2 | 18 ++++++++++++++++++ .../Failed conversions/TernaryDblQuote_ex1.ah1 | 1 + .../Failed conversions/TernaryDblQuote_ex1.ah2 | 1 + tests/Failed conversions/static_ex1.ah1 | 6 ++++++ tests/Failed conversions/static_ex1.ah2 | 6 ++++++ .../Test_Folder/Flow of Control/ByRef_ex2.ah1 | 5 +++++ .../Test_Folder/Flow of Control/ByRef_ex2.ah2 | 5 +++++ .../{Return_ex1.ah1 => Return_ex1-2.ah1} | 4 +++- .../{Return_ex1.ah2 => Return_ex1-2.ah2} | 4 +++- .../Test_Folder/Flow of Control/Return_ex2.ah1 | 1 - .../Test_Folder/Flow of Control/Return_ex2.ah2 | 1 - 21 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 tests/Failed conversions/ByRef_ex3.ah1 create mode 100644 tests/Failed conversions/ByRef_ex3.ah2 create mode 100644 tests/Failed conversions/DblQuoteMsgBox_ex1.ah1 create mode 100644 tests/Failed conversions/DblQuoteMsgBox_ex1.ah2 create mode 100644 tests/Failed conversions/DllCall_ex12.ah1 create mode 100644 tests/Failed conversions/DllCall_ex12.ah2 create mode 100644 tests/Failed conversions/GlobalGui_ex1.ah1 create mode 100644 tests/Failed conversions/GlobalGui_ex1.ah2 create mode 100644 tests/Failed conversions/MsgBox_ex7.ah1 create mode 100644 tests/Failed conversions/MsgBox_ex7.ah2 create mode 100644 tests/Failed conversions/TernaryDblQuote_ex1.ah1 create mode 100644 tests/Failed conversions/TernaryDblQuote_ex1.ah2 create mode 100644 tests/Failed conversions/static_ex1.ah1 create mode 100644 tests/Failed conversions/static_ex1.ah2 create mode 100644 tests/Test_Folder/Flow of Control/ByRef_ex2.ah1 create mode 100644 tests/Test_Folder/Flow of Control/ByRef_ex2.ah2 rename tests/Test_Folder/Flow of Control/{Return_ex1.ah1 => Return_ex1-2.ah1} (63%) rename tests/Test_Folder/Flow of Control/{Return_ex1.ah2 => Return_ex1-2.ah2} (63%) delete mode 100644 tests/Test_Folder/Flow of Control/Return_ex2.ah1 delete mode 100644 tests/Test_Folder/Flow of Control/Return_ex2.ah2 diff --git a/ConvertFuncs.ahk b/ConvertFuncs.ahk index 4123de58..d14b9030 100644 --- a/ConvertFuncs.ahk +++ b/ConvertFuncs.ahk @@ -4242,7 +4242,7 @@ FixByRefParams(ScriptString) { Line := A_LoopField replacement := false for func, v in gmByRefParamMap { - if RegExMatch(Line, "(^|.*\W)\Q" func "\E\((.*)\)", &match) ; Nested functions break and cont. sections this + if RegExMatch(Line, "(^|.*\W)\Q" func "\E\((.*)\)(.*?)$", &match) ; Nested functions break and cont. sections this && !InStr(Line, "&") { ; Not defining a function retLine := match[1] func "(" params := match[2] @@ -4254,7 +4254,7 @@ FixByRefParams(ScriptString) { } params := StrReplace(params, MatchFuncParams[],,,, 1) } - retLine := RTrim(retLine, ", ") ")" + retLine := RTrim(retLine, ", ") ")" match[3] replacement := true } } diff --git a/tests/Failed conversions/ByRef_ex3.ah1 b/tests/Failed conversions/ByRef_ex3.ah1 new file mode 100644 index 00000000..d9161d7a --- /dev/null +++ b/tests/Failed conversions/ByRef_ex3.ah1 @@ -0,0 +1,8 @@ +MyFunc(ByRef a, ByRef b) {} + +MyFunc(a, b) +MyFunc(a, b), a = b ; Stripped +MyFunc(a, b) ; Stripped + +; MyFunc(a, b), Ord(1) +; MyFunc(a, b), MyFunc(a, b) \ No newline at end of file diff --git a/tests/Failed conversions/ByRef_ex3.ah2 b/tests/Failed conversions/ByRef_ex3.ah2 new file mode 100644 index 00000000..8da36a24 --- /dev/null +++ b/tests/Failed conversions/ByRef_ex3.ah2 @@ -0,0 +1,8 @@ +MyFunc(&a, &b) {} + +MyFunc(&a, &b) +MyFunc(&a, &b), a = b ; Stripped +MyFunc(&a, &b) ; Stripped + +; MyFunc(a, b), Ord(1) +; MyFunc(a, b), MyFunc(a, b) \ No newline at end of file diff --git a/tests/Failed conversions/DblQuoteMsgBox_ex1.ah1 b/tests/Failed conversions/DblQuoteMsgBox_ex1.ah1 new file mode 100644 index 00000000..07dd2311 --- /dev/null +++ b/tests/Failed conversions/DblQuoteMsgBox_ex1.ah1 @@ -0,0 +1,7 @@ +F1:: MsgBox % """" ; " +F2:: MsgBox % "abc""123" ; abc"123 +F3:: MsgBox % "abc""123" MyFunc("", "123""abc") "" ; abc"123123"abc + +MyFunc(a, b) { + return a b +} \ No newline at end of file diff --git a/tests/Failed conversions/DblQuoteMsgBox_ex1.ah2 b/tests/Failed conversions/DblQuoteMsgBox_ex1.ah2 new file mode 100644 index 00000000..8b0c0bce --- /dev/null +++ b/tests/Failed conversions/DblQuoteMsgBox_ex1.ah2 @@ -0,0 +1,7 @@ +F1::MsgBox("`"") ; " +F2::MsgBox("abc`"123") ; abc"123 +F3::MsgBox("abc`"123" MyFunc("", "123`"abc") "") ; abc"123123"abc + +MyFunc(a, b) { + return a b +} \ No newline at end of file diff --git a/tests/Failed conversions/DllCall_ex12.ah1 b/tests/Failed conversions/DllCall_ex12.ah1 new file mode 100644 index 00000000..1ae6b6fa --- /dev/null +++ b/tests/Failed conversions/DllCall_ex12.ah1 @@ -0,0 +1,18 @@ +var := DllCall("Func" + , "Str", "ABC" ; Comment + , "Str, "123" ; Comment + , "Str", "DEF") ;Comment + +hCtrl := DllCall("CreateWindowEx" + , "Uint", 0x200 ; WS_EX_CLIENTEDGE + , "str", "HiEdit" ; ClassName + , "str", "" ; This line causes the issue + , "Uint", WS_CLIPCHILDREN | WS_CHILD | WS_VISIBLE | hStyle + , "int", X ; Left + , "int", Y ; Top + , "int", W ; Width + , "int", H ; Height + , "Uint", HParent ; hWndParent + , "Uint", MODULEID ; hMenu + , "Uint", 0 ; hInstance + , "Uint", 0, "Uint") \ No newline at end of file diff --git a/tests/Failed conversions/DllCall_ex12.ah2 b/tests/Failed conversions/DllCall_ex12.ah2 new file mode 100644 index 00000000..1ae6b6fa --- /dev/null +++ b/tests/Failed conversions/DllCall_ex12.ah2 @@ -0,0 +1,18 @@ +var := DllCall("Func" + , "Str", "ABC" ; Comment + , "Str, "123" ; Comment + , "Str", "DEF") ;Comment + +hCtrl := DllCall("CreateWindowEx" + , "Uint", 0x200 ; WS_EX_CLIENTEDGE + , "str", "HiEdit" ; ClassName + , "str", "" ; This line causes the issue + , "Uint", WS_CLIPCHILDREN | WS_CHILD | WS_VISIBLE | hStyle + , "int", X ; Left + , "int", Y ; Top + , "int", W ; Width + , "int", H ; Height + , "Uint", HParent ; hWndParent + , "Uint", MODULEID ; hMenu + , "Uint", 0 ; hInstance + , "Uint", 0, "Uint") \ No newline at end of file diff --git a/tests/Failed conversions/GlobalGui_ex1.ah1 b/tests/Failed conversions/GlobalGui_ex1.ah1 new file mode 100644 index 00000000..831648f3 --- /dev/null +++ b/tests/Failed conversions/GlobalGui_ex1.ah1 @@ -0,0 +1,7 @@ +MyFunc() { + Gui, Add, Text,, Gui + Gui, Show, w150 +} +MyFunc() + +F1::Gui, Destroy \ No newline at end of file diff --git a/tests/Failed conversions/GlobalGui_ex1.ah2 b/tests/Failed conversions/GlobalGui_ex1.ah2 new file mode 100644 index 00000000..9185ca8a --- /dev/null +++ b/tests/Failed conversions/GlobalGui_ex1.ah2 @@ -0,0 +1,9 @@ +MyFunc() { + global ; V1toV2: Made function global + myGui := Gui() + myGui.Add("Text", , "Gui") + myGui.Show("w150") +} +MyFunc() + +F1::myGui.Destroy() \ No newline at end of file diff --git a/tests/Failed conversions/MsgBox_ex7.ah1 b/tests/Failed conversions/MsgBox_ex7.ah1 new file mode 100644 index 00000000..a11b8607 --- /dev/null +++ b/tests/Failed conversions/MsgBox_ex7.ah1 @@ -0,0 +1,18 @@ +Switch Var +{ +Case 1: MsgBox Test1 +Case 2: +MsgBox Test2 +} +IfMsgBox, Ok + MsgBox + +Switch Var +{ +Case 1: +MsgBox Test1 +Case 2: +MsgBox Test2 +} +IfMsgBox, Ok + MsgBox \ No newline at end of file diff --git a/tests/Failed conversions/MsgBox_ex7.ah2 b/tests/Failed conversions/MsgBox_ex7.ah2 new file mode 100644 index 00000000..7a5c45d5 --- /dev/null +++ b/tests/Failed conversions/MsgBox_ex7.ah2 @@ -0,0 +1,18 @@ +Switch Var +{ +Case 1: msgResult := MsgBox("Test1") +Case 2: +msgResult := MsgBox("Test2") +} +if (msgResult = "Ok") + MsgBox() + +Switch Var +{ +Case 1: +msgResult := MsgBox("Test1") +Case 2: +msgResult := MsgBox("Test2") +} +if (msgResult = "Ok") + MsgBox() \ No newline at end of file diff --git a/tests/Failed conversions/TernaryDblQuote_ex1.ah1 b/tests/Failed conversions/TernaryDblQuote_ex1.ah1 new file mode 100644 index 00000000..14a29fc8 --- /dev/null +++ b/tests/Failed conversions/TernaryDblQuote_ex1.ah1 @@ -0,0 +1 @@ +x := x = "" ? 0 : "" \ No newline at end of file diff --git a/tests/Failed conversions/TernaryDblQuote_ex1.ah2 b/tests/Failed conversions/TernaryDblQuote_ex1.ah2 new file mode 100644 index 00000000..14a29fc8 --- /dev/null +++ b/tests/Failed conversions/TernaryDblQuote_ex1.ah2 @@ -0,0 +1 @@ +x := x = "" ? 0 : "" \ No newline at end of file diff --git a/tests/Failed conversions/static_ex1.ah1 b/tests/Failed conversions/static_ex1.ah1 new file mode 100644 index 00000000..baa97fbe --- /dev/null +++ b/tests/Failed conversions/static_ex1.ah1 @@ -0,0 +1,6 @@ +MyFunc() { + static var = 1 + static var1=1,var2,var3=3 + MsgBox % var +} +MyFunc() \ No newline at end of file diff --git a/tests/Failed conversions/static_ex1.ah2 b/tests/Failed conversions/static_ex1.ah2 new file mode 100644 index 00000000..d818c57c --- /dev/null +++ b/tests/Failed conversions/static_ex1.ah2 @@ -0,0 +1,6 @@ +MyFunc() { + static var := 1 + static var1:=1,var2,var3:=3 + MsgBox(var) +} +MyFunc() \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/ByRef_ex2.ah1 b/tests/Test_Folder/Flow of Control/ByRef_ex2.ah1 new file mode 100644 index 00000000..746afb57 --- /dev/null +++ b/tests/Test_Folder/Flow of Control/ByRef_ex2.ah1 @@ -0,0 +1,5 @@ +MyFunc(ByRef a, ByRef b) {} + +MyFunc(a, b) +MyFunc(a, b), a = b ; Stripped +MyFunc(a, b) ; Stripped \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/ByRef_ex2.ah2 b/tests/Test_Folder/Flow of Control/ByRef_ex2.ah2 new file mode 100644 index 00000000..9883a748 --- /dev/null +++ b/tests/Test_Folder/Flow of Control/ByRef_ex2.ah2 @@ -0,0 +1,5 @@ +MyFunc(&a, &b) {} + +MyFunc(&a, &b) +MyFunc(&a, &b), a = b ; Stripped +MyFunc(&a, &b) ; Stripped \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/Return_ex1.ah1 b/tests/Test_Folder/Flow of Control/Return_ex1-2.ah1 similarity index 63% rename from tests/Test_Folder/Flow of Control/Return_ex1.ah1 rename to tests/Test_Folder/Flow of Control/Return_ex1-2.ah1 index a8f2bb1c..4ca6860d 100644 --- a/tests/Test_Folder/Flow of Control/Return_ex1.ah1 +++ b/tests/Test_Folder/Flow of Control/Return_ex1-2.ah1 @@ -3,4 +3,6 @@ MyFunc() { Return, Trim(ToReturn, "Error") } -MsgBox % MyFunc() \ No newline at end of file +MsgBox % MyFunc() + +MsgBox("Return, Test") \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/Return_ex1.ah2 b/tests/Test_Folder/Flow of Control/Return_ex1-2.ah2 similarity index 63% rename from tests/Test_Folder/Flow of Control/Return_ex1.ah2 rename to tests/Test_Folder/Flow of Control/Return_ex1-2.ah2 index ceb29260..f21d5914 100644 --- a/tests/Test_Folder/Flow of Control/Return_ex1.ah2 +++ b/tests/Test_Folder/Flow of Control/Return_ex1-2.ah2 @@ -3,4 +3,6 @@ MyFunc() { Return Trim(ToReturn, "Error") } -MsgBox(MyFunc()) \ No newline at end of file +MsgBox(MyFunc()) + +MsgBox("Return, Test") \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/Return_ex2.ah1 b/tests/Test_Folder/Flow of Control/Return_ex2.ah1 deleted file mode 100644 index a37a9d23..00000000 --- a/tests/Test_Folder/Flow of Control/Return_ex2.ah1 +++ /dev/null @@ -1 +0,0 @@ -MsgBox("Return, Test") \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/Return_ex2.ah2 b/tests/Test_Folder/Flow of Control/Return_ex2.ah2 deleted file mode 100644 index a37a9d23..00000000 --- a/tests/Test_Folder/Flow of Control/Return_ex2.ah2 +++ /dev/null @@ -1 +0,0 @@ -MsgBox("Return, Test") \ No newline at end of file