| Index: tools/gn/input_conversion_unittest.cc
|
| diff --git a/tools/gn/input_conversion_unittest.cc b/tools/gn/input_conversion_unittest.cc
|
| index 0e355753addd4e010d7e9d68afae967b34543dfd..db012876b77e965974d9f499210931cd81a3ecbe 100644
|
| --- a/tools/gn/input_conversion_unittest.cc
|
| +++ b/tools/gn/input_conversion_unittest.cc
|
| @@ -5,9 +5,25 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "tools/gn/err.h"
|
| #include "tools/gn/input_conversion.h"
|
| +#include "tools/gn/input_file.h"
|
| +#include "tools/gn/parse_tree.h"
|
| +#include "tools/gn/scheduler.h"
|
| #include "tools/gn/value.h"
|
|
|
| -TEST(InputConversion, String) {
|
| +namespace {
|
| +
|
| +// InputConversion needs a global scheduler object.
|
| +class InputConversionTest : public testing::Test {
|
| + public:
|
| + InputConversionTest() {}
|
| +
|
| + private:
|
| + Scheduler scheduler_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(InputConversionTest, String) {
|
| Err err;
|
| std::string input("\nfoo bar \n");
|
| Value result = ConvertInputToValue(input, NULL, Value(NULL, "string"), &err);
|
| @@ -22,7 +38,7 @@ TEST(InputConversion, String) {
|
| EXPECT_EQ("foo bar", result.string_value());
|
| }
|
|
|
| -TEST(InputConversion, ListLines) {
|
| +TEST_F(InputConversionTest, ListLines) {
|
| Err err;
|
| std::string input("\nfoo\nbar \n\n");
|
| Value result = ConvertInputToValue(input, NULL, Value(NULL, "list lines"),
|
| @@ -45,7 +61,7 @@ TEST(InputConversion, ListLines) {
|
| EXPECT_EQ("bar", result.list_value()[1].string_value());
|
| }
|
|
|
| -TEST(InputConversion, ValueString) {
|
| +TEST_F(InputConversionTest, ValueString) {
|
| Err err;
|
| std::string input("\"str\"");
|
| Value result = ConvertInputToValue(input, NULL, Value(NULL, "value"), &err);
|
| @@ -54,7 +70,7 @@ TEST(InputConversion, ValueString) {
|
| EXPECT_EQ("str", result.string_value());
|
| }
|
|
|
| -TEST(InputConversion, ValueInt) {
|
| +TEST_F(InputConversionTest, ValueInt) {
|
| Err err;
|
| std::string input("\n\n 6 \n ");
|
| Value result = ConvertInputToValue(input, NULL, Value(NULL, "value"), &err);
|
| @@ -63,7 +79,7 @@ TEST(InputConversion, ValueInt) {
|
| EXPECT_EQ(6, result.int_value());
|
| }
|
|
|
| -TEST(InputConversion, ValueList) {
|
| +TEST_F(InputConversionTest, ValueList) {
|
| Err err;
|
| std::string input("\n [ \"a\", 5]");
|
| Value result = ConvertInputToValue(input, NULL, Value(NULL, "value"), &err);
|
| @@ -74,14 +90,38 @@ TEST(InputConversion, ValueList) {
|
| EXPECT_EQ(5, result.list_value()[1].int_value());
|
| }
|
|
|
| -TEST(InputConversion, ValueEmpty) {
|
| +TEST_F(InputConversionTest, ValueDict) {
|
| + Err err;
|
| + std::string input("\n a = 5 b = \"foo\" c = a + 2");
|
| + Value result = ConvertInputToValue(input, NULL, Value(NULL, "scope"), &err);
|
| + EXPECT_FALSE(err.has_error());
|
| + ASSERT_EQ(Value::DICT, result.type());
|
| + ASSERT_EQ(3u, result.dict_value().size());
|
| + EXPECT_EQ(5, result.dict_value()["a"].int_value());
|
| + EXPECT_EQ("foo", result.dict_value()["b"].string_value());
|
| + EXPECT_EQ(7, result.dict_value()["c"].int_value());
|
| +
|
| + // Tests that when we get Values out of the input conversion, the resulting
|
| + // values have an origin set to something corresponding to the input.
|
| + Value a = result.dict_value()["a"];
|
| + const ParseNode* a_origin = a.origin();
|
| + ASSERT_TRUE(a_origin);
|
| + LocationRange a_range = a_origin->GetRange();
|
| + EXPECT_EQ(2, a_range.begin().line_number());
|
| + EXPECT_EQ(6, a_range.begin().char_offset());
|
| +
|
| + const InputFile* a_file = a_range.begin().file();
|
| + EXPECT_EQ(input, a_file->contents());
|
| +}
|
| +
|
| +TEST_F(InputConversionTest, ValueEmpty) {
|
| Err err;
|
| Value result = ConvertInputToValue("", NULL, Value(NULL, "value"), &err);
|
| EXPECT_FALSE(err.has_error());
|
| EXPECT_EQ(Value::NONE, result.type());
|
| }
|
|
|
| -TEST(InputConversion, ValueError) {
|
| +TEST_F(InputConversionTest, ValueError) {
|
| Err err;
|
| std::string input("\n [ \"a\", 5\nfoo bar");
|
| Value result = ConvertInputToValue(input, NULL, Value(NULL, "value"), &err);
|
| @@ -100,7 +140,7 @@ TEST(InputConversion, ValueError) {
|
|
|
| // Passing none or the empty string for input conversion should ignore the
|
| // result.
|
| -TEST(InputConversion, Ignore) {
|
| +TEST_F(InputConversionTest, Ignore) {
|
| Err err;
|
| Value result = ConvertInputToValue("foo", NULL, Value(), &err);
|
| EXPECT_FALSE(err.has_error());
|
|
|