TestParser_DisplayTree tests tree visualization
(t *testing.T)
| 233 | |
| 234 | // TestParser_DisplayTree tests tree visualization |
| 235 | func TestParser_DisplayTree(t *testing.T) { |
| 236 | var outBuf, errBuf bytes.Buffer |
| 237 | parser := NewParser(&outBuf, &errBuf, CLIParserOptions{ |
| 238 | Format: "table", |
| 239 | TreeView: true, |
| 240 | }) |
| 241 | |
| 242 | result, err := parser.Parse("SELECT * FROM users WHERE id = 1") |
| 243 | if err != nil { |
| 244 | t.Fatalf("Unexpected error: %v", err) |
| 245 | } |
| 246 | defer ast.ReleaseAST(result.AST) |
| 247 | |
| 248 | err = parser.Display(result) |
| 249 | if err != nil { |
| 250 | t.Fatalf("Failed to display tree: %v", err) |
| 251 | } |
| 252 | |
| 253 | output := outBuf.String() |
| 254 | if output == "" { |
| 255 | t.Error("Expected tree output but got empty string") |
| 256 | } |
| 257 | |
| 258 | // Check for tree visualization elements |
| 259 | if !strings.Contains(output, "AST Tree") { |
| 260 | t.Error("Expected 'AST Tree' in output") |
| 261 | } |
| 262 | if !strings.Contains(output, "├──") && !strings.Contains(output, "└──") { |
| 263 | t.Error("Expected tree box-drawing characters in output") |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // TestParser_ComplexQuery tests parsing complex queries |
| 268 | func TestParser_ComplexQuery(t *testing.T) { |