Skip to content

Commit 7be0b5b

Browse files
committed
fix-to(array): 修复case
1 parent 0201bdc commit 7be0b5b

File tree

3 files changed

+42
-47
lines changed

3 files changed

+42
-47
lines changed

json-diff-core/src/main/java/me/codeleep/jsondiff/core/handle/object/ComplexObjectJsonNeat.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,21 @@ private void keySetConversion(Set<String> expectKeys, Set<String> actualKeys) {
7777
// 移除忽略的Path
7878
HashSet<String> ignorePath = RunTimeDataFactory.getOptionInstance().getIgnorePath();
7979
List<MappingKey> mappingKeys = keyMap.stream().filter(mappingKey -> {
80-
String actualTravelPath = PathUtil.getObjectPath(travelPath.getActualTravelPath()) + mappingKey.getActualKey();
81-
String expectTravelPath = PathUtil.getObjectPath(travelPath.getExpectTravelPath()) + mappingKey.getExpectKey();
82-
String abstractActualTravelPath = PathUtil.getObjectPath(travelPath.getAbstractTravelPath()) + mappingKey.getActualKey();
83-
String abstractExpectTravelPath = PathUtil.getObjectPath(travelPath.getAbstractTravelPath()) + mappingKey.getExpectKey();
84-
if (ignorePath.contains(abstractActualTravelPath) || ignorePath.contains(abstractExpectTravelPath) || ignorePath.contains(actualTravelPath) || ignorePath.contains(expectTravelPath) ) {
85-
return false;
80+
String actualKey = mappingKey.getActualKey();
81+
if (actualKey != null) {
82+
String actualTravelPath = PathUtil.getObjectPath(travelPath.getActualTravelPath()) + mappingKey.getActualKey();
83+
String abstractActualTravelPath = PathUtil.getObjectPath(travelPath.getAbstractTravelPath()) + mappingKey.getActualKey();
84+
if (ignorePath.contains(actualTravelPath) || ignorePath.contains(abstractActualTravelPath)) {
85+
return false;
86+
}
87+
}
88+
String expectKey = mappingKey.getExpectKey();
89+
if (expectKey != null) {
90+
String expectTravelPath = PathUtil.getObjectPath(travelPath.getExpectTravelPath()) + mappingKey.getExpectKey();
91+
String abstractExpectTravelPath = PathUtil.getObjectPath(travelPath.getAbstractTravelPath()) + mappingKey.getExpectKey();
92+
if (ignorePath.contains(expectTravelPath) || ignorePath.contains(abstractExpectTravelPath)) {
93+
return false;
94+
}
8695
}
8796
return true;
8897
}).collect(Collectors.toList());

json-diff-test/src/main/java/me/codeleep/jsondiff/test/MultAllArrayTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public void optionErr(MetaData metaData) {
6363
JsonCompareResult jsonCompareResult = defaultJsonDifference
6464
.option(metaData.getOption())
6565
.detectDiff(JSON.toJSONString(metaData.getExpect()), JSON.toJSONString(metaData.getActual()));
66-
Assert.assertEquals(FormatContent.formatComparisonContent(jsonCompareResult), FormatContent.formatComparisonContent(metaData.getRet().toString()));
66+
if (metaData.getRet() != null) {
67+
Assert.assertEquals(FormatContent.formatComparisonContent(jsonCompareResult), FormatContent.formatComparisonContent(metaData.getRet().toString()));
68+
} else {
69+
Assert.assertEquals(FormatContent.formatComparisonContent(jsonCompareResult), FormatContent.formatComparisonContent("{\"match\":true}"));
70+
}
6771
}
6872
}

json-diff-test/src/main/resources/array/MultArrays.json

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,12 +2402,12 @@
24022402
"defectsList": [
24032403
{
24042404
"actual": "1.1234",
2405-
"expect": 1.1234,
2405+
"expect": "1.1234",
24062406
"illustrate": "The expect type ('java.math.BigDecimal') is inconsistent with the actual type ('java.lang.String')",
24072407
"travelPath": {
24082408
"abstractTravelPath": "$[*]",
2409-
"actualTravelPath": "root[0]",
2410-
"expectTravelPath": "root[0]"
2409+
"actualTravelPath": "$[0]",
2410+
"expectTravelPath": "$[0]"
24112411
}
24122412
}
24132413
],
@@ -7200,7 +7200,7 @@
72007200
],
72017201
"option": {
72027202
"ignorePath": [
7203-
"$.[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*].a"
7203+
"$[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*].a"
72047204
]
72057205
},
72067206
"ret": {
@@ -7209,20 +7209,20 @@
72097209
"actual": "3",
72107210
"expect": "2",
72117211
"illustrate": "The expect('2') data is inconsistent with the actual('3') data",
7212-
"travelPath": {
7213-
"abstractTravelPath": "$[*][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][].b",
7214-
"actualTravelPath": "root[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0].b",
7215-
"expectTravelPath": "root[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0].b"
7212+
"travelPath":{
7213+
"abstractTravelPath":"$[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*].b",
7214+
"actualTravelPath":"$[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0].b",
7215+
"expectTravelPath":"$[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0].b"
72167216
}
72177217
},
72187218
{
72197219
"actual": "1",
72207220
"expect": "3",
72217221
"illustrate": "The expect('3') data is inconsistent with the actual('1') data",
7222-
"travelPath": {
7223-
"abstractTravelPath": "$[*][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][].C",
7224-
"actualTravelPath": "root[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][1].C",
7225-
"expectTravelPath": "root[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][1].C"
7222+
"travelPath":{
7223+
"abstractTravelPath":"$[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*].C",
7224+
"actualTravelPath":"$[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][1].C",
7225+
"expectTravelPath":"$[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][1].C"
72267226
}
72277227
}
72287228
],
@@ -8587,7 +8587,7 @@
85878587
],
85888588
"option": {
85898589
"ignorePath": [
8590-
"$[*][0]"
8590+
"$[*][*]"
85918591
]
85928592
}
85938593
},
@@ -10518,37 +10518,19 @@
1051810518
]
1051910519
},
1052010520
"ret": {
10521-
"defectsList": [
10522-
{
10523-
"actual": "2",
10524-
"illustrate": "The expect type ('null') is inconsistent with the actual type ('java.lang.Integer')",
10525-
"travelPath": {
10526-
"abstractTravelPath": "$[*].c",
10527-
"actualTravelPath": "$[2].c",
10528-
"expectTravelPath": "$[1].null"
10529-
}
10530-
},
10531-
{
10532-
"actual": "1",
10533-
"illustrate": "The expect type ('null') is inconsistent with the actual type ('java.lang.Integer')",
10534-
"travelPath": {
10535-
"abstractTravelPath": "$[*].b",
10536-
"actualTravelPath": "$[2].null",
10537-
"expectTravelPath": "$[1].b"
10538-
}
10539-
},
10521+
"defectsList":[
1054010522
{
10541-
"actual": "1",
10542-
"expect": "2",
10543-
"illustrate": "The expect('2') data is inconsistent with the actual('1') data",
10544-
"travelPath": {
10545-
"abstractTravelPath": "$[*].a",
10546-
"actualTravelPath": "root[2].a",
10547-
"expectTravelPath": "root[1].a"
10523+
"actual":"1",
10524+
"expect":"2",
10525+
"illustrate":"The expect('2') data is inconsistent with the actual('1') data",
10526+
"travelPath":{
10527+
"abstractTravelPath":"$[*].a",
10528+
"actualTravelPath":"$[2].a",
10529+
"expectTravelPath":"$[1].a"
1054810530
}
1054910531
}
1055010532
],
10551-
"match": false
10533+
"match":false
1055210534
}
1055310535
},
1055410536
{

0 commit comments

Comments
 (0)