OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/escape.h" | 6 #include "tools/gn/escape.h" |
7 | 7 |
8 TEST(Escape, Ninja) { | 8 TEST(Escape, Ninja) { |
9 EscapeOptions opts; | 9 EscapeOptions opts; |
10 opts.mode = ESCAPE_NINJA; | 10 opts.mode = ESCAPE_NINJA; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 TEST(Escape, PosixCommand) { | 42 TEST(Escape, PosixCommand) { |
43 EscapeOptions opts; | 43 EscapeOptions opts; |
44 opts.mode = ESCAPE_NINJA_COMMAND; | 44 opts.mode = ESCAPE_NINJA_COMMAND; |
45 opts.platform = ESCAPE_PLATFORM_POSIX; | 45 opts.platform = ESCAPE_PLATFORM_POSIX; |
46 | 46 |
47 // : and $ ninja escaped with $. Then Shell-escape backslashes and quotes. | 47 // : and $ ninja escaped with $. Then Shell-escape backslashes and quotes. |
48 EXPECT_EQ("a$:\\$ \\\"\\$$\\\\b", EscapeString("a: \"$\\b", opts, nullptr)); | 48 EXPECT_EQ("a$:\\$ \\\"\\$$\\\\b", EscapeString("a: \"$\\b", opts, nullptr)); |
49 | 49 |
50 // Some more generic shell chars. | 50 // Some more generic shell chars. |
51 EXPECT_EQ("a_\\;\\<\\*b", EscapeString("a_;<*b", opts, nullptr)); | 51 EXPECT_EQ("a_\\;\\<\\*b", EscapeString("a_;<*b", opts, nullptr)); |
| 52 |
| 53 // Curly braces must be escaped to avoid brace expansion on systems using |
| 54 // bash as default shell.. |
| 55 EXPECT_EQ("\\{a,b\\}\\{c,d\\}", EscapeString("{a,b}{c,d}", opts, nullptr)); |
52 } | 56 } |
53 | 57 |
54 TEST(Escape, NinjaPreformatted) { | 58 TEST(Escape, NinjaPreformatted) { |
55 EscapeOptions opts; | 59 EscapeOptions opts; |
56 opts.mode = ESCAPE_NINJA_PREFORMATTED_COMMAND; | 60 opts.mode = ESCAPE_NINJA_PREFORMATTED_COMMAND; |
57 | 61 |
58 // Only $ is escaped. | 62 // Only $ is escaped. |
59 EXPECT_EQ("a: \"$$\\b<;", EscapeString("a: \"$\\b<;", opts, nullptr)); | 63 EXPECT_EQ("a: \"$$\\b<;", EscapeString("a: \"$\\b<;", opts, nullptr)); |
60 } | 64 } |
OLD | NEW |