Skip to content

Commit

Permalink
feat(nav): add supporting code and failing tests for sample (#366)
Browse files Browse the repository at this point in the history
fix(nav): remove incorrect use of pointer to slice in sort (#366)

ref(nav): use item.IsDir (#366)

ref(nav): fix more pointer to slices (#366)

test(nav): use expectedNo struct in skip tests (#366)

ref(nav): rename expectedNo to directoryQuantities (#366)

ref(nav): panic if subscription type not set (#366)

ref(nav): add benign node filter for compound only filtering (#366)

ref(nav): add isFilteringActive (#366)

ref(nav): simplify useExtendHook (#366)

ref(nav): streamline filter init and automatically apply benigh filter (#366)

feat(nav): setup sample failing tests and other sample support (#366)
  • Loading branch information
plastikfan committed Nov 16, 2023
1 parent aeb9bb4 commit 9f3e294
Show file tree
Hide file tree
Showing 20 changed files with 497 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
version: v1.54.2
args: --verbose

test:
Expand Down
16 changes: 11 additions & 5 deletions xfs/nav/directory-entries.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nav

import (
"fmt"
"io/fs"

"github.com/samber/lo"
Expand All @@ -24,7 +25,7 @@ type directoryEntriesFactory struct{}
type directoryEntriesFactoryParams struct {
o *TraverseOptions
order DirectoryEntryOrderEnum
entries *[]fs.DirEntry
entries []fs.DirEntry
}

func (directoryEntriesFactory) new(params *directoryEntriesFactoryParams) *DirectoryEntries {
Expand All @@ -46,8 +47,13 @@ type DirectoryEntries struct {
Files []fs.DirEntry
}

func (e *DirectoryEntries) arrange(entries *[]fs.DirEntry) {
grouped := lo.GroupBy(*entries, func(item fs.DirEntry) bool {
func (e *DirectoryEntries) Sample() *DirectoryEntries {
fmt.Println("❌❌❌ DirectoryEntries.Sample NOT-IMPLEMENTED")
return e
}

func (e *DirectoryEntries) arrange(entries []fs.DirEntry) {
grouped := lo.GroupBy(entries, func(item fs.DirEntry) bool {
return item.IsDir()
})

Expand Down Expand Up @@ -76,8 +82,8 @@ func (e *DirectoryEntries) all() []fs.DirEntry {
return result
}

func (e *DirectoryEntries) sort(entries *[]fs.DirEntry) {
if err := e.Options.Hooks.Sort(*entries); err != nil {
func (e *DirectoryEntries) sort(entries []fs.DirEntry) {
if err := e.Options.Hooks.Sort(entries); err != nil {
panic(xi18n.NewSortFnFailedError())
}
}
13 changes: 13 additions & 0 deletions xfs/nav/errors.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package nav

import (
"errors"
"fmt"
)

// Errors defined here are internal errors that are of no value to end
// users (hence not l10n). There are usually programming errors which
// means they only have meaning for client developers.

// ❌ Invalid Notification Mute Requested

// NewInvalidNotificationMuteRequestedNativeError creates an untranslated error to
Expand Down Expand Up @@ -51,3 +56,11 @@ func NewInvalidPeriscopeRootPathNativeError(root, current string) error {
func NewResumeControllerNotSetNativeError(from string) error {
return fmt.Errorf("internal: resume controller not set (from: '%v')", from)
}

// static errors, identifiable with errors.Is

// ErrUndefinedSubscriptionType indicates client has not set the navigation
// subscription type at /Options.Store.Subscription.
var ErrUndefinedSubscriptionType = errors.New(
"undefined subscription type; please set in traverse options (/Options.Store.Subscription)",
)
7 changes: 7 additions & 0 deletions xfs/nav/filter-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,10 @@ type compoundCounters struct {
filteredIn uint
filteredOut uint
}

var BenignNodeFilterDef = FilterDef{
Type: FilterTypeRegexEn,
Description: "benign allow all",
Pattern: ".",
Scope: ScopeRootEn,
}
14 changes: 7 additions & 7 deletions xfs/nav/filter-glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
message: "universal(any scope): glob filter",
relative: "RETRO-WAVE",
subscription: nav.SubscribeAny,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 8,
folders: 0,
},
Expand All @@ -129,7 +129,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
message: "universal(any scope): glob filter (negate)",
relative: "RETRO-WAVE",
subscription: nav.SubscribeAny,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 6,
folders: 8,
},
Expand All @@ -145,7 +145,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
message: "universal(undefined scope): glob filter",
relative: "RETRO-WAVE",
subscription: nav.SubscribeAny,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 8,
folders: 0,
},
Expand All @@ -161,7 +161,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
message: "universal(any scope): glob filter (ifNotApplicable=true)",
relative: "RETRO-WAVE",
subscription: nav.SubscribeAny,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 8,
folders: 4,
},
Expand All @@ -178,7 +178,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
message: "universal(leaf scope): glob filter (ifNotApplicable=false)",
relative: "RETRO-WAVE",
subscription: nav.SubscribeAny,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 8,
folders: 0,
},
Expand Down Expand Up @@ -272,7 +272,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
message: "folder(with files): glob filter",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFoldersWithFiles,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 8,
children: map[string]int{
Expand All @@ -292,7 +292,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
message: "folder(with files): glob filter (negate)",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFoldersWithFiles,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 8,
children: map[string]int{
Expand Down
50 changes: 30 additions & 20 deletions xfs/nav/filter-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,40 @@ func InitFiltersHookFn(o *TraverseOptions, frame *navigationFrame) {
if o.Store.FilterDefs != nil {
frame.filters = &NavigationFilters{}

if o.Store.FilterDefs.Node.Pattern != "" || o.Store.FilterDefs.Node.Custom != nil {
o.useExtendHook()
frame.filters.Node = newNodeFilter(&o.Store.FilterDefs.Node)
decorated := frame.client
decorator := &LabelledTraverseCallback{
Label: "filter decorator",
Fn: func(item *TraverseItem) error {
if frame.filters.Node.IsMatch(item) {
return decorated.Fn(item)
}

item.filteredOut = true
return nil
},
if !o.isSamplingActive() {
if o.isFilteringActive() {
o.useExtendHook()
applyNodeFilterDecoration(&o.Store.FilterDefs.Node, frame)
}
frame.raw = decorator
frame.decorate("init-current-filter 🎁", decorator)
}

if o.Store.FilterDefs.Children.Pattern != "" || o.Store.FilterDefs.Children.Custom != nil {
o.useExtendHook()
frame.filters.Children = newCompoundFilter(&o.Store.FilterDefs.Children)
if o.Store.FilterDefs.Children.Pattern != "" || o.Store.FilterDefs.Children.Custom != nil {
if frame.filters.Node == nil {
applyNodeFilterDecoration(&BenignNodeFilterDef, frame)
}

frame.filters.Children = newCompoundFilter(&o.Store.FilterDefs.Children)
}
}
} else {
frame.raw = frame.client
}
}

func applyNodeFilterDecoration(nodeDef *FilterDef, frame *navigationFrame) {
frame.filters.Node = newNodeFilter(nodeDef)
decorated := frame.client
decorator := &LabelledTraverseCallback{
Label: "filter decorator",
Fn: func(item *TraverseItem) error {
if frame.filters.Node.IsMatch(item) {
return decorated.Fn(item)
}

item.filteredOut = true
return nil
},
}

frame.raw = decorator
frame.decorate("init-current-filter 🎁", decorator)
}
20 changes: 10 additions & 10 deletions xfs/nav/filter-regex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
message: "files(any scope): regex filter",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFiles,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 4,
folders: 0,
},
Expand All @@ -126,7 +126,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
message: "files(any scope): regex filter (negate)",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFiles,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 10,
folders: 0,
},
Expand All @@ -141,7 +141,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
message: "files(default to any scope): regex filter",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFiles,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 4,
folders: 0,
},
Expand All @@ -157,7 +157,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
message: "folders(any scope): regex filter",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFolders,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 2,
},
Expand All @@ -172,7 +172,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
message: "folders(any scope): regex filter (negate)",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFolders,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 6,
},
Expand All @@ -188,7 +188,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
message: "folders(undefined scope): regex filter",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFolders,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 2,
},
Expand All @@ -204,7 +204,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
message: "folders(top): regex filter (ifNotApplicable=true)",
relative: "PROGRESSIVE-HOUSE",
subscription: nav.SubscribeFolders,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 10,
},
Expand All @@ -222,7 +222,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
relative: "",
subscription: nav.SubscribeFolders,
mandatory: []string{"PROGRESSIVE-HOUSE"},
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 1,
},
Expand Down Expand Up @@ -320,7 +320,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
relative: "RETRO-WAVE",
subscription: nav.SubscribeFoldersWithFiles,

expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 8,
children: map[string]int{
Expand All @@ -340,7 +340,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
message: "folder(with files): regex filter (negate)",
relative: "RETRO-WAVE",
subscription: nav.SubscribeFoldersWithFiles,
expectedNoOf: expectedNo{
expectedNoOf: directoryQuantities{
files: 0,
folders: 8,
children: map[string]int{
Expand Down
Loading

0 comments on commit 9f3e294

Please sign in to comment.