1 //===-- DraftStoreTests.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 "Annotations.h"
10 #include "DraftStore.h"
11 #include "SourceCode.h"
12 #include "llvm/Support/ScopedPrinter.h"
13 #include "llvm/Testing/Support/Error.h"
14 #include "gmock/gmock.h"
15 #include "gtest/gtest.h"
16
17 namespace clang {
18 namespace clangd {
19 namespace {
20
TEST(DraftStore,Versions)21 TEST(DraftStore, Versions) {
22 DraftStore DS;
23 Path File = "foo.cpp";
24
25 EXPECT_EQ("25", DS.addDraft(File, "25", ""));
26 EXPECT_EQ("25", DS.getDraft(File)->Version);
27 EXPECT_EQ("", *DS.getDraft(File)->Contents);
28
29 EXPECT_EQ("26", DS.addDraft(File, "", "x"));
30 EXPECT_EQ("26", DS.getDraft(File)->Version);
31 EXPECT_EQ("x", *DS.getDraft(File)->Contents);
32
33 EXPECT_EQ("27", DS.addDraft(File, "", "x")) << "no-op change";
34 EXPECT_EQ("27", DS.getDraft(File)->Version);
35 EXPECT_EQ("x", *DS.getDraft(File)->Contents);
36
37 // We allow versions to go backwards.
38 EXPECT_EQ("7", DS.addDraft(File, "7", "y"));
39 EXPECT_EQ("7", DS.getDraft(File)->Version);
40 EXPECT_EQ("y", *DS.getDraft(File)->Contents);
41 }
42
43 } // namespace
44 } // namespace clangd
45 } // namespace clang
46