Преглед изворни кода

feat(expressions): allow expr() to be called without parameters

Update expr() convenience function to accept nullable first parameter
with default value, enabling calls without any arguments. Also fix
ParameterExpression string formatting to use printf instead of
string template syntax.
Billy Barrow пре 1 месец
родитељ
комит
752d726731

+ 4 - 1
src/lib/Expressions/Convenience.vala

@@ -1,7 +1,10 @@
 
 namespace Invercargill.Expressions {
 
-    public Expression expr(string expression, Element first, ...) throws ExpressionError {
+    public Expression expr(string expression, Element? first = null, ...) throws ExpressionError {
+        if(first == null) {
+            return ExpressionParser.parse(expression);
+        }
         return ExpressionParser.parse_with_params(expression, Wrap.va_list<Element>(first, va_list()));
     }
 

+ 1 - 1
src/lib/Expressions/Expressions/ParameterExpression.vala

@@ -46,7 +46,7 @@ namespace Invercargill.Expressions {
         }
 
         public override string to_expression_string() {
-            return @"$$index";
+            return "$%d".printf(index);
         }
     }
 }

+ 3 - 3
src/tests/TestRunner.vala

@@ -39,9 +39,9 @@ public static int main(string[] args) {
     //  modifiers_tests();
     //  data_structures_tests();
     //  remaining_components_tests();
-    //  expression_tests();
-    nullable_tests();
-    native_element_tests();
+    expression_tests();
+    //  nullable_tests();
+    //  native_element_tests();
 
     var result = Test.run();