package main import ( "regexp" "strings" "testing" ) var ReKeyDefined = regexp.MustCompile("var +([a-zA-Z_]+) +([a-zA-Z0-9]+) *(\\([0-9]+\\))") type parseTest struct { PS string Result []string } func TestParseRe(t *testing.T) { var parseCollection []parseTest parseCollection = append(parseCollection, parseTest{ PS: "var a int; a = 0 ; a >= 1 && a <= 4", Result: []string{"a", "int"}, }, parseTest{ PS: "var das_das int64; das_das = 0 ; das_das >= 1 && das_das <= 4", Result: []string{"das_das", "int64"}, }, parseTest{ PS: "var BitTkoen text; BitTkoen = 0 ; BitTkoen >= 1 && BitTkoen <= 4", Result: []string{"BitTkoen", "text"}, }, parseTest{ PS: "var BitTkoen char(24); BitTkoen = 0 ; BitTkoen >= 1 && BitTkoen <= 4", Result: []string{"BitTkoen", "text"}, }, ) for _, parse := range parseCollection { codes := strings.Split(parse.PS, ";") result := ReKeyDefined.FindStringSubmatch(codes[0]) if len(result) >= 3 && !(result[1] == parse.Result[0] && result[2] == parse.Result[1]) { t.Error(result) } t.Error(result) } }