1//
2// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#include "gtest/gtest.h"
8
9#include "Token.h"
10
11TEST(TokenTest, DefaultConstructor)
12{
13    pp::Token token;
14    EXPECT_EQ(0, token.type);
15    EXPECT_EQ(0u, token.flags);
16    EXPECT_EQ(0, token.location.line);
17    EXPECT_EQ(0, token.location.file);
18    EXPECT_EQ("", token.text);
19}
20
21TEST(TokenTest, Assignment)
22{
23    pp::Token token;
24    token.type = 1;
25    token.flags = 1;
26    token.location.line = 1;
27    token.location.file = 1;
28    token.text.assign("foo");
29
30    token = pp::Token();
31    EXPECT_EQ(0, token.type);
32    EXPECT_EQ(0u, token.flags);
33    EXPECT_EQ(0, token.location.line);
34    EXPECT_EQ(0, token.location.file);
35    EXPECT_EQ("", token.text);
36}
37
38TEST(TokenTest, Equals)
39{
40    pp::Token token;
41    EXPECT_TRUE(token.equals(pp::Token()));
42
43    token.type = 1;
44    EXPECT_FALSE(token.equals(pp::Token()));
45    token.type = 0;
46
47    token.flags = 1;
48    EXPECT_FALSE(token.equals(pp::Token()));
49    token.flags = 0;
50
51    token.location.line = 1;
52    EXPECT_FALSE(token.equals(pp::Token()));
53    token.location.line = 0;
54
55    token.location.file = 1;
56    EXPECT_FALSE(token.equals(pp::Token()));
57    token.location.file = 0;
58
59    token.text.assign("foo");
60    EXPECT_FALSE(token.equals(pp::Token()));
61    token.text.clear();
62
63    EXPECT_TRUE(token.equals(pp::Token()));
64}
65
66TEST(TokenTest, HasLeadingSpace)
67{
68    pp::Token token;
69    EXPECT_FALSE(token.hasLeadingSpace());
70    token.setHasLeadingSpace(true);
71    EXPECT_TRUE(token.hasLeadingSpace());
72    token.setHasLeadingSpace(false);
73    EXPECT_FALSE(token.hasLeadingSpace());
74}
75
76TEST(TokenTest, Write)
77{
78    pp::Token token;
79    token.text.assign("foo");
80    std::stringstream out1;
81    out1 << token;
82    EXPECT_TRUE(out1.good());
83    EXPECT_EQ("foo", out1.str());
84
85    token.setHasLeadingSpace(true);
86    std::stringstream out2;
87    out2 << token;
88    EXPECT_TRUE(out2.good());
89    EXPECT_EQ(" foo", out2.str());
90}
91