Change next_proto member type.
[chromium-blink-merge.git] / tools / gn / value_unittest.cc
blob3fa990d4a28e915190c927f4fd36153f0a8c9b02
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.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/test_with_scope.h"
7 #include "tools/gn/value.h"
9 TEST(Value, ToString) {
10 Value strval(NULL, "hi\" $me\\you\\$\\\"");
11 EXPECT_EQ("hi\" $me\\you\\$\\\"", strval.ToString(false));
12 EXPECT_EQ("\"hi\\\" \\$me\\you\\\\\\$\\\\\\\"\"", strval.ToString(true));
14 // Void type.
15 EXPECT_EQ("<void>", Value().ToString(false));
17 // Test lists, bools, and ints.
18 Value listval(NULL, Value::LIST);
19 listval.list_value().push_back(Value(NULL, "hi\"me"));
20 listval.list_value().push_back(Value(NULL, true));
21 listval.list_value().push_back(Value(NULL, false));
22 listval.list_value().push_back(Value(NULL, static_cast<int64>(42)));
23 // Printing lists always causes embedded strings to be quoted (ignoring the
24 // quote flag), or else they wouldn't make much sense.
25 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(false));
26 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(true));
28 // Scopes.
29 TestWithScope setup;
30 Scope* scope = new Scope(setup.scope());
31 Value scopeval(NULL, scoped_ptr<Scope>(scope));
32 EXPECT_EQ("{ }", scopeval.ToString(false));
34 scope->SetValue("a", Value(NULL, static_cast<int64>(42)), NULL);
35 scope->SetValue("b", Value(NULL, "hello, world"), NULL);
36 EXPECT_EQ("{\n a = 42\n b = \"hello, world\"\n}", scopeval.ToString(false));