Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct matchesJsonValue #17953

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@ class CustomStudyDialogTest : RobolectricTest() {
val expected =
"""
{
"browserCollapsed": false,
"collapsed": false,
"browserCollapsed": true,
"collapsed": true,
"delays": null,
"desc": "",
"dyn": 1,
"lrnToday": [0, 0],
"newToday": [0, 0],
"previewDelay": 0,
"previewDelay": 10,
"previewAgainSecs": 60,
"previewHardSecs": 600,
"previewGoodSecs": 0,
"resched": true,
"resched": false,
"revToday": [0, 0],
"separate": true,
"terms": [
["deck:\"Default\" prop:due<=1", 99999, 6]
["is:new added:1 deck:Default", 99999, 5]
],
"timeToday": [0, 0],
"usn": -1
Expand Down
20 changes: 11 additions & 9 deletions AnkiDroid/src/test/java/com/ichi2/testutils/JsonUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ private fun matchesJsonValue(
expectedValue: JSONObject,
actualValue: JSONObject,
): Boolean {
val expectedMap = expectedValue.keys().asSequence().associateWith { actualValue[it] }

val itemKeys = actualValue.keys().asSequence().toList()
val differentKeys =
itemKeys
.associateWith { actualValue[it] }
.filter { expectedMap[it.key].toString() != it.value.toString() }

return differentKeys.isEmpty() && expectedMap.size == itemKeys.size
// Checks the objects have the same keys
if (expectedValue.keys().asSequence().toSet() != actualValue.keys().asSequence().toSet()) {
return false
}
// And that each key have the same associated values in both object.
for (key in expectedValue.keys()) {
if (expectedValue[key] != actualValue[key]) {
return false
}
}
return true
}

// TODO: This doesn't describe the inputs in the correct order
Expand Down