2017-03-08 21:11:05 +08:00
|
|
|
//
|
|
|
|
// Copyright 2017 Memgraph
|
|
|
|
// Created by Florijan Stamenkovic on 07.03.17.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2017-06-08 00:28:31 +08:00
|
|
|
#include "query/stripped.hpp"
|
2017-04-10 18:22:48 +08:00
|
|
|
#include "query/typed_value.hpp"
|
|
|
|
|
|
|
|
using query::TypedValue;
|
2017-06-08 00:28:31 +08:00
|
|
|
using query::StrippedQuery;
|
2017-03-08 21:11:05 +08:00
|
|
|
|
|
|
|
void EXPECT_PROP_TRUE(const TypedValue& a) {
|
|
|
|
EXPECT_TRUE(a.type() == TypedValue::Type::Bool && a.Value<bool>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXPECT_PROP_EQ(const TypedValue& a, const TypedValue& b) {
|
|
|
|
EXPECT_PROP_TRUE(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, NoLiterals) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("CREATE (n)");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 0);
|
|
|
|
EXPECT_EQ(stripped.query(), "create ( n )");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, DecimalInteger) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("RETURN 42");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 1);
|
|
|
|
EXPECT_EQ(stripped.parameters().At(0).Value<int64_t>(), 42);
|
|
|
|
EXPECT_EQ(stripped.query(), "return $stripped_arg_0");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, OctalInteger) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("RETURN 010");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 1);
|
|
|
|
EXPECT_EQ(stripped.parameters().At(0).Value<int64_t>(), 8);
|
|
|
|
EXPECT_EQ(stripped.query(), "return $stripped_arg_0");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, HexInteger) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("RETURN 0xa");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 1);
|
|
|
|
EXPECT_EQ(stripped.parameters().At(0).Value<int64_t>(), 10);
|
|
|
|
EXPECT_EQ(stripped.query(), "return $stripped_arg_0");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, RegularDecimal) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("RETURN 42.3");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 1);
|
|
|
|
EXPECT_FLOAT_EQ(stripped.parameters().At(0).Value<double>(), 42.3);
|
|
|
|
EXPECT_EQ(stripped.query(), "return $stripped_arg_0");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, ExponentDecimal) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("RETURN 4e2");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 1);
|
|
|
|
EXPECT_FLOAT_EQ(stripped.parameters().At(0).Value<double>(), 4e2);
|
|
|
|
EXPECT_EQ(stripped.query(), "return $stripped_arg_0");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, StringLiteral) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("RETURN 'something'");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 1);
|
|
|
|
EXPECT_EQ(stripped.parameters().At(0).Value<std::string>(), "something");
|
|
|
|
EXPECT_EQ(stripped.query(), "return $stripped_arg_0");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, BoolLiteral) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("RETURN true");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 1);
|
|
|
|
EXPECT_PROP_EQ(stripped.parameters().At(0), TypedValue(true));
|
|
|
|
EXPECT_EQ(stripped.query(), "return $stripped_arg_0");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, ListLiteral) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("MATCH (n) RETURN [n, n.prop]");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 0);
|
|
|
|
EXPECT_EQ(stripped.query(), "match ( n ) return [ n , n . prop ]");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, MapLiteral) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("MATCH (n) RETURN {val: n}");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 0);
|
|
|
|
EXPECT_EQ(stripped.query(), "match ( n ) return { val : n }");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QueryStripper, RangeLiteral) {
|
2017-06-08 00:28:31 +08:00
|
|
|
StrippedQuery stripped("MATCH (n)-[*2..3]-() RETURN n");
|
|
|
|
EXPECT_EQ(stripped.parameters().Size(), 2);
|
|
|
|
EXPECT_EQ(stripped.parameters().At(0).Value<int64_t>(), 2);
|
|
|
|
EXPECT_EQ(stripped.parameters().At(1).Value<int64_t>(), 3);
|
|
|
|
EXPECT_EQ(
|
|
|
|
stripped.query(),
|
|
|
|
"match ( n ) - [ * $stripped_arg_0 .. $stripped_arg_1 ] - ( ) return n");
|
2017-03-08 21:11:05 +08:00
|
|
|
}
|