blob: 721aacf1b9e2c88d810761f3337f72aa53371745 [file] [log] [blame]
// Copyright 2022 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////////////////////
// File generated by 'tools/src/cmd/gen' using the template:
// src/tint/lang/core/builtin_value_test.cc.tmpl
//
// To regenerate run: './tools/run gen'
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/lang/core/builtin_value.h"
#include <gtest/gtest.h>
#include <string>
#include "src/tint/utils/text/string.h"
namespace tint::core {
namespace {
namespace parse_print_tests {
struct Case {
const char* string;
BuiltinValue value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"__point_size", BuiltinValue::kPointSize},
{"frag_depth", BuiltinValue::kFragDepth},
{"front_facing", BuiltinValue::kFrontFacing},
{"global_invocation_id", BuiltinValue::kGlobalInvocationId},
{"instance_index", BuiltinValue::kInstanceIndex},
{"local_invocation_id", BuiltinValue::kLocalInvocationId},
{"local_invocation_index", BuiltinValue::kLocalInvocationIndex},
{"num_workgroups", BuiltinValue::kNumWorkgroups},
{"position", BuiltinValue::kPosition},
{"sample_index", BuiltinValue::kSampleIndex},
{"sample_mask", BuiltinValue::kSampleMask},
{"subgroup_invocation_id", BuiltinValue::kSubgroupInvocationId},
{"subgroup_size", BuiltinValue::kSubgroupSize},
{"vertex_index", BuiltinValue::kVertexIndex},
{"workgroup_id", BuiltinValue::kWorkgroupId},
};
static constexpr Case kInvalidCases[] = {
{"_ccpoint_siz", BuiltinValue::kUndefined},
{"_3poi_ile", BuiltinValue::kUndefined},
{"__poiVt_size", BuiltinValue::kUndefined},
{"frag1depth", BuiltinValue::kUndefined},
{"fraJqqepth", BuiltinValue::kUndefined},
{"fra7ll_depth", BuiltinValue::kUndefined},
{"fonHHpp_facing", BuiltinValue::kUndefined},
{"fron_facg", BuiltinValue::kUndefined},
{"frGnt_fbcin", BuiltinValue::kUndefined},
{"glvbal_iinvocation_id", BuiltinValue::kUndefined},
{"gl8bal_invocation_WWd", BuiltinValue::kUndefined},
{"Mlobal_invocaton_xxd", BuiltinValue::kUndefined},
{"isXance_indegg", BuiltinValue::kUndefined},
{"insanc_iXVex", BuiltinValue::kUndefined},
{"instance_in3ex", BuiltinValue::kUndefined},
{"local_Envocation_id", BuiltinValue::kUndefined},
{"localiPPvocatioTT_id", BuiltinValue::kUndefined},
{"localxxnvocationddid", BuiltinValue::kUndefined},
{"loca44_invocation_index", BuiltinValue::kUndefined},
{"local_invocSStionVVindex", BuiltinValue::kUndefined},
{"locRR_invocat22n_index", BuiltinValue::kUndefined},
{"nuF_workrou9s", BuiltinValue::kUndefined},
{"numworkgroups", BuiltinValue::kUndefined},
{"nuRRworVgOOHups", BuiltinValue::kUndefined},
{"posytio", BuiltinValue::kUndefined},
{"77orritllnon", BuiltinValue::kUndefined},
{"04osition", BuiltinValue::kUndefined},
{"smpe_oonde", BuiltinValue::kUndefined},
{"smpl_inzzex", BuiltinValue::kUndefined},
{"saiip11eindep", BuiltinValue::kUndefined},
{"sample_XXask", BuiltinValue::kUndefined},
{"samII99l55_mask", BuiltinValue::kUndefined},
{"samaale_SSrHHYk", BuiltinValue::kUndefined},
{"skkgroup_Hnvocatio_d", BuiltinValue::kUndefined},
{"gRbgroup_invocajionid", BuiltinValue::kUndefined},
{"sbgroup_nbocation_id", BuiltinValue::kUndefined},
{"subgroupjsize", BuiltinValue::kUndefined},
{"subgroup_sie", BuiltinValue::kUndefined},
{"sgroupqsize", BuiltinValue::kUndefined},
{"vertx_NNndex", BuiltinValue::kUndefined},
{"vvertex_dex", BuiltinValue::kUndefined},
{"ertex_inQQex", BuiltinValue::kUndefined},
{"wrkgrup_irf", BuiltinValue::kUndefined},
{"workgroup_jd", BuiltinValue::kUndefined},
{"w82wNNgrou_id", BuiltinValue::kUndefined},
};
using BuiltinValueParseTest = testing::TestWithParam<Case>;
TEST_P(BuiltinValueParseTest, Parse) {
const char* string = GetParam().string;
BuiltinValue expect = GetParam().value;
EXPECT_EQ(expect, ParseBuiltinValue(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, BuiltinValueParseTest, testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases, BuiltinValueParseTest, testing::ValuesIn(kInvalidCases));
using BuiltinValuePrintTest = testing::TestWithParam<Case>;
TEST_P(BuiltinValuePrintTest, Print) {
BuiltinValue value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, tint::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, BuiltinValuePrintTest, testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace
} // namespace tint::core