[docs] Fix build-docs.sh
[llvm-project.git] / llvm / unittests / ADT / FloatingPointMode.cpp
blob5b819f3495afcc545f34902e9d4b31bc4a16f0be
1 //===- llvm/unittest/ADT/FloatingPointMode.cpp ----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/FloatingPointMode.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
16 TEST(FloatingPointModeTest, ParseDenormalFPAttributeComponent) {
17 EXPECT_EQ(DenormalMode::IEEE, parseDenormalFPAttributeComponent("ieee"));
18 EXPECT_EQ(DenormalMode::IEEE, parseDenormalFPAttributeComponent(""));
19 EXPECT_EQ(DenormalMode::PreserveSign,
20 parseDenormalFPAttributeComponent("preserve-sign"));
21 EXPECT_EQ(DenormalMode::PositiveZero,
22 parseDenormalFPAttributeComponent("positive-zero"));
23 EXPECT_EQ(DenormalMode::Invalid, parseDenormalFPAttributeComponent("foo"));
26 TEST(FloatingPointModeTest, DenormalAttributeName) {
27 EXPECT_EQ("ieee", denormalModeKindName(DenormalMode::IEEE));
28 EXPECT_EQ("preserve-sign", denormalModeKindName(DenormalMode::PreserveSign));
29 EXPECT_EQ("positive-zero", denormalModeKindName(DenormalMode::PositiveZero));
30 EXPECT_EQ("", denormalModeKindName(DenormalMode::Invalid));
33 TEST(FloatingPointModeTest, ParseDenormalFPAttribute) {
34 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
35 parseDenormalFPAttribute("ieee"));
36 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
37 parseDenormalFPAttribute("ieee,ieee"));
38 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
39 parseDenormalFPAttribute("ieee,"));
40 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
41 parseDenormalFPAttribute(""));
42 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
43 parseDenormalFPAttribute(","));
45 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
46 parseDenormalFPAttribute("preserve-sign"));
47 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
48 parseDenormalFPAttribute("preserve-sign,"));
49 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
50 parseDenormalFPAttribute("preserve-sign,preserve-sign"));
52 EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
53 parseDenormalFPAttribute("positive-zero"));
54 EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
55 parseDenormalFPAttribute("positive-zero,positive-zero"));
58 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::PositiveZero),
59 parseDenormalFPAttribute("ieee,positive-zero"));
60 EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::IEEE),
61 parseDenormalFPAttribute("positive-zero,ieee"));
63 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::IEEE),
64 parseDenormalFPAttribute("preserve-sign,ieee"));
65 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::PreserveSign),
66 parseDenormalFPAttribute("ieee,preserve-sign"));
69 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
70 parseDenormalFPAttribute("foo"));
71 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
72 parseDenormalFPAttribute("foo,foo"));
73 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
74 parseDenormalFPAttribute("foo,bar"));
77 TEST(FloatingPointModeTest, RenderDenormalFPAttribute) {
78 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
79 parseDenormalFPAttribute("foo"));
81 EXPECT_EQ("ieee,ieee",
82 DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).str());
83 EXPECT_EQ(",",
84 DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid).str());
86 EXPECT_EQ(
87 "preserve-sign,preserve-sign",
88 DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign).str());
90 EXPECT_EQ(
91 "positive-zero,positive-zero",
92 DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero).str());
94 EXPECT_EQ(
95 "ieee,preserve-sign",
96 DenormalMode(DenormalMode::IEEE, DenormalMode::PreserveSign).str());
98 EXPECT_EQ(
99 "preserve-sign,ieee",
100 DenormalMode(DenormalMode::PreserveSign, DenormalMode::IEEE).str());
102 EXPECT_EQ(
103 "preserve-sign,positive-zero",
104 DenormalMode(DenormalMode::PreserveSign, DenormalMode::PositiveZero).str());
107 TEST(FloatingPointModeTest, DenormalModeIsSimple) {
108 EXPECT_TRUE(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).isSimple());
109 EXPECT_FALSE(DenormalMode(DenormalMode::IEEE,
110 DenormalMode::Invalid).isSimple());
111 EXPECT_FALSE(DenormalMode(DenormalMode::PreserveSign,
112 DenormalMode::PositiveZero).isSimple());
115 TEST(FloatingPointModeTest, DenormalModeIsValid) {
116 EXPECT_TRUE(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE).isValid());
117 EXPECT_FALSE(DenormalMode(DenormalMode::IEEE, DenormalMode::Invalid).isValid());
118 EXPECT_FALSE(DenormalMode(DenormalMode::Invalid, DenormalMode::IEEE).isValid());
119 EXPECT_FALSE(DenormalMode(DenormalMode::Invalid,
120 DenormalMode::Invalid).isValid());
123 TEST(FloatingPointModeTest, DenormalModeConstructor) {
124 EXPECT_EQ(DenormalMode(DenormalMode::Invalid, DenormalMode::Invalid),
125 DenormalMode::getInvalid());
126 EXPECT_EQ(DenormalMode(DenormalMode::IEEE, DenormalMode::IEEE),
127 DenormalMode::getIEEE());
128 EXPECT_EQ(DenormalMode(DenormalMode::PreserveSign, DenormalMode::PreserveSign),
129 DenormalMode::getPreserveSign());
130 EXPECT_EQ(DenormalMode(DenormalMode::PositiveZero, DenormalMode::PositiveZero),
131 DenormalMode::getPositiveZero());