1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/err.h"
#include "tools/gn/substitution_pattern.h"
TEST(SubstitutionPattern, ParseLiteral) {
SubstitutionPattern pattern;
Err err;
EXPECT_TRUE(pattern.Parse("This is a literal", NULL, &err));
EXPECT_FALSE(err.has_error());
ASSERT_EQ(1u, pattern.ranges().size());
EXPECT_EQ(SUBSTITUTION_LITERAL, pattern.ranges()[0].type);
EXPECT_EQ("This is a literal", pattern.ranges()[0].literal);
}
TEST(SubstitutionPattern, ParseComplex) {
SubstitutionPattern pattern;
Err err;
EXPECT_TRUE(pattern.Parse(
"AA{{source}}{{source_name_part}}BB{{source_file_part}}", NULL, &err));
EXPECT_FALSE(err.has_error());
ASSERT_EQ(5u, pattern.ranges().size());
EXPECT_EQ(SUBSTITUTION_LITERAL, pattern.ranges()[0].type);
EXPECT_EQ("AA", pattern.ranges()[0].literal);
EXPECT_EQ(SUBSTITUTION_SOURCE, pattern.ranges()[1].type);
EXPECT_EQ(SUBSTITUTION_SOURCE_NAME_PART, pattern.ranges()[2].type);
EXPECT_EQ(SUBSTITUTION_LITERAL, pattern.ranges()[3].type);
EXPECT_EQ("BB", pattern.ranges()[3].literal);
EXPECT_EQ(SUBSTITUTION_SOURCE_FILE_PART, pattern.ranges()[4].type);
}
TEST(SubstitutionPattern, ParseErrors) {
SubstitutionPattern pattern;
Err err;
EXPECT_FALSE(pattern.Parse("AA{{source", NULL, &err));
EXPECT_TRUE(err.has_error());
err = Err();
EXPECT_FALSE(pattern.Parse("{{source_of_evil}}", NULL, &err));
EXPECT_TRUE(err.has_error());
err = Err();
EXPECT_FALSE(pattern.Parse("{{source{{source}}", NULL, &err));
EXPECT_TRUE(err.has_error());
}
|