yaml_test_helpers_test.cpp 904 B

1234567891011121314151617181920212223242526272829303132
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/testing/yaml_test_helpers.h"
  5. #include <gmock/gmock.h>
  6. #include <gtest/gtest.h>
  7. namespace Carbon::Testing {
  8. namespace {
  9. using ::testing::_;
  10. using ::testing::ElementsAre;
  11. using ::testing::Not;
  12. TEST(YamlTestHelpersTest, ValidYaml) {
  13. EXPECT_THAT(
  14. Yaml::Value::FromText("[foo, bar]"),
  15. Yaml::IsYaml(ElementsAre(Yaml::Sequence(ElementsAre("foo", "bar")))));
  16. }
  17. TEST(YamlTestHelpersTest, InvalidYaml) {
  18. auto result = Yaml::Value::FromText("- foo\nbar");
  19. // Make sure we've constructed invalid YAML.
  20. EXPECT_FALSE(result.ok());
  21. // Make sure the matcher detects the invalid YAML.
  22. EXPECT_THAT(result, Not(Yaml::IsYaml(_)));
  23. }
  24. } // namespace
  25. } // namespace Carbon::Testing