Skip to content

Commit

Permalink
Adding tests from Deneb Showcase repo
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Jan 16, 2024
1 parent a90d734 commit 7e8823c
Show file tree
Hide file tree
Showing 36 changed files with 24,923 additions and 42 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.svg
*.js
/candlestick.svg
/layer-line.svg

*.png
*.jpg
*.txt
72 changes: 72 additions & 0 deletions source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package vegagoja

import (
"io/fs"
"os"
"strings"
)

// Source is a cascading [fs.FS] implementation.
type Source struct {
sources []fs.FS
}

// NewSource creates a source data source for the supplied file systems.
func NewSource(sources ...fs.FS) fs.FS {
if len(sources) == 1 {
return sources[0]
}
return &Source{
sources: sources,
}
}

// Open satisfies the [fs.FS] interface.
func (s *Source) Open(name string) (fs.File, error) {
for _, source := range s.sources {
if file, err := source.Open(name); err == nil {
return file, nil
}
}
return nil, os.ErrNotExist
}

// PrefixedSource is a prefixed source.
type PrefixedSource struct {
prefix string
source fs.FS
}

// NewPrefixedSource creates a prefixed source.
func NewPrefixedSource(prefix string, source fs.FS) *PrefixedSource {
return &PrefixedSource{
prefix: prefix,
source: source,
}
}

// NewPrefixedSourceDir creates a prefixed source for the specified directory.
func NewPrefixedSourceDir(prefix, dir string) *PrefixedSource {
return &PrefixedSource{
prefix: prefix,
source: os.DirFS(dir),
}
}

// Open satisfies the [fs.FS] interface.
func (s *PrefixedSource) Open(name string) (fs.File, error) {
if !strings.HasPrefix(name, s.prefix) {
return nil, os.ErrNotExist
}
return s.source.Open(strings.TrimPrefix(name, s.prefix))
}

// ResultSet is the shared interface for a result set.
type ResultSet interface {
Next() bool
Scan(...interface{}) error
Columns() ([]string, error)
Close() error
Err() error
NextResultSet() bool
}
21 changes: 21 additions & 0 deletions testdata/deneb/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Davide Bacci

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions testdata/deneb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# About

The examples in this folder are taken from [David Bacci's][david-bacci-linkedin]
[Deneb Showcase][deneb-showcase], and modified under the [MIT License](./LICENSE).

[david-bacci-linkedin]: https://www.linkedin.com/in/davbacci/
[deneb-showcase]: https://github.com/PBI-David/Deneb-Showcase
Loading

0 comments on commit 7e8823c

Please sign in to comment.