github.com/dolthub/go-mysql-server@v0.18.0/sql/treeprinter_test.go (about)

     1  // Copyright 2020-2021 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package sql
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  const expectedTree = `Project(a, b)
    24   ├─ CrossJoin
    25   │   ├─ TableA
    26   │   └─ TableB
    27   └─ CrossJoin
    28       ├─ TableC
    29       └─ TableD
    30  `
    31  
    32  func TestTreePrinter(t *testing.T) {
    33  	p := NewTreePrinter()
    34  	p.WriteNode("Project(%s, %s)", "a", "b")
    35  
    36  	p2 := NewTreePrinter()
    37  	p2.WriteNode("CrossJoin")
    38  	p2.WriteChildren(
    39  		"TableA",
    40  		"TableB",
    41  	)
    42  
    43  	p3 := NewTreePrinter()
    44  	p3.WriteNode("CrossJoin")
    45  	p3.WriteChildren(
    46  		"TableC",
    47  		"TableD",
    48  	)
    49  
    50  	p.WriteChildren(
    51  		p2.String(),
    52  		p3.String(),
    53  	)
    54  
    55  	require.Equal(t, expectedTree, p.String())
    56  }