- add sources.
[platform/framework/web/crosswalk.git] / src / tools / gn / escape_unittest.cc
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
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/escape.h"
7
8 TEST(Escape, UsedQuotes) {
9   EscapeOptions shell_options;
10   shell_options.mode = ESCAPE_SHELL;
11
12   EscapeOptions ninja_options;
13   ninja_options.mode = ESCAPE_NINJA;
14
15   EscapeOptions ninja_shell_options;
16   ninja_shell_options.mode = ESCAPE_NINJA_SHELL;
17
18   // Shell escaping with quoting inhibited.
19   bool used_quotes = false;
20   shell_options.inhibit_quoting = true;
21   EXPECT_EQ("foo bar", EscapeString("foo bar", shell_options, &used_quotes));
22   EXPECT_TRUE(used_quotes);
23
24   // Shell escaping with regular quoting.
25   used_quotes = false;
26   shell_options.inhibit_quoting = false;
27   EXPECT_EQ("\"foo bar\"",
28             EscapeString("foo bar", shell_options, &used_quotes));
29   EXPECT_TRUE(used_quotes);
30
31   // Ninja shell escaping should be the same.
32   used_quotes = false;
33   EXPECT_EQ("\"foo$ bar\"",
34             EscapeString("foo bar", ninja_shell_options, &used_quotes));
35   EXPECT_TRUE(used_quotes);
36
37   // Ninja escaping shouldn't use quoting.
38   used_quotes = false;
39   EXPECT_EQ("foo$ bar", EscapeString("foo bar", ninja_options, &used_quotes));
40   EXPECT_FALSE(used_quotes);
41
42   // Used quotes not reset if it's already true.
43   used_quotes = true;
44   EscapeString("foo", ninja_options, &used_quotes);
45   EXPECT_TRUE(used_quotes);
46 }