示例#1
0
 def test_4(self):
     '''test that sequence_node_from_tokens works with there is a nested sequence'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             SequenceStart(),
             ScalarValue(data='value'),
             SequenceEnd(),
             SequenceEnd(),
         ],
                                   start=0),
         (SequenceNode(
             items=[SequenceNode(items=[ScalarNode(data='value')])]), 5))
示例#2
0
 def test_2(self):
     '''test that sequence_node_from_tokens works when there is no item'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             SequenceEnd(),
         ],
                                   start=0), (SequenceNode(items=[]), 2))
示例#3
0
 def test_1(self):
     '''test that sequence_node_from_tokens works for the simplest case'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             ScalarValue(data='value'),
             SequenceEnd(),
         ],
                                   start=0),
         (SequenceNode(items=[ScalarNode(data='value')]), 3))
示例#4
0
def sequence_node_from_tokens(tokens: List['Token'],
                              start: int) -> Tuple['SequenceNode', int]:
    items = []
    currentPosition = start + 1
    while not isinstance(tokens[currentPosition],
                         SequenceEnd):  # what happens if there is no end?
        valueNode, lastPosition = node_from_tokens(
            tokens=tokens,
            start=currentPosition)  # it has consumed the separator
        items.append(valueNode)
        if isinstance(tokens[lastPosition], Delimiter):
            lastPosition += 1
        currentPosition = lastPosition
    return SequenceNode(items=items), currentPosition + 1
示例#5
0
 def test_3(self):
     '''test that sequence_node_from_tokens works with more than one item'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             ScalarValue(data='value'),
             Delimiter(),
             ScalarValue(data='value'),
             SequenceEnd(),
         ],
                                   start=0),
         (SequenceNode(
             items=[ScalarNode(data='value'),
                    ScalarNode(data='value')]), 5))
示例#6
0
 def test_5(self):
     '''test that sequence_node_from_tokens works with it contains a mapping'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             ScalarValue(data='value'),
             MappingEnd(),
             SequenceEnd(),
         ],
                                   start=0),
         (SequenceNode(items=[
             MappingNode(
                 mapping={ScalarNode(data='key'): ScalarNode(data='value')})
         ]), 7))
示例#7
0
 def test_4(self):
     '''test that mapping_node_from_tokens works when the value is a sequence'''
     self.assertEqual(
         mapping_node_from_tokens(tokens=[
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             SequenceStart(),
             ScalarValue(data='value'),
             SequenceEnd(),
             MappingEnd(),
         ],
                                  start=0),
         (MappingNode(
             mapping={
                 ScalarNode(data='key'):
                 SequenceNode(items=[ScalarNode(data='value')]),
             }), 7))
示例#8
0
 def test_to_object(self):
     items = [ScalarNode(data='value')]
     node = SequenceNode(items=items)
     expectedObject = ['value']
     self.assertEqual(object_from_node(node), expectedObject)