diff --git a/tests/rules/test_key_ordering.py b/tests/rules/test_key_ordering.py index bcd9eef..dc486af 100644 --- a/tests/rules/test_key_ordering.py +++ b/tests/rules/test_key_ordering.py @@ -59,6 +59,55 @@ class KeyOrderingTestCase(RuleTestCase): ' third:\n' ' second: 2\n', conf) + def test_word_length(self): + conf = 'key-ordering: enable' + self.check('---\n' + 'a: 1\n' + 'ab: 1\n' + 'abc: 1\n', conf) + self.check('---\n' + 'a: 1\n' + 'abc: 1\n' + 'ab: 1\n', conf, + problem=(4, 1)) + + def test_key_duplicates(self): + conf = ('key-duplicates: disable\n' + 'key-ordering: enable') + self.check('---\n' + 'key: 1\n' + 'key: 2\n', conf) + + def test_case(self): + conf = 'key-ordering: enable' + self.check('---\n' + 'T-shirt: 1\n' + 'T-shirts: 2\n' + 't-shirt: 3\n' + 't-shirts: 4\n', conf) + self.check('---\n' + 'T-shirt: 1\n' + 't-shirt: 2\n' + 'T-shirts: 3\n' + 't-shirts: 4\n', conf, + problem=(4, 1)) + + def test_accents(self): + conf = 'key-ordering: enable' + self.check('---\n' + 'hair: true\n' + 'hais: true\n' + 'haïr: true\n' + 'haïssable: true\n', conf) + self.check('---\n' + 'haïr: true\n' + 'hais: true\n', conf, + problem=(3, 1)) + self.check('---\n' + 'haïr: true\n' + 'hais: true\n', conf, + problem=(3, 1)) + def test_key_tokens_in_flow_sequences(self): conf = 'key-ordering: enable' self.check('---\n' diff --git a/yamllint/rules/key_ordering.py b/yamllint/rules/key_ordering.py index 4a7e31f..3bd93c7 100644 --- a/yamllint/rules/key_ordering.py +++ b/yamllint/rules/key_ordering.py @@ -15,7 +15,9 @@ # along with this program. If not, see . """ -Use this rule to enforce alphabetical ordering of keys in mappings. +Use this rule to enforce alphabetical ordering of keys in mappings. The sorting +order uses the Unicode code point number. As a result, the ordering is +case-sensitive and not accent-friendly (see examples below). .. rubric:: Examples @@ -28,6 +30,14 @@ Use this rule to enforce alphabetical ordering of keys in mappings. key 2: val key 3: value - {a: 1, b: 2, c: 3} + - T-shirt: 1 + T-shirts: 2 + t-shirt: 3 + t-shirts: 4 + - hair: true + hais: true + haïr: true + haïssable: true the following code snippet would **FAIL**: :: @@ -39,6 +49,20 @@ Use this rule to enforce alphabetical ordering of keys in mappings. :: - {b: 1, a: 2} + + the following code snippet would **FAIL**: + :: + + - T-shirt: 1 + t-shirt: 2 + T-shirts: 3 + t-shirts: 4 + + the following code snippet would **FAIL**: + :: + + - haïr: true + hais: true """ import yaml