Skip to content

Commit

Permalink
feat(nav): navigate with pre-constructed options (#348)
Browse files Browse the repository at this point in the history
chore: lint - clean up unused items

feat(nav): setup failing tests for provided options (#348)

feat(nav): added from methods for options (#348)

feat(nav): call o.afterUserOptions for pre-constructed options (#348)
  • Loading branch information
plastikfan committed Oct 28, 2023
1 parent f664937 commit 2bd0f30
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 178 deletions.
2 changes: 1 addition & 1 deletion xfs/nav/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func universalCallback(name string, extended bool) *nav.LabelledTraverseCallback
}
}

func universalCallbackNoAssert(name string, extended bool) *nav.LabelledTraverseCallback {
func universalCallbackNoAssert(name string, extended bool) *nav.LabelledTraverseCallback { //nolint:unparam // for future use
ex := lo.Ternary(extended, "-EX", "")

return &nav.LabelledTraverseCallback{
Expand Down
6 changes: 0 additions & 6 deletions xfs/nav/navigation-async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ type (
asyncOkTE struct {
asyncTE
}

asyncErrorTE struct {
asyncTE
fragment string
timeout time.Duration
}
)

const (
Expand Down
137 changes: 81 additions & 56 deletions xfs/nav/navigation-listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,68 +272,73 @@ var _ = Describe("Listener", Ordered, func() {
})

Context("folders", func() {
Context("given: filter and listen both active", func() {
It("🧪 should: apply filter within the listen range", func() {
path := helpers.Path(root, "edm/ELECTRONICA")
optionFn := func(o *nav.TraverseOptions) {
o.Notify.OnBegin = begin("🛡️")
o.Store.Subscription = nav.SubscribeFolders
o.Store.FilterDefs = &nav.FilterDefinitions{
Node: nav.FilterDef{
Type: nav.FilterTypeRegexEn,
Description: "Contains 'o'",
Scope: nav.ScopeAllEn,
Pattern: "(i?)o",
},
}
var setOptions func(o *nav.TraverseOptions)

BeforeAll(func() {
setOptions = func(o *nav.TraverseOptions) {
o.Notify.OnBegin = begin("🛡️")
o.Store.Subscription = nav.SubscribeFolders
o.Store.FilterDefs = &nav.FilterDefinitions{
Node: nav.FilterDef{
Type: nav.FilterTypeRegexEn,
Description: "Contains 'o'",
Scope: nav.ScopeAllEn,
Pattern: "(i?)o",
},
}

o.Store.ListenDefs = nav.ListenDefinitions{
StartAt: &nav.FilterDef{
Type: nav.FilterTypeCustomEn,
Custom: &helpers.CustomFilter{
Value: "Orbital",
Name: "Start Listening At: Orbital",
},
o.Store.ListenDefs = nav.ListenDefinitions{
StartAt: &nav.FilterDef{
Type: nav.FilterTypeCustomEn,
Custom: &helpers.CustomFilter{
Value: "Orbital",
Name: "Start Listening At: Orbital",
},
StopAt: &nav.FilterDef{
Type: nav.FilterTypeCustomEn,
Custom: &helpers.CustomFilter{
Value: "Underworld",
Name: "Stop Listening At: Underworld",
},
},
StopAt: &nav.FilterDef{
Type: nav.FilterTypeCustomEn,
Custom: &helpers.CustomFilter{
Value: "Underworld",
Name: "Stop Listening At: Underworld",
},
}
},
}

o.Notify.OnStart = func(description string) {
GinkgoWriter.Printf("===> 🎶 Start Listening: '%v'\n", description)
}
o.Notify.OnStop = func(description string) {
GinkgoWriter.Printf("===> ⛔ Stop Listening: '%v'\n", description)
}
o.Store.DoExtend = true
o.Callback = &nav.LabelledTraverseCallback{
Label: "Listener Test Callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🔊 LISTENING-CALLBACK: name: '%v'\n",
item.Extension.Name,
)
GinkgoWriter.Printf(
"===> ⚗️ Regex Filter(%v) source: '%v', item-name: '%v', item-scope(fs): '%v(%v)'\n",
o.Store.FilterDefs.Node.Description,
o.Store.FilterDefs.Node.Pattern,
item.Extension.Name,
item.Extension.NodeScope,
o.Store.FilterDefs.Node.Scope,
)
Expect(item.Extension.Name).To(MatchRegexp(o.Store.FilterDefs.Node.Pattern),
helpers.Reason(item.Extension.Name),
)
return nil
},
}
o.Store.Logging = logo()
o.Notify.OnStart = func(description string) {
GinkgoWriter.Printf("===> 🎶 Start Listening: '%v'\n", description)
}
o.Notify.OnStop = func(description string) {
GinkgoWriter.Printf("===> ⛔ Stop Listening: '%v'\n", description)
}
o.Store.DoExtend = true
o.Callback = &nav.LabelledTraverseCallback{
Label: "Listener Test Callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🔊 LISTENING-CALLBACK: name: '%v'\n",
item.Extension.Name,
)
GinkgoWriter.Printf(
"===> ⚗️ Regex Filter(%v) source: '%v', item-name: '%v', item-scope(fs): '%v(%v)'\n",
o.Store.FilterDefs.Node.Description,
o.Store.FilterDefs.Node.Pattern,
item.Extension.Name,
item.Extension.NodeScope,
o.Store.FilterDefs.Node.Scope,
)
Expect(item.Extension.Name).To(MatchRegexp(o.Store.FilterDefs.Node.Pattern),
helpers.Reason(item.Extension.Name),
)
return nil
},
}
o.Store.Logging = logo()
}
})

Context("given: filter and listen both active", func() {
It("🧪 should: apply filter within the listen range", func() {
path := helpers.Path(root, "edm/ELECTRONICA")
optionFn := setOptions
result, _ := nav.New().Primary(&nav.Prime{
Path: path,
OptionsFn: optionFn,
Expand All @@ -349,6 +354,26 @@ var _ = Describe("Listener", Ordered, func() {
_ = result.Session.StartedAt()
_ = result.Session.Elapsed()
})

When("using ProvidedOptions", func() {
It("🧪 should: apply filter within the listen range", func() {
providedOptions := nav.GetDefaultOptions()
setOptions(providedOptions) // the sort option is not being set properly
//
path := helpers.Path(root, "edm/ELECTRONICA")
result, _ := nav.New().Primary(&nav.Prime{
Path: path,
ProvidedOptions: providedOptions,
}).Run()

files := result.Metrics.Count(nav.MetricNoFilesInvokedEn)
folders := result.Metrics.Count(nav.MetricNoFoldersInvokedEn)

GinkgoWriter.Printf("---> 🍕🍕 Metrics, files:'%v', folders:'%v'\n",
files, folders,
)
})
})
})
})
})
10 changes: 6 additions & 4 deletions xfs/nav/navigation-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ func (r *runner) With(with CreateNewRunnerWith, info *RunnerInfo) NavigationRunn
lo.TernaryF(with&RunnerWithResume == 0,
func() NavigationRunner {
return r.Primary(&Prime{
Path: info.PrimeInfo.Path,
OptionsFn: info.PrimeInfo.OptionsFn,
Path: info.PrimeInfo.Path,
OptionsFn: info.PrimeInfo.OptionsFn,
ProvidedOptions: info.PrimeInfo.ProvidedOptions,
})
},
func() NavigationRunner {
Expand Down Expand Up @@ -146,8 +147,9 @@ func IfWithPoolUseContext(with CreateNewRunnerWith, args ...any) []any {

func (r *runner) Primary(info *Prime) NavigationRunner {
r.session = &Primary{
Path: info.Path,
OptionFn: info.OptionsFn,
Path: info.Path,
OptionFn: info.OptionsFn,
ProvidedOptions: info.ProvidedOptions,
}

return r
Expand Down
19 changes: 15 additions & 4 deletions xfs/nav/navigation-session.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nav

import (
"errors"
"time"

xi18n "github.com/snivilised/extendio/i18n"
Expand Down Expand Up @@ -47,9 +48,10 @@ func (s *session) finish(result *TraverseResult, _ error) {
// Primary
type Primary struct {
session
Path string
OptionFn TraverseOptionFn
navigator TraverseNavigator
Path string
OptionFn TraverseOptionFn
ProvidedOptions *TraverseOptions
navigator TraverseNavigator
}

// Save persists the current state for a primary session, that allows
Expand All @@ -59,7 +61,16 @@ func (s *Primary) Save(path string) error {
}

func (s *Primary) init() {
s.navigator = navigatorFactory{}.new(s.OptionFn)
switch {
case s.OptionFn != nil:
s.navigator = navigatorFactory{}.fromOptionsFn(s.OptionFn)

case s.ProvidedOptions != nil:
s.navigator = navigatorFactory{}.fromProvidedOptions(s.ProvidedOptions)

default:
panic(errors.New("missing traverse options"))
}
}

func (s *Primary) run(sync NavigationSync, args ...any) (*TraverseResult, error) {
Expand Down
2 changes: 0 additions & 2 deletions xfs/nav/navigation-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type NavigationSync interface {
}

type baseSync struct {
session TraverseSession
}

func (s *baseSync) extract(args ...any) (bool, context.Context, context.CancelFunc) {
Expand Down Expand Up @@ -51,7 +50,6 @@ func (s *baseSync) extract(args ...any) (bool, context.Context, context.CancelFu
}

type inlineSync struct {
baseSync
}

func (s *inlineSync) Run(callback sessionCallback, _ syncable, _ ...any) (*TraverseResult, error) {
Expand Down
Loading

0 comments on commit 2bd0f30

Please sign in to comment.