Path: blob/main_old/src/tests/preprocessor_tests/identifier_test.cpp
1693 views
//1// Copyright 2012 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56#include <tuple>78#include "PreprocessorTest.h"9#include "compiler/preprocessor/Token.h"1011namespace angle12{1314#define CLOSED_RANGE(x, y) testing::Range(x, static_cast<char>((y) + 1))1516class IdentifierTest : public SimplePreprocessorTest17{18protected:19void expectIdentifier(const std::string &str)20{21const char *cstr = str.c_str();2223pp::Token token;24lexSingleToken(cstr, &token);25EXPECT_EQ(pp::Token::IDENTIFIER, token.type);26EXPECT_EQ(str, token.text);27}28};2930class SingleLetterIdentifierTest : public IdentifierTest, public testing::WithParamInterface<char>31{};3233// This test covers identifier names of form [_a-zA-Z].34TEST_P(SingleLetterIdentifierTest, Identified)35{36std::string str(1, GetParam());37expectIdentifier(str);38}3940// Test string: '_'41INSTANTIATE_TEST_SUITE_P(Underscore, SingleLetterIdentifierTest, testing::Values('_'));4243// Test string: [a-z]44INSTANTIATE_TEST_SUITE_P(a_z, SingleLetterIdentifierTest, CLOSED_RANGE('a', 'z'));4546// Test string: [A-Z]47INSTANTIATE_TEST_SUITE_P(A_Z, SingleLetterIdentifierTest, CLOSED_RANGE('A', 'Z'));4849typedef std::tuple<char, char> IdentifierParams;50class DoubleLetterIdentifierTest : public IdentifierTest,51public testing::WithParamInterface<IdentifierParams>52{};5354// This test covers identifier names of form [_a-zA-Z][_a-zA-Z0-9].55TEST_P(DoubleLetterIdentifierTest, Identified)56{57std::string str;58str.push_back(std::get<0>(GetParam()));59str.push_back(std::get<1>(GetParam()));6061expectIdentifier(str);62}6364// Test string: "__"65INSTANTIATE_TEST_SUITE_P(Underscore_Underscore,66DoubleLetterIdentifierTest,67testing::Combine(testing::Values('_'), testing::Values('_')));6869// Test string: "_"[a-z]70INSTANTIATE_TEST_SUITE_P(Underscore_a_z,71DoubleLetterIdentifierTest,72testing::Combine(testing::Values('_'), CLOSED_RANGE('a', 'z')));7374// Test string: "_"[A-Z]75INSTANTIATE_TEST_SUITE_P(Underscore_A_Z,76DoubleLetterIdentifierTest,77testing::Combine(testing::Values('_'), CLOSED_RANGE('A', 'Z')));7879// Test string: "_"[0-9]80INSTANTIATE_TEST_SUITE_P(Underscore_0_9,81DoubleLetterIdentifierTest,82testing::Combine(testing::Values('_'), CLOSED_RANGE('0', '9')));8384// Test string: [a-z]"_"85INSTANTIATE_TEST_SUITE_P(a_z_Underscore,86DoubleLetterIdentifierTest,87testing::Combine(CLOSED_RANGE('a', 'z'), testing::Values('_')));8889// Test string: [a-z][a-z]90INSTANTIATE_TEST_SUITE_P(a_z_a_z,91DoubleLetterIdentifierTest,92testing::Combine(CLOSED_RANGE('a', 'z'), CLOSED_RANGE('a', 'z')));9394// Test string: [a-z][A-Z]95INSTANTIATE_TEST_SUITE_P(a_z_A_Z,96DoubleLetterIdentifierTest,97testing::Combine(CLOSED_RANGE('a', 'z'), CLOSED_RANGE('A', 'Z')));9899// Test string: [a-z][0-9]100INSTANTIATE_TEST_SUITE_P(a_z_0_9,101DoubleLetterIdentifierTest,102testing::Combine(CLOSED_RANGE('a', 'z'), CLOSED_RANGE('0', '9')));103104// Test string: [A-Z]"_"105INSTANTIATE_TEST_SUITE_P(A_Z_Underscore,106DoubleLetterIdentifierTest,107testing::Combine(CLOSED_RANGE('A', 'Z'), testing::Values('_')));108109// Test string: [A-Z][a-z]110INSTANTIATE_TEST_SUITE_P(A_Z_a_z,111DoubleLetterIdentifierTest,112testing::Combine(CLOSED_RANGE('A', 'Z'), CLOSED_RANGE('a', 'z')));113114// Test string: [A-Z][A-Z]115INSTANTIATE_TEST_SUITE_P(A_Z_A_Z,116DoubleLetterIdentifierTest,117testing::Combine(CLOSED_RANGE('A', 'Z'), CLOSED_RANGE('A', 'Z')));118119// Test string: [A-Z][0-9]120INSTANTIATE_TEST_SUITE_P(A_Z_0_9,121DoubleLetterIdentifierTest,122testing::Combine(CLOSED_RANGE('A', 'Z'), CLOSED_RANGE('0', '9')));123124// The tests above cover one-letter and various combinations of two-letter125// identifier names. This test covers all characters in a single string.126TEST_F(IdentifierTest, AllLetters)127{128std::string str;129for (char c = 'a'; c <= 'z'; ++c)130str.push_back(c);131132str.push_back('_');133134for (char c = 'A'; c <= 'Z'; ++c)135str.push_back(c);136137str.push_back('_');138139for (char c = '0'; c <= '9'; ++c)140str.push_back(c);141142expectIdentifier(str);143}144145} // namespace angle146147148