Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: tools/gn/value_unittest.cc

Issue 1043383002: Revert of Revert of tools/gn: fix escaping of backslashes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/value.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/test_with_scope.h" 6 #include "tools/gn/test_with_scope.h"
7 #include "tools/gn/value.h" 7 #include "tools/gn/value.h"
8 8
9 TEST(Value, ToString) { 9 TEST(Value, ToString) {
10 Value strval(nullptr, "hi\" $me\\you\\$\\\""); 10 Value strval(nullptr, "hi\" $me\\you\\$\\\"");
11 EXPECT_EQ("hi\" $me\\you\\$\\\"", strval.ToString(false)); 11 EXPECT_EQ("hi\" $me\\you\\$\\\"", strval.ToString(false));
12 EXPECT_EQ("\"hi\\\" \\$me\\you\\\\\\$\\\\\\\"\"", strval.ToString(true)); 12 EXPECT_EQ("\"hi\\\" \\$me\\you\\\\\\$\\\\\\\"\"", strval.ToString(true));
13 13
14 // crbug.com/470217
15 Value strval2(nullptr, "\\foo\\\\bar\\");
16 EXPECT_EQ("\"\\foo\\\\\\bar\\\\\"", strval2.ToString(true));
17
14 // Void type. 18 // Void type.
15 EXPECT_EQ("<void>", Value().ToString(false)); 19 EXPECT_EQ("<void>", Value().ToString(false));
16 20
17 // Test lists, bools, and ints. 21 // Test lists, bools, and ints.
18 Value listval(nullptr, Value::LIST); 22 Value listval(nullptr, Value::LIST);
19 listval.list_value().push_back(Value(nullptr, "hi\"me")); 23 listval.list_value().push_back(Value(nullptr, "hi\"me"));
20 listval.list_value().push_back(Value(nullptr, true)); 24 listval.list_value().push_back(Value(nullptr, true));
21 listval.list_value().push_back(Value(nullptr, false)); 25 listval.list_value().push_back(Value(nullptr, false));
22 listval.list_value().push_back(Value(nullptr, static_cast<int64>(42))); 26 listval.list_value().push_back(Value(nullptr, static_cast<int64>(42)));
23 // Printing lists always causes embedded strings to be quoted (ignoring the 27 // Printing lists always causes embedded strings to be quoted (ignoring the
24 // quote flag), or else they wouldn't make much sense. 28 // quote flag), or else they wouldn't make much sense.
25 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(false)); 29 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(false));
26 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(true)); 30 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(true));
27 31
28 // Scopes. 32 // Scopes.
29 TestWithScope setup; 33 TestWithScope setup;
30 Scope* scope = new Scope(setup.scope()); 34 Scope* scope = new Scope(setup.scope());
31 Value scopeval(nullptr, scoped_ptr<Scope>(scope)); 35 Value scopeval(nullptr, scoped_ptr<Scope>(scope));
32 EXPECT_EQ("{ }", scopeval.ToString(false)); 36 EXPECT_EQ("{ }", scopeval.ToString(false));
33 37
34 scope->SetValue("a", Value(nullptr, static_cast<int64>(42)), nullptr); 38 scope->SetValue("a", Value(nullptr, static_cast<int64>(42)), nullptr);
35 scope->SetValue("b", Value(nullptr, "hello, world"), nullptr); 39 scope->SetValue("b", Value(nullptr, "hello, world"), nullptr);
36 EXPECT_EQ("{\n a = 42\n b = \"hello, world\"\n}", scopeval.ToString(false)); 40 EXPECT_EQ("{\n a = 42\n b = \"hello, world\"\n}", scopeval.ToString(false));
37 } 41 }
38
OLDNEW
« no previous file with comments | « tools/gn/value.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698