forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceErrorManagerTest.cpp
More file actions
67 lines (52 loc) · 1.78 KB
/
SourceErrorManagerTest.cpp
File metadata and controls
67 lines (52 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "hermes/Support/SourceErrorManager.h"
#include "gtest/gtest.h"
using namespace hermes;
namespace {
TEST(SourceErrorManagerTest, testFindSMLocFromCoords) {
SourceErrorManager mgr{};
auto buf =
llvh::MemoryBuffer::getMemBuffer("01\n34567\n\n\n\n", "TEST", false);
auto *start = buf->getBufferStart();
auto *end = buf->getBufferEnd();
mgr.addNewSourceBuffer(std::move(buf));
// Test just a normal position first.
SourceErrorManager::SourceCoords coords;
auto loc1 = SMLoc::getFromPointer(start + 5);
mgr.findBufferLineAndLoc(loc1, coords);
ASSERT_TRUE(coords.isValid());
ASSERT_EQ(2, coords.line);
ASSERT_EQ(3, coords.col);
auto loc2 = mgr.findSMLocFromCoords(coords);
ASSERT_EQ(loc1, loc2);
// Test column 1 in an empty line.
loc1 = SMLoc::getFromPointer(start + 10);
mgr.findBufferLineAndLoc(loc1, coords);
ASSERT_TRUE(coords.isValid());
ASSERT_EQ(4, coords.line);
ASSERT_EQ(1, coords.col);
loc2 = mgr.findSMLocFromCoords(coords);
ASSERT_EQ(loc1, loc2);
// Make it the last line.
loc1 = SMLoc::getFromPointer(start + 11);
mgr.findBufferLineAndLoc(loc1, coords);
ASSERT_TRUE(coords.isValid());
ASSERT_EQ(5, coords.line);
ASSERT_EQ(1, coords.col);
loc2 = mgr.findSMLocFromCoords(coords);
ASSERT_EQ(loc1, loc2);
// Some errors show unexpected EOF at one past the last character.
loc1 = SMLoc::getFromPointer(end);
mgr.findBufferLineAndLoc(loc1, coords);
ASSERT_TRUE(coords.isValid());
ASSERT_EQ(6, coords.line);
ASSERT_EQ(1, coords.col);
loc2 = mgr.findSMLocFromCoords(coords);
ASSERT_EQ(loc1, loc2);
}
} // end anonymous namespace