1212from bblfsh .node import NodeTypedGetException
1313from bblfsh .result_context import (Node , NodeIterator , ResultContext )
1414from bblfsh .pyuast import uast , decode
15+ from functools import cmp_to_key
1516
1617class BblfshTests (unittest .TestCase ):
1718 BBLFSH_SERVER_EXISTED = None
@@ -261,12 +262,11 @@ def _get_nodes(iterator: NodeIterator) -> t.List[dict]:
261262
262263 @staticmethod
263264 def _get_positions (iterator : NodeIterator ):
264- nodes = [ n .get () for n in iterator ]
265- start_positions = [ n ["@pos" ]["start" ] for n in
266- filter (lambda x : isinstance (x , dict ) and
267- "@pos" in x .keys () and
268- "start" in x ["@pos" ].keys (), nodes ) ]
269- return [ (int (n ["offset" ]), int (n ["line" ]), int (n ["col" ])) for n in start_positions ]
265+ startPositions = [ n ["@pos" ]["start" ] for n in
266+ filter (lambda x : isinstance (x , dict ) and
267+ "@pos" in x .keys () and
268+ "start" in x ["@pos" ].keys (), iterator ) ]
269+ return [ (int (n ["offset" ]), int (n ["line" ]), int (n ["col" ])) for n in startPositions ]
270270
271271 def decrefAndGC (self , obj ) -> None :
272272 del obj
@@ -306,10 +306,10 @@ def testIteratorPositionOrder(self) -> None:
306306 'son1_2' , 'son2_2' , 'son2' ])
307307 # Check that when using the positional order the positions we get are
308308 # in fact sorted by (offset, line, col)
309- ctx = self ._parse_fixture ()
310- it = ctx .iterate (TreeOrder .POSITION_ORDER )
309+ it = iterator (root , TreeOrder .POSITION_ORDER )
311310 positions = self ._get_positions (it )
312- self .assertListEqual (positions , sorted (positions ))
311+ self .assertListEqual (positions , [(0 ,1 ,1 ), (2 ,2 ,2 ), (5 ,5 ,1 ), (10 ,10 ,1 ),
312+ (10 ,10 ,1 ), (15 ,15 ,1 ), (100 ,100 ,1 )])
313313
314314 def testAnyOrder (self ) -> None :
315315 root = self ._itTestTree ()
@@ -320,6 +320,14 @@ def testAnyOrder(self) -> None:
320320 self .assertEqual (set (expanded ), {'root' , 'son1' , 'son2' , 'son1_1' ,
321321 'son1_2' , 'son2_1' , 'son2_2' })
322322
323+ def testChildrenOrder (self ) -> None :
324+ root = self ._itTestTree ()
325+ it = iterator (root , TreeOrder .CHILDREN_ORDER )
326+ self .assertIsNotNone (it )
327+ expanded = self ._get_nodetypes (it )
328+ # We only can test that the order gives us all the nodes
329+ self .assertEqual (expanded , ['son1' , 'son2' ])
330+
323331 # Iterating from the root node should give the same result as
324332 # iterating from the tree, for every available node
325333 def testNodeIteratorEqualsCtxIterator (self ) -> None :
@@ -348,7 +356,6 @@ def testItersMixingIterations(self) -> None:
348356 it = ctx .iterate (TreeOrder .PRE_ORDER )
349357 next (it ); next (it ); next (it ); next (it )
350358
351-
352359 it2 = it .iterate (TreeOrder .PRE_ORDER )
353360 next (it2 )
354361
0 commit comments