mirror of
https://github.com/mikefarah/yq.git
synced 2026-08-30 20:35:13 +08:00
skip format check for filenames ending with dot
also add a unit test for func FormatStringFromFilename to cover such case
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v4/pkg/yqlib"
|
||||
)
|
||||
|
||||
// only test format detection based on filename extension
|
||||
func TestFormatStringFromFilename(t *testing.T) {
|
||||
cases := []struct {
|
||||
filename string
|
||||
expected string
|
||||
}{
|
||||
// filenames that have extensions
|
||||
{"file.yaml", "yaml"},
|
||||
{"FILE.JSON", "json"},
|
||||
{"file.properties", "properties"},
|
||||
{"file.xml", "xml"},
|
||||
{"file.unknown", "unknown"},
|
||||
|
||||
// filenames without extensions
|
||||
{"file", "yaml"},
|
||||
{"a.dir/file", "yaml"},
|
||||
{"file.", "yaml"},
|
||||
{".", "yaml"},
|
||||
{"", "yaml"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
result := yqlib.FormatStringFromFilename(c.filename)
|
||||
if result != c.expected {
|
||||
t.Errorf("FormatStringFromFilename(%q) = %q, wanted: %q", c.filename, result, c.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user