Files
textmate/Frameworks/document/tests/t_inode.cc
Allan Odgaard 1d4d3bd3d3 Fix path/inode lookup when opening documents
The strategy is to prefer an existing document with same path and if there is none, check if there is a document with the same inode. The latter is so that links or files that have been moved, do not create duplicate documents.

The old code used a single map for the lookup, using path::identifier_t as key (wrapping path and/or inode), though since the map is ordered, the code would occasionally fail, as the keys cannot be correctly ordered (so effectively this reworked code is a fix for an incorrect path::identifier_t::operator<).

Fixes #1052.
2013-07-30 15:34:17 +02:00

35 lines
1.0 KiB
C++

#include <document/document.h>
#include <test/jail.h>
class InodeTests : public CxxTest::TestSuite
{
public:
void test_inode ()
{
test::jail_t jail;
jail.touch("file_1.txt");
document::document_ptr doc_1 = document::create(jail.path("file_1.txt"));
path::move(jail.path("file_1.txt"), jail.path("file_2.txt"));
document::document_ptr doc_2 = document::create(jail.path("file_2.txt"));
jail.ln("file_3.txt", "file_2.txt");
document::document_ptr doc_3 = document::create(jail.path("file_3.txt"));
TS_ASSERT(*doc_1 == *doc_2);
TS_ASSERT(*doc_2 == *doc_3);
TS_ASSERT_EQUALS(path::name(doc_1->path()), "file_1.txt");
TS_ASSERT_EQUALS(path::name(doc_2->path()), "file_1.txt");
TS_ASSERT_EQUALS(path::name(doc_3->path()), "file_1.txt");
document::document_ptr doc_4 = document::create(jail.path("future.txt"));
jail.touch("future.txt");
document::document_ptr doc_5 = document::create(jail.path("future.txt"));
TS_ASSERT(*doc_4 == *doc_5);
TS_ASSERT_EQUALS(path::name(doc_4->path()), "future.txt");
}
};