From 2363911d58f0cdbd0da5c24d4c007904a9b73d2c Mon Sep 17 00:00:00 2001 From: Vitaly Pryakhin Date: Thu, 31 Jan 2019 13:29:32 +0300 Subject: [PATCH] add test case for issue #83 --- .../run/smt/ktest/json/matcher/JsonDiffSpec.kt | 13 +++++++++++++ .../test/resources/json-with-array-of-objects1.json | 12 ++++++++++++ .../test/resources/json-with-array-of-objects2.json | 12 ++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects1.json create mode 100644 ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects2.json diff --git a/ktest-integration/ktest-json-matchers/src/test/kotlin/run/smt/ktest/json/matcher/JsonDiffSpec.kt b/ktest-integration/ktest-json-matchers/src/test/kotlin/run/smt/ktest/json/matcher/JsonDiffSpec.kt index ec6988b..c145b90 100644 --- a/ktest-integration/ktest-json-matchers/src/test/kotlin/run/smt/ktest/json/matcher/JsonDiffSpec.kt +++ b/ktest-integration/ktest-json-matchers/src/test/kotlin/run/smt/ktest/json/matcher/JsonDiffSpec.kt @@ -56,6 +56,19 @@ object JsonDiffSpec : WordSpec({ assertThat(diff, isEmpty) } + "not return mismatch for arrays containing equal objects with different field order" { + val firstJson = "json-with-array-of-objects1.json".loadAsJsonTree() + val secondJson = "json-with-array-of-objects2.json".loadAsJsonTree() + + val comparator = jsonComparator { + compareArraysUnordered() + } + + val diff = comparator.diff(firstJson, secondJson) + + assertThat(diff, isEmpty) + } + "not return mismatch for permutation-based array comparison on arrays with different sort order" { val firstJson = "json-with-array.json".loadAsJsonTree() val secondJson = "json-with-array-reversed.json".loadAsJsonTree() diff --git a/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects1.json b/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects1.json new file mode 100644 index 0000000..1b513d2 --- /dev/null +++ b/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects1.json @@ -0,0 +1,12 @@ +{ + "myArray": [ + { + "a": 1, + "z": 1 + }, + { + "a": 2, + "z": 2 + } + ] +} diff --git a/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects2.json b/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects2.json new file mode 100644 index 0000000..d1d057a --- /dev/null +++ b/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects2.json @@ -0,0 +1,12 @@ +{ + "myArray": [ + { + "a": 2, + "z": 2 + }, + { + "z": 1, + "a": 1 + } + ] +}