github.com/goki/ki@v1.1.11/walki/walki_test.go (about) 1 // Copyright (c) 2020, The GoKi Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package walki 6 7 import ( 8 "fmt" 9 "reflect" 10 "testing" 11 12 "github.com/goki/ki/ki" 13 ) 14 15 var testTree *ki.Node 16 17 func init() { 18 testTree = &ki.Node{} 19 typ := reflect.TypeOf(testTree).Elem() 20 testTree.InitName(testTree, "root") 21 // child1 := 22 testTree.AddNewChild(typ, "child0") 23 var child2 = testTree.AddNewChild(typ, "child1") 24 // child3 := 25 testTree.AddNewChild(typ, "child2") 26 schild2 := child2.AddNewChild(typ, "subchild1") 27 // sschild2 := 28 schild2.AddNewChild(typ, "subsubchild1") 29 // child4 := 30 testTree.AddNewChild(typ, "child3") 31 } 32 33 func TestDown(t *testing.T) { 34 cur := testTree 35 for { 36 fmt.Println(cur.Path()) 37 curi := Next(cur) 38 if curi == nil { 39 break 40 } 41 cur = curi.(*ki.Node) 42 } 43 } 44 45 func TestUp(t *testing.T) { 46 cur := Last(testTree) 47 for { 48 fmt.Println(cur.Path()) 49 curi := Prev(cur) 50 if curi == nil { 51 break 52 } 53 cur = curi.(*ki.Node) 54 } 55 }