github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/compiler/compile_test.go (about) 1 // Copyright 2022 zGraph Authors. All rights reserved. 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 compiler_test 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 "github.com/vescale/zgraph" 22 "github.com/vescale/zgraph/catalog" 23 "github.com/vescale/zgraph/compiler" 24 "github.com/vescale/zgraph/executor" 25 "github.com/vescale/zgraph/parser" 26 "github.com/vescale/zgraph/parser/model" 27 ) 28 29 func TestCompile(t *testing.T) { 30 t.Skip() 31 assert := assert.New(t) 32 db, err := zgraph.Open(t.TempDir(), nil) 33 assert.Nil(err) 34 35 db.Catalog().Apply(&catalog.Patch{ 36 Type: catalog.PatchTypeCreateGraph, 37 Data: &model.GraphInfo{ 38 ID: 1, 39 Name: model.NewCIStr("g1"), 40 }, 41 }) 42 43 ddl := func(exec executor.Executor) { 44 _, ok := exec.(*executor.DDLExec) 45 assert.True(ok) 46 } 47 48 simple := func(exec executor.Executor) { 49 _, ok := exec.(*executor.SimpleExec) 50 assert.True(ok) 51 } 52 53 cases := []struct { 54 query string 55 check func(exec executor.Executor) 56 }{ 57 { 58 query: "create graph g2", 59 check: ddl, 60 }, 61 { 62 query: "create graph if not exists g1", 63 check: ddl, 64 }, 65 { 66 query: "create label if not exists l1", 67 check: ddl, 68 }, 69 { 70 query: "create index if not exists i1 (a)", 71 check: ddl, 72 }, 73 { 74 query: "use g1", 75 check: simple, 76 }, 77 } 78 79 sc := db.NewSession().StmtContext() 80 sc.SetCurrentGraphName("g1") 81 82 for _, c := range cases { 83 parser := parser.New() 84 stmt, err := parser.ParseOneStmt(c.query) 85 assert.Nil(err, c.query) 86 exec, err := compiler.Compile(sc, stmt) 87 assert.Nil(err, c.query) 88 c.check(exec) 89 } 90 }