39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package folio
|
|
|
|
import (
|
|
"encoding/json"
|
|
"decl/internal/data"
|
|
)
|
|
|
|
type MockConverter struct {
|
|
InjectType func() data.TypeName `json:"-" yaml:"-"`
|
|
InjectEmit func(data.Document, data.ElementSelector) (data.Resource, error) `json:"-" yaml:"-"`
|
|
InjectExtract func(data.Resource, data.ElementSelector) (data.Document, error) `json:"-" yaml:"-"`
|
|
InjectClose func() (error) `json:"-" yaml:"-"`
|
|
}
|
|
|
|
func (m *MockConverter) Type() data.TypeName {
|
|
return m.InjectType()
|
|
}
|
|
|
|
func (m *MockConverter) Emit(document data.Document, filter data.ElementSelector) (data.Resource, error) {
|
|
return m.InjectEmit(document, filter)
|
|
}
|
|
|
|
func (m *MockConverter) Extract(sourceResource data.Resource, filter data.ElementSelector) (data.Document, error) {
|
|
return m.InjectExtract(sourceResource, filter)
|
|
}
|
|
|
|
func (m *MockConverter) Close() error {
|
|
return m.InjectClose()
|
|
}
|
|
|
|
func (m *MockConverter) UnmarshalJSON(data []byte) error {
|
|
if err := json.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|