github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/compiler/property_preparation_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/compiler" 23 "github.com/vescale/zgraph/parser" 24 "github.com/vescale/zgraph/stmtctx" 25 ) 26 27 func TestPropertyPreparation(t *testing.T) { 28 assert := assert.New(t) 29 tempDir := t.TempDir() 30 initCatalog(assert, tempDir) 31 32 db, err := zgraph.Open(tempDir, nil) 33 assert.Nil(err) 34 35 cases := []struct { 36 query string 37 check func() 38 }{ 39 { 40 query: "INSERT INTO graph1 VERTEX x LABELS (label1) PROPERTIES ( x.prop1 = 'test')", 41 check: func() { 42 graph := db.Catalog().Graph("graph1") 43 assert.NotNil(graph.Property("prop1")) 44 }, 45 }, 46 { 47 query: "INSERT INTO graph2 VERTEX x LABELS (label1) PROPERTIES ( x.property = 'test')", 48 check: func() { 49 graph := db.Catalog().Graph("graph1") 50 assert.NotNil(2, len(graph.Properties())) 51 }, 52 }, 53 { 54 query: "INSERT INTO graph2 VERTEX x LABELS (label1) PROPERTIES ( x.property2 = 'test')", 55 check: func() { 56 graph := db.Catalog().Graph("graph1") 57 assert.NotNil(3, len(graph.Properties())) 58 assert.NotNil(graph.Property("property2")) 59 }, 60 }, 61 } 62 63 for _, c := range cases { 64 parser := parser.New() 65 stmt, err := parser.ParseOneStmt(c.query) 66 assert.Nil(err) 67 sc := stmtctx.New(db.Store(), db.Catalog()) 68 69 prep := compiler.NewPropertyPreparation(sc) 70 stmt.Accept(prep) 71 err = prep.CreateMissing() 72 assert.Nil(err) 73 } 74 }