Esempio n. 1
0
func main() {

	query := flag.String("q", "", "The Query to search")
	pathString := flag.String("p", ".", "The (optional) path to run gitql")
	version := flag.Bool("v", false, "The version of gitql")
	flag.Parse()

	if *version {
		// @todo refactor to dynamic value
		fmt.Println("Gitql 1.0.0")
		return
	}

	path, errFile := filepath.Abs(*pathString)

	if errFile != nil {
		panic(errFile)
	}

	parser.New(*query)
	ast, errGit := parser.AST()
	if errGit != nil {
		panic(errGit)
	}
	ast.Path = &path
	errGit = semantical.Analysis(ast)
	if errGit != nil {
		panic(errGit)
	}

	runtime.Run(ast)
}
Esempio n. 2
0
func TestSmallerWithDate(t *testing.T) {
	parser.New("select name from commits where date > '2013-03-14 00:00:00'")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err != nil {
		t.Fatalf(err.Error())
	}
}
Esempio n. 3
0
func TestSmallerWithInvalidConstant(t *testing.T) {
	parser.New("select name from commits where date <= 'name'")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Shoud avoid smaller with no numeric")
	}
}
Esempio n. 4
0
func TestInvalidZeroLimit(t *testing.T) {
	parser.New("select * from commits limit 0")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Should not accept limit zero")
	}
}
Esempio n. 5
0
func TestGreaterWithNoNumeric(t *testing.T) {
	parser.New("select name from commits where date > 'name'")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Shoud avoid greater with no numeric")
	}
}
Esempio n. 6
0
func TestConstantLValue(t *testing.T) {
	parser.New("select name from commits where 'name' = 'name' ")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err != nil {
		t.Fatalf(err.Error())
	}
}
Esempio n. 7
0
func TestChooseRepetitiveFields(t *testing.T) {
	parser.New("select name, created_at, name from commits")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Shoud avoid repetitive fields")
	}
}
Esempio n. 8
0
func TestValidNullLimit(t *testing.T) {
	parser.New("select * from commits")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err != nil {
		t.Fatalf(err.Error())
	}
}
Esempio n. 9
0
func TestInUsingNotIdRight(t *testing.T) {
	parser.New("select * from commits where 'c' in 'cc' ")
	ast, parserErr := parser.AST()
	if parserErr != nil {
		t.Fatalf(parserErr.Error())
	}

	err := Analysis(ast)
	if err == nil {
		t.Fatalf("Should trow error with invalid in ")
	}
}
Esempio n. 10
0
File: itql.go Progetto: lianz/gitql
func main() {
	folder, errFile := filepath.Abs(*path)

	if errFile != nil {
		log.Fatalln(errFile)
	}

	parser.New(query)
	ast, errGit := parser.AST()
	if errGit != nil {
		log.Fatalln(errGit)
	}
	ast.Path = &folder
	errGit = semantical.Analysis(ast)
	if errGit != nil {
		log.Fatalln(errGit)
	}

	runtime.Run(ast)
}