-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue_590 and add testcases (#720)
fix issue_590 and add testcases
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
json-path/src/test/java/com/jayway/jsonpath/ScientificNotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.jayway.jsonpath; | ||
|
||
import com.google.gson.JsonArray; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static com.jayway.jsonpath.JsonPath.using; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
//test for issue: https://github.com/json-path/JsonPath/issues/590 | ||
public class ScientificNotationTest extends BaseTest { | ||
|
||
final String sci_rep_array = "{\"num_array\": [" + | ||
"{\"num\":1}," + | ||
"{\"num\":-1e-10}," + | ||
"{\"num\":0.1e10},"+ | ||
"{\"num\":2E-20}," + | ||
"{\"num\":-0.2E20}" + | ||
" ]}"; | ||
|
||
@Test | ||
public void testScientificNotation() { | ||
List<JsonArray> result = using(Configuration.defaultConfiguration()) | ||
.parse(sci_rep_array) | ||
.read("$.num_array[?(@.num == 1 || @.num == -1e-10 || @.num == 0.1e10 || @.num == 2E-20 || @.num == -0.2E20)]"); | ||
|
||
assertThat(result.toString()).isEqualTo("[{\"num\":1},{\"num\":-1.0E-10},{\"num\":1.0E9},{\"num\":2.0E-20},{\"num\":-2.0E19}]"); | ||
} | ||
@Test | ||
public void testScientificNotation_lt_gt() { | ||
List<JsonArray> result; | ||
result = using(Configuration.defaultConfiguration()) | ||
.parse(sci_rep_array) | ||
.read("$.num_array[?(@.num > -0.0E0)]"); | ||
|
||
assertThat(result.toString()).isEqualTo("[{\"num\":1},{\"num\":1.0E9},{\"num\":2.0E-20}]"); | ||
|
||
result = using(Configuration.defaultConfiguration()) | ||
.parse(sci_rep_array) | ||
.read("$.num_array[?(@.num < -0.0E0)]"); | ||
|
||
assertThat(result.toString()).isEqualTo("[{\"num\":-1.0E-10},{\"num\":-2.0E19}]"); | ||
|
||
} | ||
|
||
} |