clang-tools
22.0.0git
llvm-project
clang-tools-extra
clangd
unittests
tweaks
RawStringLiteralTests.cpp
Go to the documentation of this file.
1
//===-- RawStringLiteralTests.cpp -------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "
TweakTesting.h
"
10
#include "gmock/gmock-matchers.h"
11
#include "gmock/gmock.h"
12
#include "gtest/gtest.h"
13
14
namespace
clang
{
15
namespace
clangd
{
16
namespace
{
17
18
TWEAK_TEST
(RawStringLiteral);
19
20
TEST_F
(RawStringLiteralTest, Test) {
21
Context
= Expression;
22
EXPECT_AVAILABLE
(R
"cpp(^"^f^o^o^\^n^")cpp");
23
EXPECT_AVAILABLE
(R
"cpp(R"(multi )" ^"token " "str\ning")cpp");
24
EXPECT_UNAVAILABLE
(R
"cpp(^"f^o^o^o")cpp");
// no chars need escaping
25
EXPECT_UNAVAILABLE
(R
"cpp(R"(multi )" ^"token " u8"str\ning")cpp");
// nonascii
26
EXPECT_UNAVAILABLE
(R
"cpp(^R^"^(^multi )" "token " "str\ning")cpp");
// raw
27
EXPECT_UNAVAILABLE
(R
"cpp(^"token\n" __FILE__)cpp");
// chunk is macro
28
EXPECT_UNAVAILABLE
(R
"cpp(^"a\r\n";)cpp");
// forbidden escape char
29
30
const
char
*Input = R
"cpp(R"(multi
31
token)" "\nst^ring\n" "literal")cpp";
32
const
char
*Output = R
"cpp(R"(multi
33
token
34
string
35
literal)")cpp";
36
EXPECT_EQ(apply(Input), Output);
37
}
38
39
TEST_F
(RawStringLiteralTest, TestC) {
40
Context
=
File
;
41
FileName =
"TestTU.c"
;
42
ExtraArgs = {
"-xc"
};
// raw strings are unavailable in C
43
EXPECT_UNAVAILABLE
(R
"c(const char *a = ^"^f^o^o^\^n^";)c");
44
}
45
46
TEST_F
(RawStringLiteralTest, TestCpp98) {
47
Context
=
File
;
48
ExtraArgs = {
"-std=c++98"
};
// raw strings are unavailable
49
// in versions prior to C++11
50
EXPECT_UNAVAILABLE
(R
"cpp(const char *a = ^"^f^o^o^\^n^";)cpp");
51
}
52
53
}
// namespace
54
}
// namespace clangd
55
}
// namespace clang
TweakTesting.h
TWEAK_TEST
#define TWEAK_TEST(TweakID)
Definition
TweakTesting.h:107
EXPECT_AVAILABLE
#define EXPECT_AVAILABLE(MarkedCode)
Definition
TweakTesting.h:123
EXPECT_UNAVAILABLE
#define EXPECT_UNAVAILABLE(MarkedCode)
Definition
TweakTesting.h:124
clang::clangd::Context
A context is an immutable container for per-request data that must be propagated through layers that ...
Definition
Context.h:69
clang::clangd
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
Definition
AST.cpp:45
clang::clangd::TEST_F
TEST_F(BackgroundIndexTest, NoCrashOnErrorFile)
Definition
BackgroundIndexTests.cpp:94
clang::clangd::CompletionItemKind::File
@ File
Definition
Protocol.h:356
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition
ApplyReplacements.h:27
Generated on
for clang-tools by
1.14.0