From 6298fe0f1ab12359bf1cbb87f9c31d3553c071f5 Mon Sep 17 00:00:00 2001 From: ryenus Date: Mon, 5 Aug 2024 11:45:34 +0800 Subject: [PATCH] add a test for file ext based format detection --- pkg/yqlib/format_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/yqlib/format_test.go b/pkg/yqlib/format_test.go index e6db1644..6060ccdf 100644 --- a/pkg/yqlib/format_test.go +++ b/pkg/yqlib/format_test.go @@ -50,3 +50,13 @@ func TestFormatFromString(t *testing.T) { } } } + +func TestFormatStringFromFilename(t *testing.T) { + test.AssertResult(t, "yaml", FormatStringFromFilename("test.Yaml")) + test.AssertResult(t, "yaml", FormatStringFromFilename("test.index.Yaml")) + test.AssertResult(t, "yaml", FormatStringFromFilename("test")) + test.AssertResult(t, "json", FormatStringFromFilename("test.json")) + test.AssertResult(t, "json", FormatStringFromFilename("TEST.JSON")) + test.AssertResult(t, "yaml", FormatStringFromFilename("test.json/foo")) + test.AssertResult(t, "yaml", FormatStringFromFilename("")) +}