mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:34:41 +01:00
Rename executable_semantics to explorer (#1188)
Change generated with: ``` #!/usr/bin/bash -eux # Helper script for renaming pending work. # Run from the repo root. # Rename executable_semantics in code. sed -i 's/executable_semantics/explorer/g' \ $(git grep -l 'executable_semantics' . | grep -v proposals) sed -i 's/executable semantics/explorer/g' \ $(git grep -l 'executable semantics' . | grep -v proposals) sed -i 's/Executable semantics/Explorer/g' \ $(git grep -l 'Executable semantics' . | grep -v proposals) sed -i 's/Executable Semantics/Explorer/g' \ $(git grep -l 'Executable Semantics' . | grep -v proposals) sed -i 's/EXECUTABLE_SEMANTICS/EXPLORER/g' \ $(git grep -l 'EXECUTABLE_SEMANTICS' . | grep -v proposals) sed -i 's/ExecutableSemantics/Explorer/g' \ $(git grep -l 'ExecutableSemantics' . | grep -v proposals) sed -i 's/executable-semantics/explorer/g' \ $(git grep -l 'executable-semantics' . | grep -v proposals) # This is only needed for the initial move. mv executable_semantics explorer mv explorer/fuzzing/executable_semantics_fuzzer.cpp explorer/fuzzing/explorer_fuzzer.cpp ``` Verified with `bazel test ...`
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "explorer/ast/expression.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "explorer/ast/paren_contents.h"
|
||||
#include "explorer/common/arena.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
|
||||
namespace Carbon::Testing {
|
||||
namespace {
|
||||
|
||||
using llvm::cast;
|
||||
using testing::ElementsAre;
|
||||
using testing::IsEmpty;
|
||||
|
||||
// Matches any `IntLiteral`.
|
||||
MATCHER(IntField, "") { return arg->kind() == ExpressionKind::IntLiteral; }
|
||||
|
||||
static auto FakeSourceLoc(int line_num) -> SourceLocation {
|
||||
return SourceLocation("<test>", line_num);
|
||||
}
|
||||
|
||||
class ExpressionTest : public ::testing::Test {
|
||||
protected:
|
||||
Arena arena;
|
||||
};
|
||||
|
||||
TEST_F(ExpressionTest, EmptyAsExpression) {
|
||||
ParenContents<Expression> contents = {.elements = {},
|
||||
.has_trailing_comma = false};
|
||||
Nonnull<const Expression*> expression =
|
||||
ExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(expression->source_loc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(expression->kind(), ExpressionKind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*expression).fields(), IsEmpty());
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, EmptyAsTuple) {
|
||||
ParenContents<Expression> contents = {.elements = {},
|
||||
.has_trailing_comma = false};
|
||||
Nonnull<const Expression*> tuple =
|
||||
TupleExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->source_loc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(tuple->kind(), ExpressionKind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*tuple).fields(), IsEmpty());
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, UnaryNoCommaAsExpression) {
|
||||
// Equivalent to a code fragment like
|
||||
// ```
|
||||
// (
|
||||
// 42
|
||||
// )
|
||||
// ```
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {arena.New<IntLiteral>(FakeSourceLoc(2), 42)},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
Nonnull<const Expression*> expression =
|
||||
ExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(expression->source_loc(), FakeSourceLoc(2));
|
||||
ASSERT_EQ(expression->kind(), ExpressionKind::IntLiteral);
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, UnaryNoCommaAsTuple) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {arena.New<IntLiteral>(FakeSourceLoc(2), 42)},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
Nonnull<const Expression*> tuple =
|
||||
TupleExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->source_loc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(tuple->kind(), ExpressionKind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*tuple).fields(), ElementsAre(IntField()));
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, UnaryWithCommaAsExpression) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {arena.New<IntLiteral>(FakeSourceLoc(2), 42)},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Nonnull<const Expression*> expression =
|
||||
ExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(expression->source_loc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(expression->kind(), ExpressionKind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*expression).fields(),
|
||||
ElementsAre(IntField()));
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, UnaryWithCommaAsTuple) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {arena.New<IntLiteral>(FakeSourceLoc(2), 42)},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Nonnull<const Expression*> tuple =
|
||||
TupleExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->source_loc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(tuple->kind(), ExpressionKind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*tuple).fields(), ElementsAre(IntField()));
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, BinaryAsExpression) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {arena.New<IntLiteral>(FakeSourceLoc(2), 42),
|
||||
arena.New<IntLiteral>(FakeSourceLoc(3), 42)},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Nonnull<const Expression*> expression =
|
||||
ExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(expression->source_loc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(expression->kind(), ExpressionKind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*expression).fields(),
|
||||
ElementsAre(IntField(), IntField()));
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, BinaryAsTuple) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {arena.New<IntLiteral>(FakeSourceLoc(2), 42),
|
||||
arena.New<IntLiteral>(FakeSourceLoc(3), 42)},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Nonnull<const Expression*> tuple =
|
||||
TupleExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->source_loc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(tuple->kind(), ExpressionKind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*tuple).fields(),
|
||||
ElementsAre(IntField(), IntField()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace Carbon::Testing
|
||||
Reference in New Issue
Block a user