Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GetFullLineCount() to the Rolodex #320

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions index/rolodex.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,23 @@ func (r *Rolodex) RolodexFileSize() int64 {
}
return size
}

// GetFullLineCount returns the total number of lines from all files in the Rolodex
func (r *Rolodex) GetFullLineCount() int64 {
var lineCount int64
for _, v := range r.localFS {
if lfs, ok := v.(RolodexFS); ok {
for _, f := range lfs.GetFiles() {
lineCount += int64(strings.Count(f.GetContent(), "\n")) + 1
}
}
}
for _, v := range r.remoteFS {
if lfs, ok := v.(RolodexFS); ok {
for _, f := range lfs.GetFiles() {
lineCount += int64(strings.Count(f.GetContent(), "\n")) + 1
}
}
}
return lineCount
}
7 changes: 7 additions & 0 deletions index/rolodex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,10 @@ components:

assert.GreaterOrEqual(t, len(rolodex.GetIgnoredCircularReferences()), 1)

expectedFullLineCount := (strings.Count(first, "\n") + 1) + (strings.Count(second, "\n") + 1) +
(strings.Count(third, "\n") + 1) + (strings.Count(fourth, "\n") + 1)
assert.Equal(t, int64(expectedFullLineCount), rolodex.GetFullLineCount())

}

func TestRolodex_IndexCircularLookup_PolyItemsFileOnly_LocalIncluded(t *testing.T) {
Expand Down Expand Up @@ -1529,6 +1533,9 @@ func TestRolodex_SimpleTest_OneDoc(t *testing.T) {
assert.Nil(t, rolo.GetRootIndex())
assert.Len(t, rolo.GetIndexes(), 10)

lineCount := rolo.GetFullLineCount()
assert.Equal(t, int64(158), lineCount, "total line count in the rolodex is wrong")

assert.NoError(t, err)
assert.Len(t, rolo.indexes, 10)

Expand Down
Loading