Kalle Stenflo
9 years ago
8 changed files with 233 additions and 376 deletions
@ -1,54 +1,41 @@
|
||||
package com.jayway.jsonpath; |
||||
|
||||
import com.jayway.jsonpath.internal.filter.FilterCompiler; |
||||
import org.junit.Test; |
||||
|
||||
import static com.jayway.jsonpath.internal.filter.FilterCompiler.compile; |
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
public class FilterCompilerTest { |
||||
|
||||
|
||||
@Test |
||||
public void filter_compiler_test() { |
||||
|
||||
FilterCompiler.compile("[?(@)]"); |
||||
|
||||
FilterCompiler.compile("[?($)]"); |
||||
|
||||
FilterCompiler.compile("[?(@.firstname)]"); |
||||
FilterCompiler.compile("[?(@.firstname)]"); |
||||
FilterCompiler.compile("[?($.firstname)]"); |
||||
FilterCompiler.compile("[?(@['firstname'])]"); |
||||
|
||||
|
||||
FilterCompiler.compile("[?($['firstname'].lastname)]"); |
||||
FilterCompiler.compile("[?($['firstname']['lastname'])]"); |
||||
|
||||
FilterCompiler.compile("[?($['firstname']['lastname'].*)]"); |
||||
|
||||
FilterCompiler.compile("[?($['firstname']['num_eq'] == 1)]"); |
||||
FilterCompiler.compile("[?($['firstname']['num_gt'] > 1.1)]"); |
||||
|
||||
FilterCompiler.compile("[?($['firstname']['num_lt'] < 11.11)]"); |
||||
|
||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == 'hej')]"); |
||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == '')]"); |
||||
|
||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == null)]"); |
||||
FilterCompiler.compile("[?($['firstname']['str_eq'] == true)]"); |
||||
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\\\\')]"); |
||||
assertThat(compile("[?(@)]").toString()).isEqualTo("[?(@)]"); |
||||
assertThat(compile("[?(@)]").toString()).isEqualTo("[?(@)]"); |
||||
assertThat(compile("[?(@.firstname)]").toString()).isEqualTo("[?(@['firstname'])]"); |
||||
assertThat(compile("[?($.firstname)]").toString()).isEqualTo("[?($['firstname'])]"); |
||||
assertThat(compile("[?(@['firstname'])]").toString()).isEqualTo("[?(@['firstname'])]"); |
||||
assertThat(compile("[?($['firstname'].lastname)]").toString()).isEqualTo("[?($['firstname']['lastname'])]"); |
||||
assertThat(compile("[?($['firstname']['lastname'])]").toString()).isEqualTo("[?($['firstname']['lastname'])]"); |
||||
assertThat(compile("[?($['firstname']['lastname'].*)]").toString()).isEqualTo("[?($['firstname']['lastname'][*])]"); |
||||
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)]"); |
||||
assertThat(compile("[?($['firstname']['str_eq'] == 'hej')]").toString()).isEqualTo("[?($['firstname']['str_eq'] == 'hej')]"); |
||||
assertThat(compile("[?($['firstname']['str_eq'] == '')]").toString()).isEqualTo("[?($['firstname']['str_eq'] == '')]"); |
||||
assertThat(compile("[?($['firstname']['str_eq'] == null)]").toString()).isEqualTo("[?($['firstname']['str_eq'] == null)]"); |
||||
assertThat(compile("[?($['firstname']['str_eq'] == true)]").toString()).isEqualTo("[?($['firstname']['str_eq'] == true)]"); |
||||
assertThat(compile("[?($['firstname']['str_eq'] == false)]").toString()).isEqualTo("[?($['firstname']['str_eq'] == false)]"); |
||||
assertThat(compile("[?(@.firstname && @.lastname)]").toString()).isEqualTo("[?(@['firstname'] && @['lastname'])]"); |
||||
assertThat(compile("[?((@.firstname || @.lastname) && @.and)]").toString()).isEqualTo("[?((@['firstname'] || @['lastname']) && @['and'])]"); |
||||
assertThat(compile("[?((@.a || @.b || @.c) && @.x)]").toString()).isEqualTo("[?((@['a'] || @['b'] || @['c']) && @['x'])]"); |
||||
assertThat(compile("[?((@.a && @.b && @.c) || @.x)]").toString()).isEqualTo("[?((@['a'] && @['b'] && @['c']) || @['x'])]"); |
||||
assertThat(compile("[?((@.a && @.b || @.c) || @.x)]").toString()).isEqualTo("[?((@['a'] && (@['b'] || @['c'])) || @['x'])]"); |
||||
assertThat(compile("[?((@.a && @.b) || (@.c && @.d))]").toString()).isEqualTo("[?((@['a'] && @['b']) || (@['c'] && @['d']))]"); |
||||
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'})]"); |
||||
assertThat(compile("[?(@.value<'7')]").toString()).isEqualTo("[?(@['value'] < '7')]"); |
||||
assertThat(compile("[?(@.message == 'it\\\\')]").toString()).isEqualTo("[?(@['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