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 {
|
|
|
|
|
2019-05-23 17:47:55 +00:00
|
|
|
TorqueCompilerResult TestCompileTorque(const std::string& source) {
|
2019-05-02 07:54:08 +00:00
|
|
|
TorqueCompilerOptions options;
|
|
|
|
options.output_directory = "";
|
|
|
|
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) {
|
2019-05-23 17:47:55 +00:00
|
|
|
std::string source = R"(
|
|
|
|
type void;
|
|
|
|
type never;
|
|
|
|
|
2019-04-24 13:25:27 +00:00
|
|
|
type foo generates 'TNode<Foo>';
|
2019-05-23 17:47:55 +00:00
|
|
|
)";
|
2019-04-24 13:25:27 +00:00
|
|
|
|
2019-05-23 17:47:55 +00:00
|
|
|
const TorqueCompilerResult result = TestCompileTorque(source);
|
2019-05-02 07:54:08 +00:00
|
|
|
|
2019-05-23 17:47:55 +00:00
|
|
|
ASSERT_EQ(result.messages.size(), static_cast<size_t>(1));
|
|
|
|
EXPECT_THAT(result.messages[0].message, HasSubstr("\"foo\""));
|
2019-05-02 07:54:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:47:55 +00:00
|
|
|
TEST(Torque, StructNamingConventionLintError) {
|
|
|
|
const std::string source = R"(
|
|
|
|
type void;
|
|
|
|
type never;
|
2019-04-24 13:25:27 +00:00
|
|
|
|
2019-05-23 17:47:55 +00:00
|
|
|
struct foo {}
|
|
|
|
)";
|
2019-05-23 09:06:15 +00:00
|
|
|
|
2019-05-23 17:47:55 +00:00
|
|
|
const TorqueCompilerResult result = TestCompileTorque(source);
|
2019-04-24 13:25:27 +00:00
|
|
|
|
2019-05-23 17:47:55 +00:00
|
|
|
ASSERT_EQ(result.messages.size(), static_cast<size_t>(1));
|
|
|
|
EXPECT_THAT(result.messages[0].message, HasSubstr("\"foo\""));
|
2019-04-24 13:25:27 +00:00
|
|
|
}
|
|
|
|
|
2018-10-15 22:31:24 +00:00
|
|
|
} // namespace torque
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|