servo: Merge #14092 - Sort check on JSON (from kivikakk:sort-check); r=Wafflespeanut

<!-- Please describe your changes on the following line: -->
Check that JSON keys are ordered, and that there's no duplicates (for `resources/prefs.json` and `resources/package-prefs.json`).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x]  🆕 `./mach test-tidy --self-test` does not report any errors
- [x] These changes fix #12283

<!-- Either: -->
- [x] There are tests for these changes 🎉

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 94d0c485e10138e0d5b2bd8b41b6a922a22a059f
This commit is contained in:
Yuki Izumi
2016-11-07 07:41:34 -06:00
parent 5493a95fe6
commit 231d5ffcee
6 changed files with 107 additions and 75 deletions

View File

@@ -171,6 +171,12 @@ class CheckTidiness(unittest.TestCase):
self.assertEqual('Duplicated Key (the_duplicated_key)', errors.next()[2])
self.assertNoMoreErrors(errors)
def test_json_with_unordered_keys(self):
tidy.config["check-ordered-json-keys"].append('python/tidy/servo_tidy_tests/unordered_key.json')
errors = tidy.collect_errors_for_files(iterFile('unordered_key.json'), [tidy.check_json], [], print_text=False)
self.assertEqual('Unordered key (found b before a)', errors.next()[2])
self.assertNoMoreErrors(errors)
def test_lock(self):
errors = tidy.collect_errors_for_files(iterFile('duplicated_package.lock'), [tidy.check_lock], [], print_text=False)
msg = """duplicate versions for package "test"

View File

@@ -0,0 +1,7 @@
{
"key": "value",
"other_key": {
"b": 1,
"a": 2
}
}