summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-06-08 22:00:50 +0000
committerPeter Wu <peter@lekensteyn.nl>2017-06-08 22:00:50 +0000
commit6b87ef832eba600ca72655f462b6e3d5088ec375 (patch)
treef2549a96b51121d58432d00cd8e09c36768bceee /unittests
parent1fc30fcae813617a5beb272c5abedc11fcce2e31 (diff)
downloadclang-6b87ef832eba600ca72655f462b6e3d5088ec375.tar.gz
[ASTMatchers] Add support for floatLiterals
Summary: Needed to support something like "floatLiteral(equals(1.0))". The parser for floating point numbers is kept simple, so instead of ".1" you have to use "0.1". Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D33135 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305021 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ASTMatchers/Dynamic/ParserTest.cpp19
-rw-r--r--unittests/ASTMatchers/Dynamic/VariantValueTest.cpp13
2 files changed, 30 insertions, 2 deletions
diff --git a/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index 504724362a..ed184a8c14 100644
--- a/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -84,6 +84,21 @@ TEST(ParserTest, ParseBoolean) {
EXPECT_EQ(false, Sema.Values[1].getBoolean());
}
+TEST(ParserTest, ParseDouble) {
+ MockSema Sema;
+ Sema.parse("1.0");
+ Sema.parse("2.0f");
+ Sema.parse("34.56e-78");
+ Sema.parse("4.E+6");
+ Sema.parse("1");
+ EXPECT_EQ(5U, Sema.Values.size());
+ EXPECT_EQ(1.0, Sema.Values[0].getDouble());
+ EXPECT_EQ("1:1: Error parsing numeric literal: <2.0f>", Sema.Errors[1]);
+ EXPECT_EQ(34.56e-78, Sema.Values[2].getDouble());
+ EXPECT_EQ(4e+6, Sema.Values[3].getDouble());
+ EXPECT_FALSE(Sema.Values[4].isDouble());
+}
+
TEST(ParserTest, ParseUnsigned) {
MockSema Sema;
Sema.parse("0");
@@ -95,8 +110,8 @@ TEST(ParserTest, ParseUnsigned) {
EXPECT_EQ(0U, Sema.Values[0].getUnsigned());
EXPECT_EQ(123U, Sema.Values[1].getUnsigned());
EXPECT_EQ(31U, Sema.Values[2].getUnsigned());
- EXPECT_EQ("1:1: Error parsing unsigned token: <12345678901>", Sema.Errors[3]);
- EXPECT_EQ("1:1: Error parsing unsigned token: <1a1>", Sema.Errors[4]);
+ EXPECT_EQ("1:1: Error parsing numeric literal: <12345678901>", Sema.Errors[3]);
+ EXPECT_EQ("1:1: Error parsing numeric literal: <1a1>", Sema.Errors[4]);
}
TEST(ParserTest, ParseString) {
diff --git a/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp b/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
index ca0eb90285..7d3a07028a 100644
--- a/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
+++ b/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
@@ -76,6 +76,7 @@ TEST(VariantValueTest, Assignment) {
EXPECT_EQ("A", Value.getString());
EXPECT_TRUE(Value.hasValue());
EXPECT_FALSE(Value.isBoolean());
+ EXPECT_FALSE(Value.isDouble());
EXPECT_FALSE(Value.isUnsigned());
EXPECT_FALSE(Value.isMatcher());
EXPECT_EQ("String", Value.getTypeAsString());
@@ -83,6 +84,7 @@ TEST(VariantValueTest, Assignment) {
Value = VariantMatcher::SingleMatcher(recordDecl());
EXPECT_TRUE(Value.hasValue());
EXPECT_FALSE(Value.isBoolean());
+ EXPECT_FALSE(Value.isDouble());
EXPECT_FALSE(Value.isUnsigned());
EXPECT_FALSE(Value.isString());
EXPECT_TRUE(Value.isMatcher());
@@ -98,10 +100,20 @@ TEST(VariantValueTest, Assignment) {
EXPECT_FALSE(Value.isMatcher());
EXPECT_FALSE(Value.isString());
+ Value = 3.14;
+ EXPECT_TRUE(Value.isDouble());
+ EXPECT_EQ(3.14, Value.getDouble());
+ EXPECT_TRUE(Value.hasValue());
+ EXPECT_FALSE(Value.isBoolean());
+ EXPECT_FALSE(Value.isUnsigned());
+ EXPECT_FALSE(Value.isMatcher());
+ EXPECT_FALSE(Value.isString());
+
Value = 17;
EXPECT_TRUE(Value.isUnsigned());
EXPECT_EQ(17U, Value.getUnsigned());
EXPECT_FALSE(Value.isBoolean());
+ EXPECT_FALSE(Value.isDouble());
EXPECT_TRUE(Value.hasValue());
EXPECT_FALSE(Value.isMatcher());
EXPECT_FALSE(Value.isString());
@@ -109,6 +121,7 @@ TEST(VariantValueTest, Assignment) {
Value = VariantValue();
EXPECT_FALSE(Value.hasValue());
EXPECT_FALSE(Value.isBoolean());
+ EXPECT_FALSE(Value.isDouble());
EXPECT_FALSE(Value.isUnsigned());
EXPECT_FALSE(Value.isString());
EXPECT_FALSE(Value.isMatcher());