1 /* ----------------------------------------------------------------------
2    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3    https://www.lammps.org/, Sandia National Laboratories
4    Steve Plimpton, sjplimp@sandia.gov
5 
6    Copyright (2003) Sandia Corporation.  Under the terms of Contract
7    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
8    certain rights in this software.  This software is distributed under
9    the GNU General Public License.
10 
11    See the README file in the top-level LAMMPS directory.
12 ------------------------------------------------------------------------- */
13 
14 #include "fmt/format.h"
15 #include "lmptype.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
18 #include <exception>
19 
20 using namespace LAMMPS_NS;
21 using ::testing::Eq;
22 
23 // this tests a subset of {fmt} that is most relevant to LAMMPS
24 
TEST(FmtLib,insert_string)25 TEST(FmtLib, insert_string)
26 {
27     const char val[] = "word";
28     auto text        = fmt::format("word {}", val);
29     ASSERT_THAT(text, Eq("word word"));
30 }
31 
TEST(FmtLib,insert_int)32 TEST(FmtLib, insert_int)
33 {
34     const int val = 333;
35     auto text     = fmt::format("word {}", val);
36     ASSERT_THAT(text, Eq("word 333"));
37 }
38 
TEST(FmtLib,insert_neg_int)39 TEST(FmtLib, insert_neg_int)
40 {
41     const int val = -333;
42     auto text     = fmt::format("word {}", val);
43     ASSERT_THAT(text, Eq("word -333"));
44 }
45 
TEST(FmtLib,insert_bigint)46 TEST(FmtLib, insert_bigint)
47 {
48 #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
49     const bigint val = 9945234592L;
50     auto text        = fmt::format("word {}", val);
51     ASSERT_THAT(text, Eq("word 9945234592"));
52 #else
53     GTEST_SKIP();
54 #endif
55 }
56 
TEST(FmtLib,insert_neg_bigint)57 TEST(FmtLib, insert_neg_bigint)
58 {
59 #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
60     const bigint val = -9945234592L;
61     auto text        = fmt::format("word {}", val);
62     ASSERT_THAT(text, Eq("word -9945234592"));
63 #else
64     GTEST_SKIP();
65 #endif
66 }
67 
TEST(FmtLib,insert_tagint)68 TEST(FmtLib, insert_tagint)
69 {
70 #if defined(LAMMPS_BIGBIG)
71     const tagint val = 9945234592L;
72     auto text        = fmt::format("word {}", val);
73     ASSERT_THAT(text, Eq("word 9945234592"));
74 #else
75     GTEST_SKIP();
76 #endif
77 }
78 
TEST(FmtLib,insert_neg_tagint)79 TEST(FmtLib, insert_neg_tagint)
80 {
81 #if defined(LAMMPS_BIGBIG)
82     const tagint val = -9945234592L;
83     auto text        = fmt::format("word {}", val);
84     ASSERT_THAT(text, Eq("word -9945234592"));
85 #else
86     GTEST_SKIP();
87 #endif
88 }
89 
TEST(FmtLib,insert_imageint)90 TEST(FmtLib, insert_imageint)
91 {
92 #if defined(LAMMPS_BIGBIG)
93     const imageint val = 9945234592L;
94     auto text          = fmt::format("word {}", val);
95     ASSERT_THAT(text, Eq("word 9945234592"));
96 #else
97     GTEST_SKIP();
98 #endif
99 }
100 
TEST(FmtLib,insert_neg_imageint)101 TEST(FmtLib, insert_neg_imageint)
102 {
103 #if defined(LAMMPS_BIGBIG)
104     const imageint val = -9945234592L;
105     auto text          = fmt::format("word {}", val);
106     ASSERT_THAT(text, Eq("word -9945234592"));
107 #else
108     GTEST_SKIP();
109 #endif
110 }
111 
TEST(FmtLib,insert_double)112 TEST(FmtLib, insert_double)
113 {
114     const double val = 1.5;
115     auto text        = fmt::format("word {}", val);
116     ASSERT_THAT(text, Eq("word 1.5"));
117 }
118 
TEST(FmtLib,insert_neg_double)119 TEST(FmtLib, insert_neg_double)
120 {
121     const double val = -1.5;
122     auto text        = fmt::format("word {}", val);
123     ASSERT_THAT(text, Eq("word -1.5"));
124 }
125 
TEST(FmtLib,int_for_double)126 TEST(FmtLib, int_for_double)
127 {
128     const double val = -1.5;
129     ASSERT_THROW(fmt::format("word {:d}", val), std::exception);
130 }
131 
TEST(FmtLib,double_for_int)132 TEST(FmtLib, double_for_int)
133 {
134     const int val = 15;
135     ASSERT_THROW(fmt::format("word {:g}", val), std::exception);
136 }
137