Kalle Stenflo
9 years ago
8 changed files with 233 additions and 376 deletions
@ -1,54 +1,41 @@ |
|||||||
package com.jayway.jsonpath; |
package com.jayway.jsonpath; |
||||||
|
|
||||||
import com.jayway.jsonpath.internal.filter.FilterCompiler; |
|
||||||
import org.junit.Test; |
import org.junit.Test; |
||||||
|
|
||||||
|
import static com.jayway.jsonpath.internal.filter.FilterCompiler.compile; |
||||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||||
|
|
||||||
public class FilterCompilerTest { |
public class FilterCompilerTest { |
||||||
|
|
||||||
|
|
||||||
@Test |
@Test |
||||||
public void filter_compiler_test() { |
public void filter_compiler_test() { |
||||||
|
assertThat(compile("[?(@)]").toString()).isEqualTo("[?(@)]"); |
||||||
FilterCompiler.compile("[?(@)]"); |
assertThat(compile("[?(@)]").toString()).isEqualTo("[?(@)]"); |
||||||
|
assertThat(compile("[?(@.firstname)]").toString()).isEqualTo("[?(@['firstname'])]"); |
||||||
FilterCompiler.compile("[?($)]"); |
assertThat(compile("[?($.firstname)]").toString()).isEqualTo("[?($['firstname'])]"); |
||||||
|
assertThat(compile("[?(@['firstname'])]").toString()).isEqualTo("[?(@['firstname'])]"); |
||||||
FilterCompiler.compile("[?(@.firstname)]"); |
assertThat(compile("[?($['firstname'].lastname)]").toString()).isEqualTo("[?($['firstname']['lastname'])]"); |
||||||
FilterCompiler.compile("[?(@.firstname)]"); |
assertThat(compile("[?($['firstname']['lastname'])]").toString()).isEqualTo("[?($['firstname']['lastname'])]"); |
||||||
FilterCompiler.compile("[?($.firstname)]"); |
assertThat(compile("[?($['firstname']['lastname'].*)]").toString()).isEqualTo("[?($['firstname']['lastname'][*])]"); |
||||||
FilterCompiler.compile("[?(@['firstname'])]"); |
assertThat(compile("[?($['firstname']['num_eq'] == 1)]").toString()).isEqualTo("[?($['firstname']['num_eq'] == 1)]"); |
||||||
|
assertThat(compile("[?($['firstname']['num_gt'] > 1.1)]").toString()).isEqualTo("[?($['firstname']['num_gt'] > 1.1)]"); |
||||||
|
assertThat(compile("[?($['firstname']['num_lt'] < 11.11)]").toString()).isEqualTo("[?($['firstname']['num_lt'] < 11.11)]"); |
||||||
FilterCompiler.compile("[?($['firstname'].lastname)]"); |
assertThat(compile("[?($['firstname']['str_eq'] == 'hej')]").toString()).isEqualTo("[?($['firstname']['str_eq'] == 'hej')]"); |
||||||
FilterCompiler.compile("[?($['firstname']['lastname'])]"); |
assertThat(compile("[?($['firstname']['str_eq'] == '')]").toString()).isEqualTo("[?($['firstname']['str_eq'] == '')]"); |
||||||
|
assertThat(compile("[?($['firstname']['str_eq'] == null)]").toString()).isEqualTo("[?($['firstname']['str_eq'] == null)]"); |
||||||
FilterCompiler.compile("[?($['firstname']['lastname'].*)]"); |
assertThat(compile("[?($['firstname']['str_eq'] == true)]").toString()).isEqualTo("[?($['firstname']['str_eq'] == true)]"); |
||||||
|
assertThat(compile("[?($['firstname']['str_eq'] == false)]").toString()).isEqualTo("[?($['firstname']['str_eq'] == false)]"); |
||||||
FilterCompiler.compile("[?($['firstname']['num_eq'] == 1)]"); |
assertThat(compile("[?(@.firstname && @.lastname)]").toString()).isEqualTo("[?(@['firstname'] && @['lastname'])]"); |
||||||
FilterCompiler.compile("[?($['firstname']['num_gt'] > 1.1)]"); |
assertThat(compile("[?((@.firstname || @.lastname) && @.and)]").toString()).isEqualTo("[?((@['firstname'] || @['lastname']) && @['and'])]"); |
||||||
|
assertThat(compile("[?((@.a || @.b || @.c) && @.x)]").toString()).isEqualTo("[?((@['a'] || @['b'] || @['c']) && @['x'])]"); |
||||||
FilterCompiler.compile("[?($['firstname']['num_lt'] < 11.11)]"); |
assertThat(compile("[?((@.a && @.b && @.c) || @.x)]").toString()).isEqualTo("[?((@['a'] && @['b'] && @['c']) || @['x'])]"); |
||||||
|
assertThat(compile("[?((@.a && @.b || @.c) || @.x)]").toString()).isEqualTo("[?((@['a'] && (@['b'] || @['c'])) || @['x'])]"); |
||||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == 'hej')]"); |
assertThat(compile("[?((@.a && @.b) || (@.c && @.d))]").toString()).isEqualTo("[?((@['a'] && @['b']) || (@['c'] && @['d']))]"); |
||||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == '')]"); |
assertThat(compile("[?(@.a IN [1,2,3])]").toString()).isEqualTo("[?(@['a'] IN [1,2,3])]"); |
||||||
|
assertThat(compile("[?(@.a IN {'foo':'bar'})]").toString()).isEqualTo("[?(@['a'] IN {'foo':'bar'})]"); |
||||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == null)]"); |
assertThat(compile("[?(@.value<'7')]").toString()).isEqualTo("[?(@['value'] < '7')]"); |
||||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == true)]"); |
assertThat(compile("[?(@.message == 'it\\\\')]").toString()).isEqualTo("[?(@['message'] == 'it\\\\')]"); |
||||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == false)]"); |
|
||||||
|
|
||||||
|
|
||||||
FilterCompiler.compile("[?(@.firstname && @.lastname)]"); |
|
||||||
FilterCompiler.compile("[?((@.firstname || @.lastname) && @.and)]"); |
|
||||||
|
|
||||||
FilterCompiler.compile("[?((@.a || @.b || @.c) && @.x)]"); |
|
||||||
FilterCompiler.compile("[?((@.a && @.b && @.c) || @.x)]"); |
|
||||||
FilterCompiler.compile("[?((@.a && @.b || @.c) || @.x)]"); |
|
||||||
FilterCompiler.compile("[?((@.a && @.b) || (@.c && @.d))]"); |
|
||||||
|
|
||||||
|
|
||||||
FilterCompiler.compile("[?(@.a IN [1,2,3])]"); |
|
||||||
FilterCompiler.compile("[?(@.a IN {'foo':'bar'})]"); |
|
||||||
FilterCompiler.compile("[?(@.value<'7')]"); |
|
||||||
|
|
||||||
FilterCompiler.compile("[?(@.message == 'it\\\\')]"); |
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
@ -0,0 +1,17 @@ |
|||||||
|
package com.jayway.jsonpath.internal; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
public class UtilsTest { |
||||||
|
|
||||||
|
|
||||||
|
@Test |
||||||
|
public void strings_can_be_escaped() { |
||||||
|
|
||||||
|
String str = "it\\\\"; |
||||||
|
System.out.println(Utils.unescape(str)); |
||||||
|
System.out.println(Utils.escape(str, true)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue