|
| 1 | +package com.jayway.jsonpath.internal.function; |
| 2 | + |
| 3 | +import com.jayway.jsonpath.Configuration; |
| 4 | +import com.jayway.jsonpath.Configurations; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +/** |
| 8 | + * Test cases for functions |
| 9 | + * |
| 10 | + * -first |
| 11 | + * -last |
| 12 | + * -index(X) |
| 13 | + * |
| 14 | + * Created by git9527 on 6/11/22. |
| 15 | + */ |
| 16 | +public class SequentialPathFunctionTest extends BaseFunctionTest { |
| 17 | + |
| 18 | + private Configuration conf = Configurations.JACKSON_CONFIGURATION; |
| 19 | + |
| 20 | + @Test |
| 21 | + public void testFirstOfNumbers() throws Exception { |
| 22 | + verifyFunction(conf, "$.numbers.first()", NUMBER_SERIES, 1); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testLastOfNumbers() throws Exception { |
| 27 | + verifyFunction(conf, "$.numbers.last()", NUMBER_SERIES, 10); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testIndexOfNumbers() throws Exception { |
| 32 | + verifyFunction(conf, "$.numbers.index(0)", NUMBER_SERIES, 1); |
| 33 | + verifyFunction(conf, "$.numbers.index(-1)", NUMBER_SERIES, 10); |
| 34 | + verifyFunction(conf, "$.numbers.index(1)", NUMBER_SERIES, 2); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testFirstOfText() throws Exception { |
| 39 | + verifyFunction(conf, "$.text.first()", TEXT_SERIES, "a"); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testLastOfText() throws Exception { |
| 44 | + verifyFunction(conf, "$.text.last()", TEXT_SERIES, "f"); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testIndexOfText() throws Exception { |
| 49 | + verifyFunction(conf, "$.text.index(0)", TEXT_SERIES, "a"); |
| 50 | + verifyFunction(conf, "$.text.index(-1)", TEXT_SERIES, "f"); |
| 51 | + verifyFunction(conf, "$.text.index(1)", TEXT_SERIES, "b"); |
| 52 | + } |
| 53 | +} |
0 commit comments