Script { public static StringUtils.Pair parseVariableAndPath(String text) { Matcher matcher = VAR_AND_PATH_PATTERN.matcher(text); matcher.find(); String name = text.substring(0, matcher.end()); String path; if (matcher.end() == text.length()) { path = ""; } else { path = text.substring(matcher.end()); } if (isXmlPath(path) || isXmlPathFunction(path)) { } else { path = "$" + path; } return StringUtils.pair(name, path); } private  Script(); static final boolean isCallSyntax(String text); static final boolean isCallOnceSyntax(String text); static final boolean isGetSyntax(String text); static final boolean isJson(String text); static final boolean isJsonPath(String text); static final boolean isXml(String text); static final boolean isXmlPath(String text); static final boolean isXmlPathFunction(String text); static final boolean isEmbeddedExpression(String text); static final boolean isWithinParentheses(String text); static final boolean isContainsMacro(String text); static final boolean isContainsOnlyMacro(String text); static final boolean isContainsAnyMacro(String text); static final boolean isNotContainsMacro(String text); static final boolean isDollarPrefixedJsonPath(String text); static final boolean isDollarPrefixedParen(String text); static final boolean isDollarPrefixed(String text); static final boolean isVariable(String text); static final boolean isVariableAndSpaceAndPath(String text); static StringUtils.Pair parseVariableAndPath(String text); static ScriptValue evalKarateExpressionForMatch(String text, ScenarioContext context); static ScriptValue getIfVariableReference(String text, ScenarioContext context); static ScriptValue evalKarateExpression(String text, ScenarioContext context); static ScriptValue evalXmlPathOnVarByName(String name, String path, ScenarioContext context); static ScriptValue evalXmlPathOnXmlNode(Node doc, String path); static ScriptValue evalJsonPathOnVarByName(String name, String exp, ScenarioContext context); static ScriptValue evalJsExpression(String exp, ScenarioContext context); static ScriptValue evalJsExpression(String exp, ScenarioContext context, ScriptValue selfValue, Object root, Object parent); static boolean isValidVariableName(String name); static void evalJsonEmbeddedExpressions(DocumentContext doc, ScenarioContext context); static void evalXmlEmbeddedExpressions(Node node, ScenarioContext context); static ScriptValue copy(String name, String exp, ScenarioContext context, boolean validateName); static ScriptValue assign(String name, String exp, ScenarioContext context); static ScriptValue assign(AssignType assignType, String name, String exp, ScenarioContext context, boolean validateName); static DocumentContext toJsonDoc(ScriptValue sv, ScenarioContext context); static AssertionResult matchNamed(MatchType matchType, String expression, String path, String expected, ScenarioContext context); static AssertionResult matchScriptValue(MatchType matchType, ScriptValue actual, String path, String expected, ScenarioContext context); static AssertionResult matchString(MatchType matchType, ScriptValue actual, String expected, String path, ScenarioContext context); static boolean isMacro(String text); static boolean isOptionalMacro(String text); static AssertionResult matchStringOrPattern(char delimiter, String path, MatchType stringMatchType,
            Object actRoot, Object actParent, ScriptValue actValue, String expected, ScenarioContext context); static AssertionResult matchXml(MatchType matchType, ScriptValue actual, String path, String expression, ScenarioContext context); static AssertionResult matchJsonOrObject(MatchType matchType, ScriptValue actual, String path, String expression, ScenarioContext context); static AssertionResult matchFailed(MatchType matchType, String path,
            Object actObject, Object expObject, String reason); static AssertionResult matchNestedObject(char delimiter, String path, MatchType matchType,
            Object actRoot, Object actParent, Object actObject, Object expObject, ScenarioContext context); static boolean isPrimitive(Class clazz); static void removeValueByPath(String name, String path, ScenarioContext context); static void setValueByPath(String name, String path, ScriptValue value, ScenarioContext context); static void setValueByPath(String name, String path, String exp, ScenarioContext context); static void setValueByPath(String name, String path, String exp, boolean delete, ScenarioContext context, boolean viaTable); static void setValueByPath(String name, String path, ScriptValue value, boolean delete, ScenarioContext context, boolean viaTable); static ScriptValue call(ScriptValue called, String argString, ScenarioContext context, boolean reuseParentConfig); static ScriptValue evalJavaFunctionCall(Function function, Object callArg, ScenarioContext context); static ScriptValue evalJsFunctionCall(ScriptObjectMirror som, Object callArg, ScenarioContext context); static ScriptValue evalFeatureCall(Feature feature, Object callArg, ScenarioContext context, boolean reuseParentConfig); static StringUtils.Pair parseCallArgs(String line); static void callAndUpdateConfigAndAlsoVarsIfMapReturned(boolean callOnce, String name, String arg, ScenarioContext context); static AssertionResult assertBoolean(String expression, ScenarioContext context); static String replacePlaceholderText(String text, String token, String replaceWith, ScenarioContext context); static String replacePlaceholders(String text, List<Map<String, String>> list, ScenarioContext context); static List<Map<String, Object>> evalTable(List<Map<String, String>> list, ScenarioContext context); static void setByPathTable(String name, String path, List<Map<String, String>> list, ScenarioContext context); static final String VAR_SELF; static final String VAR_ROOT; static final String VAR_PARENT; static final String VAR_LOOP; static final String VAR_ARG; static final String VAR_HEADER; static final Map<String, Validator> VALIDATORS; }
@Test public void testParsingVariableAndJsonPath() { assertEquals(StringUtils.pair("foo", "$"), Script.parseVariableAndPath("foo")); assertEquals(StringUtils.pair("foo", "$.bar"), Script.parseVariableAndPath("foo.bar")); assertEquals(StringUtils.pair("foo", "$['bar']"), Script.parseVariableAndPath("foo['bar']")); assertEquals(StringUtils.pair("foo", "$[0]"), Script.parseVariableAndPath("foo[0]")); assertEquals(StringUtils.pair("foo", "$[0].bar"), Script.parseVariableAndPath("foo[0].bar")); assertEquals(StringUtils.pair("foo", "$[0]['bar']"), Script.parseVariableAndPath("foo[0]['bar']")); assertEquals(StringUtils.pair("foo", "/bar"), Script.parseVariableAndPath("foo/bar")); assertEquals(StringUtils.pair("foo", "/"), Script.parseVariableAndPath("foo/")); assertEquals(StringUtils.pair("foo", "/bar/baz[1]/ban"), Script.parseVariableAndPath("foo/bar/baz[1]/ban")); }