/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include namespace apache::thrift::compiler { namespace { TEST(TEnumTest, Unused) { t_program program("path/to/program.thrift"); program.set_package(t_package{"test.dev/foo/bar"}); t_enum& def = program.add_def(std::make_unique(&program, "Enum")); EXPECT_EQ(def.unused(), 113); def.append_value(std::make_unique("zero", 0)); def.append_value(std::make_unique("two", 2)); def.append_value(std::make_unique("one", 1)); def.append_value(std::make_unique("ntwo", -2)); def.append_value(std::make_unique( "max", std::numeric_limits::max())); EXPECT_EQ(def.unused(), 113); def.append_value(std::make_unique("t1", 113)); EXPECT_EQ(def.unused(), 113 + 1); def.append_value(std::make_unique("t2", 113 + 2)); def.append_value(std::make_unique("t3", 113 + 3)); def.append_value(std::make_unique("t4", 113 + 5)); EXPECT_EQ(def.unused(), 113 + 1); def.append_value(std::make_unique("t5", def.unused())); EXPECT_EQ(def.unused(), 113 + 4); def.append_value(std::make_unique("t6", def.unused())); EXPECT_EQ(def.unused(), 113 + 6); def.append_value(std::make_unique("t7", def.unused())); EXPECT_EQ(def.unused(), 113 + 7); } } // namespace } // namespace apache::thrift::compiler