• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <string>
16 
17 #include "gtest/gtest.h"
18 #include "source/util/string_utils.h"
19 #include "spirv-tools/libspirv.h"
20 
21 namespace spvtools {
22 namespace utils {
23 namespace {
24 
TEST(ToString,Int)25 TEST(ToString, Int) {
26   EXPECT_EQ("0", ToString(0));
27   EXPECT_EQ("1000", ToString(1000));
28   EXPECT_EQ("-1", ToString(-1));
29   EXPECT_EQ("0", ToString(0LL));
30   EXPECT_EQ("1000", ToString(1000LL));
31   EXPECT_EQ("-1", ToString(-1LL));
32 }
33 
TEST(ToString,Uint)34 TEST(ToString, Uint) {
35   EXPECT_EQ("0", ToString(0U));
36   EXPECT_EQ("1000", ToString(1000U));
37   EXPECT_EQ("0", ToString(0ULL));
38   EXPECT_EQ("1000", ToString(1000ULL));
39 }
40 
TEST(ToString,Float)41 TEST(ToString, Float) {
42   EXPECT_EQ("0", ToString(0.f));
43   EXPECT_EQ("1000", ToString(1000.f));
44   EXPECT_EQ("-1.5", ToString(-1.5f));
45 }
46 
TEST(ToString,Double)47 TEST(ToString, Double) {
48   EXPECT_EQ("0", ToString(0.));
49   EXPECT_EQ("1000", ToString(1000.));
50   EXPECT_EQ("-1.5", ToString(-1.5));
51 }
52 
TEST(CardinalToOrdinal,Test)53 TEST(CardinalToOrdinal, Test) {
54   EXPECT_EQ("1st", CardinalToOrdinal(1));
55   EXPECT_EQ("2nd", CardinalToOrdinal(2));
56   EXPECT_EQ("3rd", CardinalToOrdinal(3));
57   EXPECT_EQ("4th", CardinalToOrdinal(4));
58   EXPECT_EQ("5th", CardinalToOrdinal(5));
59   EXPECT_EQ("6th", CardinalToOrdinal(6));
60   EXPECT_EQ("7th", CardinalToOrdinal(7));
61   EXPECT_EQ("8th", CardinalToOrdinal(8));
62   EXPECT_EQ("9th", CardinalToOrdinal(9));
63   EXPECT_EQ("10th", CardinalToOrdinal(10));
64   EXPECT_EQ("11th", CardinalToOrdinal(11));
65   EXPECT_EQ("12th", CardinalToOrdinal(12));
66   EXPECT_EQ("13th", CardinalToOrdinal(13));
67   EXPECT_EQ("14th", CardinalToOrdinal(14));
68   EXPECT_EQ("15th", CardinalToOrdinal(15));
69   EXPECT_EQ("16th", CardinalToOrdinal(16));
70   EXPECT_EQ("17th", CardinalToOrdinal(17));
71   EXPECT_EQ("18th", CardinalToOrdinal(18));
72   EXPECT_EQ("19th", CardinalToOrdinal(19));
73   EXPECT_EQ("20th", CardinalToOrdinal(20));
74   EXPECT_EQ("21st", CardinalToOrdinal(21));
75   EXPECT_EQ("22nd", CardinalToOrdinal(22));
76   EXPECT_EQ("23rd", CardinalToOrdinal(23));
77   EXPECT_EQ("24th", CardinalToOrdinal(24));
78   EXPECT_EQ("25th", CardinalToOrdinal(25));
79   EXPECT_EQ("26th", CardinalToOrdinal(26));
80   EXPECT_EQ("27th", CardinalToOrdinal(27));
81   EXPECT_EQ("28th", CardinalToOrdinal(28));
82   EXPECT_EQ("29th", CardinalToOrdinal(29));
83   EXPECT_EQ("30th", CardinalToOrdinal(30));
84   EXPECT_EQ("31st", CardinalToOrdinal(31));
85   EXPECT_EQ("32nd", CardinalToOrdinal(32));
86   EXPECT_EQ("33rd", CardinalToOrdinal(33));
87   EXPECT_EQ("34th", CardinalToOrdinal(34));
88   EXPECT_EQ("35th", CardinalToOrdinal(35));
89   EXPECT_EQ("100th", CardinalToOrdinal(100));
90   EXPECT_EQ("101st", CardinalToOrdinal(101));
91   EXPECT_EQ("102nd", CardinalToOrdinal(102));
92   EXPECT_EQ("103rd", CardinalToOrdinal(103));
93   EXPECT_EQ("104th", CardinalToOrdinal(104));
94   EXPECT_EQ("105th", CardinalToOrdinal(105));
95   EXPECT_EQ("106th", CardinalToOrdinal(106));
96   EXPECT_EQ("107th", CardinalToOrdinal(107));
97   EXPECT_EQ("108th", CardinalToOrdinal(108));
98   EXPECT_EQ("109th", CardinalToOrdinal(109));
99   EXPECT_EQ("110th", CardinalToOrdinal(110));
100   EXPECT_EQ("111th", CardinalToOrdinal(111));
101   EXPECT_EQ("112th", CardinalToOrdinal(112));
102   EXPECT_EQ("113th", CardinalToOrdinal(113));
103   EXPECT_EQ("114th", CardinalToOrdinal(114));
104   EXPECT_EQ("115th", CardinalToOrdinal(115));
105   EXPECT_EQ("116th", CardinalToOrdinal(116));
106   EXPECT_EQ("117th", CardinalToOrdinal(117));
107   EXPECT_EQ("118th", CardinalToOrdinal(118));
108   EXPECT_EQ("119th", CardinalToOrdinal(119));
109   EXPECT_EQ("120th", CardinalToOrdinal(120));
110   EXPECT_EQ("121st", CardinalToOrdinal(121));
111   EXPECT_EQ("122nd", CardinalToOrdinal(122));
112   EXPECT_EQ("123rd", CardinalToOrdinal(123));
113   EXPECT_EQ("124th", CardinalToOrdinal(124));
114   EXPECT_EQ("125th", CardinalToOrdinal(125));
115   EXPECT_EQ("126th", CardinalToOrdinal(126));
116   EXPECT_EQ("127th", CardinalToOrdinal(127));
117   EXPECT_EQ("128th", CardinalToOrdinal(128));
118   EXPECT_EQ("129th", CardinalToOrdinal(129));
119   EXPECT_EQ("130th", CardinalToOrdinal(130));
120   EXPECT_EQ("131st", CardinalToOrdinal(131));
121   EXPECT_EQ("132nd", CardinalToOrdinal(132));
122   EXPECT_EQ("133rd", CardinalToOrdinal(133));
123   EXPECT_EQ("134th", CardinalToOrdinal(134));
124   EXPECT_EQ("135th", CardinalToOrdinal(135));
125   EXPECT_EQ("1000th", CardinalToOrdinal(1000));
126   EXPECT_EQ("1001st", CardinalToOrdinal(1001));
127   EXPECT_EQ("1002nd", CardinalToOrdinal(1002));
128   EXPECT_EQ("1003rd", CardinalToOrdinal(1003));
129   EXPECT_EQ("1004th", CardinalToOrdinal(1004));
130   EXPECT_EQ("1005th", CardinalToOrdinal(1005));
131   EXPECT_EQ("1006th", CardinalToOrdinal(1006));
132   EXPECT_EQ("1007th", CardinalToOrdinal(1007));
133   EXPECT_EQ("1008th", CardinalToOrdinal(1008));
134   EXPECT_EQ("1009th", CardinalToOrdinal(1009));
135   EXPECT_EQ("1010th", CardinalToOrdinal(1010));
136   EXPECT_EQ("1011th", CardinalToOrdinal(1011));
137   EXPECT_EQ("1012th", CardinalToOrdinal(1012));
138   EXPECT_EQ("1013th", CardinalToOrdinal(1013));
139   EXPECT_EQ("1014th", CardinalToOrdinal(1014));
140   EXPECT_EQ("1015th", CardinalToOrdinal(1015));
141   EXPECT_EQ("1016th", CardinalToOrdinal(1016));
142   EXPECT_EQ("1017th", CardinalToOrdinal(1017));
143   EXPECT_EQ("1018th", CardinalToOrdinal(1018));
144   EXPECT_EQ("1019th", CardinalToOrdinal(1019));
145   EXPECT_EQ("1020th", CardinalToOrdinal(1020));
146   EXPECT_EQ("1021st", CardinalToOrdinal(1021));
147   EXPECT_EQ("1022nd", CardinalToOrdinal(1022));
148   EXPECT_EQ("1023rd", CardinalToOrdinal(1023));
149   EXPECT_EQ("1024th", CardinalToOrdinal(1024));
150   EXPECT_EQ("1025th", CardinalToOrdinal(1025));
151   EXPECT_EQ("1026th", CardinalToOrdinal(1026));
152   EXPECT_EQ("1027th", CardinalToOrdinal(1027));
153   EXPECT_EQ("1028th", CardinalToOrdinal(1028));
154   EXPECT_EQ("1029th", CardinalToOrdinal(1029));
155   EXPECT_EQ("1030th", CardinalToOrdinal(1030));
156   EXPECT_EQ("1031st", CardinalToOrdinal(1031));
157   EXPECT_EQ("1032nd", CardinalToOrdinal(1032));
158   EXPECT_EQ("1033rd", CardinalToOrdinal(1033));
159   EXPECT_EQ("1034th", CardinalToOrdinal(1034));
160   EXPECT_EQ("1035th", CardinalToOrdinal(1035));
161   EXPECT_EQ("1200th", CardinalToOrdinal(1200));
162   EXPECT_EQ("1201st", CardinalToOrdinal(1201));
163   EXPECT_EQ("1202nd", CardinalToOrdinal(1202));
164   EXPECT_EQ("1203rd", CardinalToOrdinal(1203));
165   EXPECT_EQ("1204th", CardinalToOrdinal(1204));
166   EXPECT_EQ("1205th", CardinalToOrdinal(1205));
167   EXPECT_EQ("1206th", CardinalToOrdinal(1206));
168   EXPECT_EQ("1207th", CardinalToOrdinal(1207));
169   EXPECT_EQ("1208th", CardinalToOrdinal(1208));
170   EXPECT_EQ("1209th", CardinalToOrdinal(1209));
171   EXPECT_EQ("1210th", CardinalToOrdinal(1210));
172   EXPECT_EQ("1211th", CardinalToOrdinal(1211));
173   EXPECT_EQ("1212th", CardinalToOrdinal(1212));
174   EXPECT_EQ("1213th", CardinalToOrdinal(1213));
175   EXPECT_EQ("1214th", CardinalToOrdinal(1214));
176   EXPECT_EQ("1215th", CardinalToOrdinal(1215));
177   EXPECT_EQ("1216th", CardinalToOrdinal(1216));
178   EXPECT_EQ("1217th", CardinalToOrdinal(1217));
179   EXPECT_EQ("1218th", CardinalToOrdinal(1218));
180   EXPECT_EQ("1219th", CardinalToOrdinal(1219));
181   EXPECT_EQ("1220th", CardinalToOrdinal(1220));
182   EXPECT_EQ("1221st", CardinalToOrdinal(1221));
183   EXPECT_EQ("1222nd", CardinalToOrdinal(1222));
184   EXPECT_EQ("1223rd", CardinalToOrdinal(1223));
185   EXPECT_EQ("1224th", CardinalToOrdinal(1224));
186   EXPECT_EQ("1225th", CardinalToOrdinal(1225));
187 }
188 
189 }  // namespace
190 }  // namespace utils
191 }  // namespace spvtools
192