Path: blob/main_old/src/tests/preprocessor_tests/pragma_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 "PreprocessorTest.h"7#include "compiler/preprocessor/Token.h"89namespace angle10{1112class PragmaTest : public SimplePreprocessorTest13{};1415TEST_F(PragmaTest, EmptyName)16{17const char *str = "#pragma\n";18const char *expected = "\n";1920using testing::_;21// No handlePragma calls.22EXPECT_CALL(mDirectiveHandler, handlePragma(_, _, _, false)).Times(0);23// No error or warning.24EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);2526preprocess(str, expected);27}2829TEST_F(PragmaTest, EmptyValue)30{31const char *str = "#pragma foo\n";32const char *expected = "\n";3334using testing::_;35EXPECT_CALL(mDirectiveHandler, handlePragma(pp::SourceLocation(0, 1), "foo", "", false));36// No error or warning.37EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);3839preprocess(str, expected);40}4142TEST_F(PragmaTest, NameValue)43{44const char *str = "#pragma foo(bar)\n";45const char *expected = "\n";4647using testing::_;48EXPECT_CALL(mDirectiveHandler, handlePragma(pp::SourceLocation(0, 1), "foo", "bar", false));49// No error or warning.50EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);5152preprocess(str, expected);53}5455TEST_F(PragmaTest, STDGL)56{57const char *str = "#pragma STDGL\n";58const char *expected = "\n";5960using testing::_;61EXPECT_CALL(mDirectiveHandler, handlePragma(_, _, _, _)).Times(0);62// No error or warning.63EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);6465preprocess(str, expected);66}6768TEST_F(PragmaTest, STDGLInvariantAll)69{70const char *str = "#pragma STDGL invariant(all)\n";71const char *expected = "\n";7273using testing::_;74EXPECT_CALL(mDirectiveHandler,75handlePragma(pp::SourceLocation(0, 1), "invariant", "all", true));76// No error or warning.77EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);7879preprocess(str, expected);80}8182TEST_F(PragmaTest, Comments)83{84const char *str =85"/*foo*/"86"#"87"/*foo*/"88"pragma"89"/*foo*/"90"foo"91"/*foo*/"92"("93"/*foo*/"94"bar"95"/*foo*/"96")"97"/*foo*/"98"//foo"99"\n";100const char *expected = "\n";101102using testing::_;103EXPECT_CALL(mDirectiveHandler, handlePragma(pp::SourceLocation(0, 1), "foo", "bar", false));104// No error or warning.105EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);106107preprocess(str, expected);108}109110TEST_F(PragmaTest, MissingNewline)111{112const char *str = "#pragma foo(bar)";113const char *expected = "";114115using testing::_;116// Pragma successfully parsed.117EXPECT_CALL(mDirectiveHandler, handlePragma(pp::SourceLocation(0, 1), "foo", "bar", false));118// Error reported about EOF.119EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_EOF_IN_DIRECTIVE, _, _));120121preprocess(str, expected);122}123124class InvalidPragmaTest : public PragmaTest, public testing::WithParamInterface<const char *>125{};126127TEST_P(InvalidPragmaTest, Identified)128{129const char *str = GetParam();130const char *expected = "\n";131132using testing::_;133// No handlePragma calls.134EXPECT_CALL(mDirectiveHandler, handlePragma(_, _, _, false)).Times(0);135// Unrecognized pragma warning.136EXPECT_CALL(mDiagnostics,137print(pp::Diagnostics::PP_UNRECOGNIZED_PRAGMA, pp::SourceLocation(0, 1), _));138139preprocess(str, expected);140}141142INSTANTIATE_TEST_SUITE_P(All,143InvalidPragmaTest,144testing::Values("#pragma 1\n", // Invalid name.145"#pragma foo()\n", // Missing value.146"#pragma foo bar)\n", // Missing left paren,147"#pragma foo(bar\n", // Missing right paren.148"#pragma foo bar\n", // Missing parens.149"#pragma foo(bar) baz\n")); // Extra tokens.150151} // namespace angle152153154