add tests for float value types.
parent
37c39d5fef
commit
0da4a23776
|
@ -23,6 +23,7 @@ type ValueType int
|
|||
const (
|
||||
ValueRegex ValueType = C.VALUE_REGEX
|
||||
ValueInt ValueType = C.VALUE_INT
|
||||
ValueFloat ValueType = C.VALUE_FLOAT
|
||||
ValueString ValueType = C.VALUE_STRING
|
||||
ValueTableName ValueType = C.VALUE_TABLE_NAME
|
||||
ValueSimpleName ValueType = C.VALUE_SIMPLE_NAME
|
||||
|
|
|
@ -222,7 +222,7 @@ func (self *QueryParserSuite) TestParseFromWithNestedFunctions(c *C) {
|
|||
}
|
||||
|
||||
func (self *QueryParserSuite) TestParseWhereClausePrecedence(c *C) {
|
||||
q, err := ParseQuery("select value from cpu.idle where value > 90 and other_value > 10 or value > 80 and other_value > 20;")
|
||||
q, err := ParseQuery("select value from cpu.idle where value > 90 and other_value > 10.0 or value > 80 and other_value > 20;")
|
||||
defer q.Close()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
|
@ -247,7 +247,7 @@ func (self *QueryParserSuite) TestParseWhereClausePrecedence(c *C) {
|
|||
c.Assert(ok, Equals, true)
|
||||
c.Assert(rightExpression.Operation, Equals, ">")
|
||||
c.Assert(rightExpression.Left.Left, DeepEquals, &Value{"other_value", ValueSimpleName, false, nil})
|
||||
c.Assert(rightExpression.Right.Left, DeepEquals, &Value{"10", ValueInt, false, nil})
|
||||
c.Assert(rightExpression.Right.Left, DeepEquals, &Value{"10.0", ValueFloat, false, nil})
|
||||
}
|
||||
|
||||
func (self *QueryParserSuite) TestParseWhereClauseParantheses(c *C) {
|
||||
|
@ -368,7 +368,7 @@ func (self *QueryParserSuite) TestParseSelectWithRegexTables(c *C) {
|
|||
}
|
||||
|
||||
func (self *QueryParserSuite) TestParseSelectWithComplexArithmeticOperations(c *C) {
|
||||
q, err := ParseQuery("select value from cpu.idle where 30 < value * 1 / 3 ;")
|
||||
q, err := ParseQuery("select value from cpu.idle where .30 < value * 1 / 3 ;")
|
||||
defer q.Close()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
|
@ -377,7 +377,7 @@ func (self *QueryParserSuite) TestParseSelectWithComplexArithmeticOperations(c *
|
|||
boolExpression, ok := q.GetWhereCondition().GetBoolExpression()
|
||||
c.Assert(ok, Equals, true)
|
||||
|
||||
c.Assert(boolExpression.Left.Left, DeepEquals, &Value{"30", ValueInt, false, nil})
|
||||
c.Assert(boolExpression.Left.Left, DeepEquals, &Value{".30", ValueFloat, false, nil})
|
||||
|
||||
// value * 1 / 3
|
||||
rightExpression := boolExpression.Right
|
||||
|
|
|
@ -51,6 +51,8 @@ static int yycolumn = 1;
|
|||
|
||||
[0-9]+ { yylval->string = strdup(yytext); return INT_VALUE; }
|
||||
|
||||
[0-9]*\.[0-9]+|[0-9]+\.[0-9]* { yylval->string = strdup(yytext); return FLOAT_VALUE; }
|
||||
|
||||
[0-9]+[smhdw] { yylval->string = strdup(yytext); return DURATION; }
|
||||
|
||||
\/.+\/ { yytext[strlen(yytext)-1]='\0';yylval->string=strdup(yytext+1);return REGEX_STRING; }
|
||||
|
|
|
@ -55,7 +55,7 @@ value *create_value(char *name, int type, char is_case_insensitive, value_array
|
|||
|
||||
// define types of tokens (terminals)
|
||||
%token SELECT FROM WHERE EQUAL GROUP BY FIRST LAST LIMIT ORDER ASC DESC
|
||||
%token <string> STRING_VALUE INT_VALUE TABLE_NAME SIMPLE_NAME REGEX_OP REGEX_STRING INSENSITIVE_REGEX_STRING DURATION
|
||||
%token <string> STRING_VALUE INT_VALUE FLOAT_VALUE TABLE_NAME SIMPLE_NAME REGEX_OP REGEX_STRING INSENSITIVE_REGEX_STRING DURATION
|
||||
|
||||
// define the precendence of these operators
|
||||
%left OR
|
||||
|
@ -220,6 +220,11 @@ VALUE:
|
|||
$$ = create_value($1, VALUE_INT, FALSE, NULL);
|
||||
}
|
||||
|
|
||||
FLOAT_VALUE
|
||||
{
|
||||
$$ = create_value($1, VALUE_FLOAT, FALSE, NULL);
|
||||
}
|
||||
|
|
||||
DURATION_VALUE
|
||||
|
|
||||
SIMPLE_NAME_VALUE
|
||||
|
|
|
@ -20,6 +20,7 @@ typedef struct value_t {
|
|||
enum {
|
||||
VALUE_REGEX,
|
||||
VALUE_INT,
|
||||
VALUE_FLOAT,
|
||||
VALUE_STRING,
|
||||
VALUE_TABLE_NAME,
|
||||
VALUE_SIMPLE_NAME,
|
||||
|
|
Loading…
Reference in New Issue