Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / gn / value_unittest.cc
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/value.h"
7
8 TEST(Value, ToString) {
9   Value strval(NULL, "hi\" $me\\you\\$\\\"");
10   EXPECT_EQ("hi\" $me\\you\\$\\\"", strval.ToString(false));
11   EXPECT_EQ("\"hi\\\" \\$me\\you\\\\\\$\\\\\\\"\"", strval.ToString(true));
12
13   // Test lists, bools, and ints.
14   Value listval(NULL, Value::LIST);
15   listval.list_value().push_back(Value(NULL, "hi\"me"));
16   listval.list_value().push_back(Value(NULL, true));
17   listval.list_value().push_back(Value(NULL, false));
18   listval.list_value().push_back(Value(NULL, static_cast<int64>(42)));
19   // Printing lists always causes embedded strings to be quoted (ignoring the
20   // quote flag), or else they wouldn't make much sense.
21   EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(false));
22   EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(true));
23
24   // Some weird types, we may want to enhance or change printing of these, but
25   // here we test the current behavior.
26   EXPECT_EQ("<void>", Value().ToString(false));
27   EXPECT_EQ("<scope>", Value(NULL, Value::SCOPE).ToString(false));
28 }
29