From f07044dab60fcd74ee32f4f959f7c2a233153bfa Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 11 Mar 2023 23:45:00 +0100 Subject: Handle YAML nodes without values. --- plugins/yaml/pair.c | 3 +++ tests/plugins/yamlrdr.py | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/yaml/pair.c b/plugins/yaml/pair.c index 0e96937..df29f6f 100644 --- a/plugins/yaml/pair.c +++ b/plugins/yaml/pair.c @@ -192,6 +192,9 @@ GYamlPair *g_yaml_pair_new(GYamlLine *line) value = g_yaml_line_get_value(line); if (key == NULL) + key = g_yaml_line_get_payload(line); + + if (key == NULL) result = NULL; else diff --git a/tests/plugins/yamlrdr.py b/tests/plugins/yamlrdr.py index b9a99a2..dbd9651 100644 --- a/tests/plugins/yamlrdr.py +++ b/tests/plugins/yamlrdr.py @@ -4,7 +4,6 @@ from chrysacase import ChrysalideTestCase from pychrysalide.plugins.yaml import YamlReader -import tempfile class TestYamlReader(ChrysalideTestCase): @@ -234,3 +233,29 @@ root: sub = found[0].find_one_by_path('/aa') self.assertIsNotNone(sub) self.assertEqual(sub.key, 'aa') + + + def testItemsWithoutValue(self): + """Find items without values.""" + + from pychrysalide import core + core.set_verbosity(5) + + data = ''' +vals: + - 1 + - 2 + - 3 + +''' + + reader = YamlReader(text=data) + self.assertIsNotNone(reader) + + found = reader.tree.find_by_path('/vals/') + + self.assertEqual(len(found), 3) + + self.assertEqual(found[0].nodes[0].key, '1') + self.assertEqual(found[1].nodes[0].key, '2') + self.assertEqual(found[2].nodes[0].key, '3') -- cgit v0.11.2-87-g4458