| OLD | NEW |
| 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 <stdint.h> |
| 6 |
| 5 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "tools/gn/test_with_scope.h" | 8 #include "tools/gn/test_with_scope.h" |
| 7 #include "tools/gn/value.h" | 9 #include "tools/gn/value.h" |
| 8 | 10 |
| 9 TEST(Value, ToString) { | 11 TEST(Value, ToString) { |
| 10 Value strval(nullptr, "hi\" $me\\you\\$\\\""); | 12 Value strval(nullptr, "hi\" $me\\you\\$\\\""); |
| 11 EXPECT_EQ("hi\" $me\\you\\$\\\"", strval.ToString(false)); | 13 EXPECT_EQ("hi\" $me\\you\\$\\\"", strval.ToString(false)); |
| 12 EXPECT_EQ("\"hi\\\" \\$me\\you\\\\\\$\\\\\\\"\"", strval.ToString(true)); | 14 EXPECT_EQ("\"hi\\\" \\$me\\you\\\\\\$\\\\\\\"\"", strval.ToString(true)); |
| 13 | 15 |
| 14 // crbug.com/470217 | 16 // crbug.com/470217 |
| 15 Value strval2(nullptr, "\\foo\\\\bar\\"); | 17 Value strval2(nullptr, "\\foo\\\\bar\\"); |
| 16 EXPECT_EQ("\"\\foo\\\\\\bar\\\\\"", strval2.ToString(true)); | 18 EXPECT_EQ("\"\\foo\\\\\\bar\\\\\"", strval2.ToString(true)); |
| 17 | 19 |
| 18 // Void type. | 20 // Void type. |
| 19 EXPECT_EQ("<void>", Value().ToString(false)); | 21 EXPECT_EQ("<void>", Value().ToString(false)); |
| 20 | 22 |
| 21 // Test lists, bools, and ints. | 23 // Test lists, bools, and ints. |
| 22 Value listval(nullptr, Value::LIST); | 24 Value listval(nullptr, Value::LIST); |
| 23 listval.list_value().push_back(Value(nullptr, "hi\"me")); | 25 listval.list_value().push_back(Value(nullptr, "hi\"me")); |
| 24 listval.list_value().push_back(Value(nullptr, true)); | 26 listval.list_value().push_back(Value(nullptr, true)); |
| 25 listval.list_value().push_back(Value(nullptr, false)); | 27 listval.list_value().push_back(Value(nullptr, false)); |
| 26 listval.list_value().push_back(Value(nullptr, static_cast<int64>(42))); | 28 listval.list_value().push_back(Value(nullptr, static_cast<int64_t>(42))); |
| 27 // Printing lists always causes embedded strings to be quoted (ignoring the | 29 // Printing lists always causes embedded strings to be quoted (ignoring the |
| 28 // quote flag), or else they wouldn't make much sense. | 30 // quote flag), or else they wouldn't make much sense. |
| 29 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(false)); | 31 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(false)); |
| 30 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(true)); | 32 EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(true)); |
| 31 | 33 |
| 32 // Scopes. | 34 // Scopes. |
| 33 TestWithScope setup; | 35 TestWithScope setup; |
| 34 Scope* scope = new Scope(setup.scope()); | 36 Scope* scope = new Scope(setup.scope()); |
| 35 Value scopeval(nullptr, scoped_ptr<Scope>(scope)); | 37 Value scopeval(nullptr, scoped_ptr<Scope>(scope)); |
| 36 EXPECT_EQ("{ }", scopeval.ToString(false)); | 38 EXPECT_EQ("{ }", scopeval.ToString(false)); |
| 37 | 39 |
| 38 scope->SetValue("a", Value(nullptr, static_cast<int64>(42)), nullptr); | 40 scope->SetValue("a", Value(nullptr, static_cast<int64_t>(42)), nullptr); |
| 39 scope->SetValue("b", Value(nullptr, "hello, world"), nullptr); | 41 scope->SetValue("b", Value(nullptr, "hello, world"), nullptr); |
| 40 EXPECT_EQ("{\n a = 42\n b = \"hello, world\"\n}", scopeval.ToString(false)); | 42 EXPECT_EQ("{\n a = 42\n b = \"hello, world\"\n}", scopeval.ToString(false)); |
| 41 } | 43 } |
| OLD | NEW |