Revert "[lldb][test] Remove compiler version check and use regex" (#124101)
[llvm-project.git] / libc / test / src / stdlib / atof_test.cpp
blob1e4259b792d7ef1b1cf16be79a88ba438c938b99
1 //===-- Unittests for atof ------------------------------------------------===//
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 "src/__support/FPUtil/FPBits.h"
10 #include "src/errno/libc_errno.h"
11 #include "src/stdlib/atof.h"
13 #include "test/UnitTest/ErrnoSetterMatcher.h"
14 #include "test/UnitTest/Test.h"
16 #include <stddef.h>
18 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
20 // This is just a simple test to make sure that this function works at all. It's
21 // functionally identical to strtod so the bulk of the testing is there.
22 TEST(LlvmLibcAToFTest, SimpleTest) {
23 LIBC_NAMESPACE::fputil::FPBits<double> expected_fp =
24 LIBC_NAMESPACE::fputil::FPBits<double>(uint64_t(0x405ec00000000000));
26 LIBC_NAMESPACE::libc_errno = 0;
27 EXPECT_THAT(LIBC_NAMESPACE::atof("123"),
28 Succeeds<double>(expected_fp.get_val()));
31 TEST(LlvmLibcAToFTest, FailedParsingTest) {
32 LIBC_NAMESPACE::libc_errno = 0;
33 // atof does not flag errors.
34 EXPECT_THAT(LIBC_NAMESPACE::atof("???"), Succeeds<double>(0.0));