1bad3168bSMichael Jones //===-- Unittests for atoll -----------------------------------------------===//
2bad3168bSMichael Jones //
3bad3168bSMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4bad3168bSMichael Jones // See https://llvm.org/LICENSE.txt for license information.
5bad3168bSMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6bad3168bSMichael Jones //
7bad3168bSMichael Jones //===----------------------------------------------------------------------===//
8bad3168bSMichael Jones 
9bad3168bSMichael Jones #include "src/stdlib/atoll.h"
10bad3168bSMichael Jones 
11bad3168bSMichael Jones #include "utils/UnitTest/Test.h"
12bad3168bSMichael Jones 
13bad3168bSMichael Jones #include <limits.h>
14bad3168bSMichael Jones 
TEST(LlvmLibcAToLLTest,ValidNumbers)15bad3168bSMichael Jones TEST(LlvmLibcAToLLTest, ValidNumbers) {
16bad3168bSMichael Jones   const char *zero = "0";
17bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(zero), 0ll);
18bad3168bSMichael Jones 
19bad3168bSMichael Jones   const char *ten = "10";
20bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(ten), 10ll);
21bad3168bSMichael Jones 
22bad3168bSMichael Jones   const char *negative_hundred = "-100";
23bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(negative_hundred), -100ll);
24bad3168bSMichael Jones 
25bad3168bSMichael Jones   const char *positive_thousand = "+1000";
26bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(positive_thousand), 1000ll);
27bad3168bSMichael Jones 
28bad3168bSMichael Jones   const char *spaces_before = "     12345";
29bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(spaces_before), 12345ll);
30bad3168bSMichael Jones 
31bad3168bSMichael Jones   const char *tabs_before = "\t\t\t\t67890";
32bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(tabs_before), 67890ll);
33bad3168bSMichael Jones 
34bad3168bSMichael Jones   const char *letters_after = "123abc";
35bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(letters_after), 123ll);
36bad3168bSMichael Jones 
37bad3168bSMichael Jones   const char *letters_between = "456def789";
38bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(letters_between), 456ll);
39bad3168bSMichael Jones 
40bad3168bSMichael Jones   const char *all_together = "\t   110 times 5 = 550";
41bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(all_together), 110ll);
42bad3168bSMichael Jones 
43bad3168bSMichael Jones   const char *biggest_long_long = "9223372036854775807";
44*eff11176SMichael Jones   ASSERT_EQ(__llvm_libc::atoll(biggest_long_long), LLONG_MAX);
45bad3168bSMichael Jones 
46bad3168bSMichael Jones   const char *smallest_long_long = "-9223372036854775808";
47*eff11176SMichael Jones   ASSERT_EQ(__llvm_libc::atoll(smallest_long_long), LLONG_MIN);
48bad3168bSMichael Jones }
49bad3168bSMichael Jones 
TEST(LlvmLibcAToLLTest,NonBaseTenWholeNumbers)50bad3168bSMichael Jones TEST(LlvmLibcAToLLTest, NonBaseTenWholeNumbers) {
51bad3168bSMichael Jones   const char *hexadecimal = "0x10";
52bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(hexadecimal), 0ll);
53bad3168bSMichael Jones 
54bad3168bSMichael Jones   const char *octal = "010";
55*eff11176SMichael Jones   ASSERT_EQ(__llvm_libc::atoll(octal), 10ll);
56bad3168bSMichael Jones 
57bad3168bSMichael Jones   const char *decimal_point = "5.9";
58*eff11176SMichael Jones   ASSERT_EQ(__llvm_libc::atoll(decimal_point), 5ll);
59bad3168bSMichael Jones }
60bad3168bSMichael Jones 
TEST(LlvmLibcAToLLTest,NotNumbers)61bad3168bSMichael Jones TEST(LlvmLibcAToLLTest, NotNumbers) {
62bad3168bSMichael Jones   const char *ten_as_word = "ten";
63bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(ten_as_word), 0ll);
64bad3168bSMichael Jones 
65bad3168bSMichael Jones   const char *lots_of_letters =
66bad3168bSMichael Jones       "wtragsdhfgjykutjdyfhgnchgmjhkyurktfgjhlu;po7urtdjyfhgklyk";
67bad3168bSMichael Jones   ASSERT_EQ(__llvm_libc::atoll(lots_of_letters), 0ll);
68bad3168bSMichael Jones }
69