Exemplo 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)
}
Exemplo 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())
	}
}
Exemplo 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")
	}
}
Exemplo 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")
	}
}
Exemplo 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")
	}
}
Exemplo 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())
	}
}
Exemplo 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")
	}
}
Exemplo 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())
	}
}
Exemplo 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 ")
	}
}
Exemplo n.º 10
0
Arquivo: itql.go Projeto: 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)
}