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/err.h" | 6 #include "tools/gn/err.h" |
7 #include "tools/gn/input_conversion.h" | 7 #include "tools/gn/input_conversion.h" |
8 #include "tools/gn/input_file.h" | 8 #include "tools/gn/input_file.h" |
9 #include "tools/gn/parse_tree.h" | 9 #include "tools/gn/parse_tree.h" |
10 #include "tools/gn/scheduler.h" | 10 #include "tools/gn/scheduler.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 TEST_F(InputConversionTest, ValueEmpty) { | 135 TEST_F(InputConversionTest, ValueEmpty) { |
136 Err err; | 136 Err err; |
137 Value result = ConvertInputToValue(settings(), "", nullptr, | 137 Value result = ConvertInputToValue(settings(), "", nullptr, |
138 Value(nullptr, "value"), &err); | 138 Value(nullptr, "value"), &err); |
139 EXPECT_FALSE(err.has_error()); | 139 EXPECT_FALSE(err.has_error()); |
140 EXPECT_EQ(Value::NONE, result.type()); | 140 EXPECT_EQ(Value::NONE, result.type()); |
141 } | 141 } |
142 | 142 |
143 TEST_F(InputConversionTest, ValueError) { | 143 TEST_F(InputConversionTest, ValueError) { |
144 Err err; | 144 static const char* const kTests[] = { |
145 std::string input("\n [ \"a\", 5\nfoo bar"); | 145 "\n [ \"a\", 5\nfoo bar", |
146 Value result = ConvertInputToValue(settings(), input, nullptr, | |
147 Value(nullptr, "value"), &err); | |
148 EXPECT_TRUE(err.has_error()); | |
149 | 146 |
150 // Blocks not allowed. | 147 // Blocks not allowed. |
151 input = "{ foo = 5 }"; | 148 "{ foo = 5 }", |
152 result = ConvertInputToValue(settings(), input, nullptr, | |
153 Value(nullptr, "value"), &err); | |
154 EXPECT_TRUE(err.has_error()); | |
155 | 149 |
156 // Function calls not allowed. | 150 // Function calls not allowed. |
157 input = "print(5)"; | 151 "print(5)", |
158 result = ConvertInputToValue(settings(), input, nullptr, | 152 |
159 Value(nullptr, "value"), &err); | 153 // Trailing junk not allowed. |
160 EXPECT_TRUE(err.has_error()); | 154 "233105-1", |
| 155 |
| 156 // Non-literals hidden in arrays are not allowed. |
| 157 "[233105 - 1]", |
| 158 "[rebase_path(\"//\")]", |
| 159 }; |
| 160 |
| 161 for (auto test : kTests) { |
| 162 Err err; |
| 163 std::string input(test); |
| 164 Value result = ConvertInputToValue(settings(), input, nullptr, |
| 165 Value(nullptr, "value"), &err); |
| 166 EXPECT_TRUE(err.has_error()) << test; |
| 167 } |
161 } | 168 } |
162 | 169 |
163 // Passing none or the empty string for input conversion should ignore the | 170 // Passing none or the empty string for input conversion should ignore the |
164 // result. | 171 // result. |
165 TEST_F(InputConversionTest, Ignore) { | 172 TEST_F(InputConversionTest, Ignore) { |
166 Err err; | 173 Err err; |
167 Value result = ConvertInputToValue(settings(), "foo", nullptr, Value(), &err); | 174 Value result = ConvertInputToValue(settings(), "foo", nullptr, Value(), &err); |
168 EXPECT_FALSE(err.has_error()); | 175 EXPECT_FALSE(err.has_error()); |
169 EXPECT_EQ(Value::NONE, result.type()); | 176 EXPECT_EQ(Value::NONE, result.type()); |
170 | 177 |
171 result = | 178 result = |
172 ConvertInputToValue(settings(), "foo", nullptr, Value(nullptr, ""), &err); | 179 ConvertInputToValue(settings(), "foo", nullptr, Value(nullptr, ""), &err); |
173 EXPECT_FALSE(err.has_error()); | 180 EXPECT_FALSE(err.has_error()); |
174 EXPECT_EQ(Value::NONE, result.type()); | 181 EXPECT_EQ(Value::NONE, result.type()); |
175 } | 182 } |
OLD | NEW |