2018-10-15 22:31:24 +00:00
|
|
|
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-04-24 13:25:27 +00:00
|
|
|
#include "src/torque/torque-compiler.h"
|
2018-10-15 22:31:24 +00:00
|
|
|
#include "src/torque/utils.h"
|
|
|
|
#include "test/unittests/test-utils.h"
|
2019-04-24 13:25:27 +00:00
|
|
|
#include "testing/gmock-support.h"
|
2018-10-15 22:31:24 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace torque {
|
|
|
|
|
2019-05-02 07:54:08 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
TorqueCompilerResult TestCompileTorque(const std::string& source) {
|
|
|
|
TorqueCompilerOptions options;
|
|
|
|
options.output_directory = "";
|
|
|
|
options.verbose = false;
|
|
|
|
options.collect_language_server_data = false;
|
2019-05-08 08:26:07 +00:00
|
|
|
options.force_assert_statements = false;
|
2019-05-02 07:54:08 +00:00
|
|
|
|
|
|
|
return CompileTorque(source, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-10-15 22:31:24 +00:00
|
|
|
TEST(Torque, StackDeleteRange) {
|
|
|
|
Stack<int> stack = {1, 2, 3, 4, 5, 6, 7};
|
|
|
|
stack.DeleteRange(StackRange{BottomOffset{2}, BottomOffset{4}});
|
|
|
|
Stack<int> result = {1, 2, 5, 6, 7};
|
|
|
|
ASSERT_TRUE(stack == result);
|
|
|
|
}
|
|
|
|
|
2019-04-24 13:25:27 +00:00
|
|
|
using ::testing::HasSubstr;
|
|
|
|
TEST(Torque, TypeNamingConventionLintError) {
|
|
|
|
std::string source = R"(
|
|
|
|
type void;
|
|
|
|
type never;
|
|
|
|
|
|
|
|
type foo generates 'TNode<Foo>';
|
|
|
|
)";
|
|
|
|
|
2019-05-02 07:54:08 +00:00
|
|
|
const TorqueCompilerResult result = TestCompileTorque(source);
|
|
|
|
|
|
|
|
ASSERT_EQ(result.lint_errors.size(), static_cast<size_t>(1));
|
|
|
|
EXPECT_THAT(result.lint_errors[0].message, HasSubstr("\"foo\""));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Torque, StructNamingConventionLintError) {
|
|
|
|
const std::string source = R"(
|
|
|
|
type void;
|
|
|
|
type never;
|
|
|
|
|
|
|
|
struct foo {}
|
|
|
|
)";
|
2019-04-24 13:25:27 +00:00
|
|
|
|
2019-05-02 07:54:08 +00:00
|
|
|
const TorqueCompilerResult result = TestCompileTorque(source);
|
2019-04-24 13:25:27 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(result.lint_errors.size(), static_cast<size_t>(1));
|
|
|
|
EXPECT_THAT(result.lint_errors[0].message, HasSubstr("\"foo\""));
|
|
|
|
}
|
|
|
|
|
2018-10-15 22:31:24 +00:00
|
|
|
} // namespace torque
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|