View | Details | Raw Unified | Return to bug 64198
Collapse All | Expand All

(-)a/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java (-2 / +12 lines)
Lines 125-134 class FunctionParser { Link Here
125
                    buffer.append(current[0]);
125
                    buffer.append(current[0]);
126
                } else if (current[0] == '(' && previous != ' ') {
126
                } else if (current[0] == '(' && previous != ' ') {
127
                    String funcName = buffer.toString();
127
                    String funcName = buffer.toString();
128
                    function = CompoundVariable.getNamedFunction(funcName);
128
                    function = CompoundVariable.getNamedFunction(funcName.trim());
129
                    if (function instanceof Function) {
129
                    if (function instanceof Function) {
130
                        ((Function) function).setParameters(parseParams(reader));
130
                        ((Function) function).setParameters(parseParams(reader));
131
                        if (reader.read(current) == 0 || current[0] != '}') {
131
                        if (firstNonSpace(reader, '#') != '}') {
132
                            reader.reset();// set to start of string
132
                            reader.reset();// set to start of string
133
                            char []cb = new char[100];
133
                            char []cb = new char[100];
134
                            int nbRead = reader.read(cb);
134
                            int nbRead = reader.read(cb);
Lines 162-167 class FunctionParser { Link Here
162
        return buffer.toString();
162
        return buffer.toString();
163
    }
163
    }
164
164
165
    private char firstNonSpace(StringReader reader, char defaultResult) throws IOException {
166
        char[] current = new char[1];
167
        while (reader.read(current) == 1) {
168
            if (!Character.isSpaceChar(current[0])) {
169
                return current[0];
170
            }
171
        }
172
        return defaultResult;
173
    }
174
165
    /**
175
    /**
166
     * Compile a String into a list of parameters, each made into a
176
     * Compile a String into a list of parameters, each made into a
167
     * CompoundVariable.
177
     * CompoundVariable.
(-)a/src/core/src/test/groovy/org/apache/jmeter/engine/util/FunctionParserSpec.groovy (-1 / +62 lines)
Line 0 Link Here
0
- 
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to you under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
package org.apache.jmeter.engine.util
19
20
import org.apache.jmeter.functions.Function
21
import org.apache.jmeter.samplers.SampleResult
22
import org.apache.jmeter.samplers.Sampler
23
24
import spock.lang.Specification
25
import spock.lang.Unroll
26
27
@Unroll
28
class FunctionParserSpec extends Specification {
29
    def "function '#value' gets compiled"() {
30
        given:
31
            CompoundVariable.functions.put('__func', Func.class)
32
            def parser = new FunctionParser()
33
        when:
34
            def result = parser.compileString(value)
35
        then:
36
            "$result" == "$expected"
37
        where:
38
            value           | expected
39
            '${__func()}'   | [new Func()]
40
            '${ __func()}'  | [new Func()]
41
            '${__func() }'  | [new Func()]
42
            '${ __func() }' | [new Func()]
43
    }
44
45
    public static class Func implements Function {
46
        void setParameters(Collection params) {
47
            // do nothing
48
        }
49
        String getReferenceKey() {
50
            return "__func"
51
        }
52
        List<String> getArgumentDesc() {
53
            return Collections.emptyList()
54
        }
55
        String execute(SampleResult result, Sampler sampler) {
56
            return "done"
57
        }
58
        String toString() {
59
            return "__func()"
60
        }
61
    }
62
}

Return to bug 64198