| 14 | namespace { |
| 15 | |
| 16 | TEST(ErrorMessageTest, BadSubscriptErrorMessage) { |
| 17 | const char *example_yaml = "first:\n" |
| 18 | " second: 1\n" |
| 19 | " third: 2\n"; |
| 20 | |
| 21 | Node doc = Load(example_yaml); |
| 22 | |
| 23 | // Test that printable key is part of error message |
| 24 | EXPECT_THROW_EXCEPTION(YAML::BadSubscript, doc["first"]["second"]["fourth"], |
| 25 | "operator[] call on a scalar (key: \"fourth\")"); |
| 26 | |
| 27 | EXPECT_THROW_EXCEPTION(YAML::BadSubscript, doc["first"]["second"][37], |
| 28 | "operator[] call on a scalar (key: \"37\")"); |
| 29 | |
| 30 | |
| 31 | // Non-printable key is not included in error message |
| 32 | EXPECT_THROW_EXCEPTION(YAML::BadSubscript, |
| 33 | doc["first"]["second"][std::vector<int>()], |
| 34 | "operator[] call on a scalar"); |
| 35 | |
| 36 | EXPECT_THROW_EXCEPTION(YAML::BadSubscript, doc["first"]["second"][Node()], |
| 37 | "operator[] call on a scalar"); |
| 38 | } |
| 39 | |
| 40 | TEST(ErrorMessageTest, Ex9_1_InvalidNodeErrorMessage) { |
| 41 | const char *example_yaml = "first:\n" |