mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-04 20:25:56 +00:00
Emit unit tests for parsing and printing. Emit benchmarks for parsing. Uses intrinsics.def as a single-source-of-truth. The generators provide a way to optimize the enum parsers. Change-Id: I1669c123d375f24aca45f3ea4abf04d7892673c7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97150 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@chromium.org>
95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
// Copyright 2022 The Tint Authors.
|
|
//
|
|
// 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.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// File generated by tools/src/cmd/gen
|
|
// using the template:
|
|
// src/tint/ast/storage_class_test.cc.tmpl
|
|
//
|
|
// Do not modify this file directly
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "src/tint/ast/storage_class.h"
|
|
|
|
#include <string>
|
|
|
|
#include "src/tint/ast/test_helper.h"
|
|
#include "src/tint/utils/string.h"
|
|
|
|
namespace tint::ast {
|
|
namespace {
|
|
|
|
namespace parse_print_tests {
|
|
|
|
struct Case {
|
|
const char* string;
|
|
StorageClass value;
|
|
};
|
|
|
|
inline std::ostream& operator<<(std::ostream& out, Case c) {
|
|
return out << "'" << std::string(c.string) << "'";
|
|
}
|
|
|
|
static constexpr Case kValidCases[] = {
|
|
{"function", StorageClass::kFunction},
|
|
{"private", StorageClass::kPrivate},
|
|
{"workgroup", StorageClass::kWorkgroup},
|
|
{"uniform", StorageClass::kUniform},
|
|
{"storage", StorageClass::kStorage},
|
|
};
|
|
|
|
static constexpr Case kInvalidCases[] = {
|
|
{"fccnctin", StorageClass::kInvalid},
|
|
{"ucti3", StorageClass::kInvalid},
|
|
{"functVon", StorageClass::kInvalid},
|
|
{"priv1te", StorageClass::kInvalid},
|
|
{"pqiJate", StorageClass::kInvalid},
|
|
{"privat7ll", StorageClass::kInvalid},
|
|
{"workroppqHH", StorageClass::kInvalid},
|
|
{"workru", StorageClass::kInvalid},
|
|
{"wbkgGoup", StorageClass::kInvalid},
|
|
{"unifiivm", StorageClass::kInvalid},
|
|
{"8WWiform", StorageClass::kInvalid},
|
|
{"uxxform", StorageClass::kInvalid},
|
|
{"sXraggg", StorageClass::kInvalid},
|
|
{"traXe", StorageClass::kInvalid},
|
|
{"stor3ge", StorageClass::kInvalid},
|
|
};
|
|
|
|
using StorageClassParseTest = testing::TestWithParam<Case>;
|
|
|
|
TEST_P(StorageClassParseTest, Parse) {
|
|
const char* string = GetParam().string;
|
|
StorageClass expect = GetParam().value;
|
|
EXPECT_EQ(expect, ParseStorageClass(string));
|
|
}
|
|
|
|
INSTANTIATE_TEST_SUITE_P(ValidCases, StorageClassParseTest, testing::ValuesIn(kValidCases));
|
|
INSTANTIATE_TEST_SUITE_P(InvalidCases, StorageClassParseTest, testing::ValuesIn(kInvalidCases));
|
|
|
|
using StorageClassPrintTest = testing::TestWithParam<Case>;
|
|
|
|
TEST_P(StorageClassPrintTest, Print) {
|
|
StorageClass value = GetParam().value;
|
|
const char* expect = GetParam().string;
|
|
EXPECT_EQ(expect, utils::ToString(value));
|
|
}
|
|
|
|
INSTANTIATE_TEST_SUITE_P(ValidCases, StorageClassPrintTest, testing::ValuesIn(kValidCases));
|
|
|
|
} // namespace parse_print_tests
|
|
|
|
} // namespace
|
|
} // namespace tint::ast
|