From 5f9f27604b033c09ec6c40ec0a67f4453bf3711b Mon Sep 17 00:00:00 2001 From: thez3ro Date: Sun, 4 Mar 2018 22:25:28 +0100 Subject: [PATCH] fix autotype custom attributes --- src/autotype/AutoType.cpp | 3 ++- tests/TestAutoType.cpp | 45 +++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 92dab488..aa8064ba 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -659,6 +659,7 @@ bool AutoType::checkSyntax(const QString& string) QString delay = "DELAY=\\d+"; QString beep = "BEEP\\s\\d+\\s\\d+"; QString vkey = "VKEY(?:-[EN]X)?\\s\\w+"; + QString customAttributes = "S:(?:[^\\{\\}])+"; // these chars aren't in parentheses QString shortcutKeys = "[\\^\\%~\\+@]"; @@ -666,7 +667,7 @@ bool AutoType::checkSyntax(const QString& string) QString fixedStrings = "[^\\^\\%~\\+@\\{\\}]*"; QRegularExpression autoTypeSyntax("^(?:" + shortcutKeys + "|" + fixedStrings + "|\\{(?:" + normalCommands + "|" + specialLiterals + - "|" + functionKeys + "|" + numpad + "|" + delay + "|" + beep + "|" + vkey + ")\\})*$", + "|" + functionKeys + "|" + numpad + "|" + delay + "|" + beep + "|" + vkey + ")\\}|\\{" + customAttributes + "\\})*$", QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatch match = autoTypeSyntax.match(string); return match.hasMatch(); diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index 7590bc61..25790e3b 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -273,32 +273,41 @@ void TestAutoType::testGlobalAutoTypeRegExp() void TestAutoType::testAutoTypeSyntaxChecks() { // Huge sequence - QCOMPARE(true, AutoType::checkSyntax("{word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{SUBTRACT}~+%@fixedstring")); + QVERIFY(AutoType::checkSyntax("{word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{SUBTRACT}~+%@fixedstring")); - QCOMPARE(true, AutoType::checkSyntax("{NUMPAD1 3}")); + QVERIFY(AutoType::checkSyntax("{NUMPAD1 3}")); - QCOMPARE(true, AutoType::checkSyntax("{BEEP 3 3}")); - QCOMPARE(false, AutoType::checkSyntax("{BEEP 3}")); + QVERIFY(AutoType::checkSyntax("{S:SPECIALTOKEN}")); + QVERIFY(AutoType::checkSyntax("{S:SPECIAL TOKEN}")); + QVERIFY(AutoType::checkSyntax("{S:SPECIAL_TOKEN}")); + QVERIFY(AutoType::checkSyntax("{S:SPECIAL-TOKEN}")); + QVERIFY(AutoType::checkSyntax("{S:SPECIAL:TOKEN}")); + QVERIFY(AutoType::checkSyntax("{S:SPECIAL_TOKEN}{ENTER}")); + QVERIFY(AutoType::checkSyntax("{S:FOO}{S:HELLO WORLD}")); + QVERIFY(!AutoType::checkSyntax("{S:SPECIAL_TOKEN{}}")); - QCOMPARE(true, AutoType::checkSyntax("{VKEY 0x01}")); - QCOMPARE(true, AutoType::checkSyntax("{VKEY VK_LBUTTON}")); - QCOMPARE(true, AutoType::checkSyntax("{VKEY-EX 0x01}")); + QVERIFY(AutoType::checkSyntax("{BEEP 3 3}")); + QVERIFY(!AutoType::checkSyntax("{BEEP 3}")); + + QVERIFY(AutoType::checkSyntax("{VKEY 0x01}")); + QVERIFY(AutoType::checkSyntax("{VKEY VK_LBUTTON}")); + QVERIFY(AutoType::checkSyntax("{VKEY-EX 0x01}")); // Bad sequence - QCOMPARE(false, AutoType::checkSyntax("{{{}}{}{}}{{}}")); + QVERIFY(!AutoType::checkSyntax("{{{}}{}{}}{{}}")); // Good sequence - QCOMPARE(true, AutoType::checkSyntax("{{}{}}{}}{{}")); - QCOMPARE(true, AutoType::checkSyntax("{]}{[}{[}{]}")); - QCOMPARE(true, AutoType::checkSyntax("{)}{(}{(}{)}")); + QVERIFY(AutoType::checkSyntax("{{}{}}{}}{{}")); + QVERIFY(AutoType::checkSyntax("{]}{[}{[}{]}")); + QVERIFY(AutoType::checkSyntax("{)}{(}{(}{)}")); // High DelAY / low delay - QCOMPARE(true, AutoType::checkHighDelay("{DelAY 50000}")); - QCOMPARE(false, AutoType::checkHighDelay("{delay 50}")); + QVERIFY(AutoType::checkHighDelay("{DelAY 50000}")); + QVERIFY(!AutoType::checkHighDelay("{delay 50}")); // Slow typing - QCOMPARE(true, AutoType::checkSlowKeypress("{DelAY=50000}")); - QCOMPARE(false, AutoType::checkSlowKeypress("{delay=50}")); + QVERIFY(AutoType::checkSlowKeypress("{DelAY=50000}")); + QVERIFY(!AutoType::checkSlowKeypress("{delay=50}")); // Many repetition / few repetition / delay not repetition - QCOMPARE(true, AutoType::checkHighRepetition("{LEFT 50000000}")); - QCOMPARE(false, AutoType::checkHighRepetition("{SPACE 10}{TAB 3}{RIGHT 50}")); - QCOMPARE(false, AutoType::checkHighRepetition("{delay 5000000000}")); + QVERIFY(AutoType::checkHighRepetition("{LEFT 50000000}")); + QVERIFY(!AutoType::checkHighRepetition("{SPACE 10}{TAB 3}{RIGHT 50}")); + QVERIFY(!AutoType::checkHighRepetition("{delay 5000000000}")); } void TestAutoType::testAutoTypeEffectiveSequences()