Path: blob/main_old/src/tests/preprocessor_tests/token_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 "gtest/gtest.h"78#include "compiler/preprocessor/Token.h"910namespace angle11{1213TEST(TokenTest, DefaultConstructor)14{15pp::Token token;16EXPECT_EQ(0, token.type);17EXPECT_EQ(0u, token.flags);18EXPECT_EQ(0, token.location.line);19EXPECT_EQ(0, token.location.file);20EXPECT_EQ("", token.text);21}2223TEST(TokenTest, Assignment)24{25pp::Token token;26token.type = 1;27token.flags = 1;28token.location.line = 1;29token.location.file = 1;30token.text.assign("foo");3132token = pp::Token();33EXPECT_EQ(0, token.type);34EXPECT_EQ(0u, token.flags);35EXPECT_EQ(0, token.location.line);36EXPECT_EQ(0, token.location.file);37EXPECT_EQ("", token.text);38}3940TEST(TokenTest, Equals)41{42pp::Token token;43EXPECT_TRUE(token.equals(pp::Token()));4445token.type = 1;46EXPECT_FALSE(token.equals(pp::Token()));47token.type = 0;4849token.flags = 1;50EXPECT_FALSE(token.equals(pp::Token()));51token.flags = 0;5253token.location.line = 1;54EXPECT_FALSE(token.equals(pp::Token()));55token.location.line = 0;5657token.location.file = 1;58EXPECT_FALSE(token.equals(pp::Token()));59token.location.file = 0;6061token.text.assign("foo");62EXPECT_FALSE(token.equals(pp::Token()));63token.text.clear();6465EXPECT_TRUE(token.equals(pp::Token()));66}6768TEST(TokenTest, HasLeadingSpace)69{70pp::Token token;71EXPECT_FALSE(token.hasLeadingSpace());72token.setHasLeadingSpace(true);73EXPECT_TRUE(token.hasLeadingSpace());74token.setHasLeadingSpace(false);75EXPECT_FALSE(token.hasLeadingSpace());76}7778TEST(TokenTest, Write)79{80pp::Token token;81token.text.assign("foo");82std::stringstream out1;83out1 << token;84EXPECT_TRUE(out1.good());85EXPECT_EQ("foo", out1.str());8687token.setHasLeadingSpace(true);88std::stringstream out2;89out2 << token;90EXPECT_TRUE(out2.good());91EXPECT_EQ(" foo", out2.str());92}9394} // namespace angle959697