33using Strumenta . Sharplasu . Traversing ;
44using Type = System . Type ;
55using Expression = Strumenta . Sharplasu . Tests . Models . SimpleLang . Expression ;
6+ using System ;
7+ using static Strumenta . Sharplasu . Tests . Models . SimpleLang . Models ;
68
79namespace Strumenta . Sharplasu . Tests
810{
@@ -29,7 +31,7 @@ public void TestWalk()
2931 [ TestMethod ]
3032 public void TestWalkLeavesFirst ( )
3133 {
32- var cu = Tests . Models . SimpleLang . Models . GetCompilationUnit ( ) ;
34+ var cu = Tests . Models . SimpleLang . Models . GetCompilationUnit ( ) ;
3335 TestSequences (
3436 MapNodesToTypes ( cu . WalkLeavesFirst ( ) ) ,
3537 new List < System . Type >
@@ -145,18 +147,45 @@ public void TestWalkDescendants()
145147 } ) ;
146148 }
147149
150+ public IEnumerable < Node > GetNotEncodingChildren ( Node x )
151+ {
152+ if ( x is FileRoot )
153+ {
154+ List < Node > children = new List < Node > ( ) ;
155+ x . WalkDescendants ( ) . ToList ( ) . ForEach ( t =>
156+ {
157+ children . AddRange ( GetNotEncodingChildren ( t ) ) ;
158+ } ) ;
159+ return children ;
160+ }
161+ else if ( x is EncodingFunction )
162+ return x . WalkChildren ( ) ;
163+ else
164+ return Enumerable . Empty < Node > ( ) ;
165+ }
166+
167+
148168 [ TestMethod ]
149169 public void TestFindAncestorOfType ( )
150170 {
151171 var cu = Tests . Models . SimpleLang . Models . GetCompilationUnit ( ) ;
152172 var identifier = cu . WalkDescendants ( ) . First ( n => n . GetType ( ) == typeof ( Identifier ) ) ;
173+ var ast = Tests . Models . SimpleLang . Models . GetExampleCompilationUnit ( ) ;
174+ var nodes = ast . WalkDescendants ( x => {
175+ return GetNotEncodingChildren ( x ) ;
176+ } ) ;
177+ foreach ( var node in nodes )
178+ {
179+ Console . WriteLine ( node . ToString ( ) ) ;
180+ }
153181 Assert . IsInstanceOfType ( identifier . FindAncestorOfType < CompilationUnit > ( ) , typeof ( CompilationUnit ) ) ;
154182 Assert . IsInstanceOfType ( identifier . FindAncestorOfType < SetStatement > ( ) , typeof ( SetStatement ) ) ;
155183 Assert . IsNull ( identifier . FindAncestorOfType < DisplayStatement > ( ) ) ;
156184 }
157185
158186 private List < Type > MapNodesToTypes ( IEnumerable < Node > nodeSequence )
159187 {
188+
160189 return nodeSequence . Select ( node => node . GetType ( ) ) . ToList ( ) ;
161190 }
162191
0 commit comments