Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / tools / gn / substitution_pattern_unittest.cc
blob9f606af0e7ba61f666c641f537e4e757d27bb04b
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/err.h"
7 #include "tools/gn/substitution_pattern.h"
9 TEST(SubstitutionPattern, ParseLiteral) {
10 SubstitutionPattern pattern;
11 Err err;
12 EXPECT_TRUE(pattern.Parse("This is a literal", nullptr, &err));
13 EXPECT_FALSE(err.has_error());
14 ASSERT_EQ(1u, pattern.ranges().size());
15 EXPECT_EQ(SUBSTITUTION_LITERAL, pattern.ranges()[0].type);
16 EXPECT_EQ("This is a literal", pattern.ranges()[0].literal);
19 TEST(SubstitutionPattern, ParseComplex) {
20 SubstitutionPattern pattern;
21 Err err;
22 EXPECT_TRUE(pattern.Parse(
23 "AA{{source}}{{source_name_part}}BB{{source_file_part}}", nullptr, &err));
24 EXPECT_FALSE(err.has_error());
25 ASSERT_EQ(5u, pattern.ranges().size());
27 EXPECT_EQ(SUBSTITUTION_LITERAL, pattern.ranges()[0].type);
28 EXPECT_EQ("AA", pattern.ranges()[0].literal);
29 EXPECT_EQ(SUBSTITUTION_SOURCE, pattern.ranges()[1].type);
30 EXPECT_EQ(SUBSTITUTION_SOURCE_NAME_PART, pattern.ranges()[2].type);
31 EXPECT_EQ(SUBSTITUTION_LITERAL, pattern.ranges()[3].type);
32 EXPECT_EQ("BB", pattern.ranges()[3].literal);
33 EXPECT_EQ(SUBSTITUTION_SOURCE_FILE_PART, pattern.ranges()[4].type);
36 TEST(SubstitutionPattern, ParseErrors) {
37 SubstitutionPattern pattern;
38 Err err;
39 EXPECT_FALSE(pattern.Parse("AA{{source", nullptr, &err));
40 EXPECT_TRUE(err.has_error());
42 err = Err();
43 EXPECT_FALSE(pattern.Parse("{{source_of_evil}}", nullptr, &err));
44 EXPECT_TRUE(err.has_error());
46 err = Err();
47 EXPECT_FALSE(pattern.Parse("{{source{{source}}", nullptr, &err));
48 EXPECT_TRUE(err.has_error());