Add Buffer::n_lines()
This commit is contained in:
parent
8fbd7252de
commit
65be7c3a6f
@ -502,3 +502,14 @@ void Buffer::set_filename(const std::string & filename)
|
||||
{
|
||||
m_filename = std::make_shared<std::string>(filename);
|
||||
}
|
||||
|
||||
size_t Buffer::n_lines() const
|
||||
{
|
||||
auto it = end();
|
||||
it.go_back();
|
||||
if (it.valid())
|
||||
{
|
||||
return it.line() + 1u;
|
||||
}
|
||||
return 0u;
|
||||
}
|
||||
|
@ -192,6 +192,7 @@ public:
|
||||
void pop_operation();
|
||||
void undo();
|
||||
void redo();
|
||||
size_t n_lines() const;
|
||||
|
||||
#ifndef ENABLE_TESTING
|
||||
protected:
|
||||
|
@ -33,11 +33,13 @@ TEST(BufferTest, writes_an_empty_file_for_an_empty_buffer)
|
||||
Buffer b;
|
||||
ASSERT_TRUE(b.write_to_file("test/tmp/f"));
|
||||
TestSupport::compare_files("test/files/empty.txt", "test/tmp/f");
|
||||
ASSERT_EQ(0u, b.n_lines());
|
||||
}
|
||||
|
||||
TEST(BufferTest, allows_navigating_using_iterators)
|
||||
{
|
||||
Buffer b("test/files/line_endings/lf_format.txt");
|
||||
ASSERT_EQ(2u, b.n_lines());
|
||||
auto iterator = b.add_cursor();
|
||||
|
||||
EXPECT_EQ(0u, iterator->line());
|
||||
|
Loading…
x
Reference in New Issue
Block a user