From 546bd16aba7c9c0d0f84d33f160f4f246c9db0da Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 21 Nov 2017 14:49:32 +0900 Subject: [PATCH] Move isHTMLFile function --- extensions.go | 9 ++++++++- extensions_test.go | 10 ++++++++++ file_checker.go | 5 ----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/extensions.go b/extensions.go index 17757ed..4996ea3 100644 --- a/extensions.go +++ b/extensions.go @@ -1,6 +1,9 @@ package main -import "path/filepath" +import ( + "path/filepath" + "strings" +) var extensions = map[string]bool{ ".htm": true, @@ -12,3 +15,7 @@ func isMarkupFile(f string) bool { _, ok := extensions[filepath.Ext(f)] return ok } + +func isHTMLFile(f string) bool { + return strings.HasSuffix(f, ".html") || strings.HasSuffix(f, ".htm") +} diff --git a/extensions_test.go b/extensions_test.go index be29e91..a3314d5 100644 --- a/extensions_test.go +++ b/extensions_test.go @@ -15,3 +15,13 @@ func TestIsMarkupFile(t *testing.T) { assert.False(t, isMarkupFile(f)) } } + +func TestIsHTMLFile(t *testing.T) { + for _, f := range []string{"foo.html", "foo.htm", "foo/bar.html"} { + assert.True(t, isHTMLFile(f)) + } + + for _, f := range []string{"foo", "foo.md", "bar/foo"} { + assert.False(t, isHTMLFile(f)) + } +} diff --git a/file_checker.go b/file_checker.go index 93792cb..3b08546 100644 --- a/file_checker.go +++ b/file_checker.go @@ -4,7 +4,6 @@ import ( "bytes" "io/ioutil" "net/url" - "strings" "sync" "time" @@ -122,7 +121,3 @@ func isURL(s string) bool { u, err := url.Parse(s) return err == nil && (u.Scheme == "" || u.Scheme == "http" || u.Scheme == "https") } - -func isHTMLFile(f string) bool { - return strings.HasSuffix(f, ".html") || strings.HasSuffix(f, ".htm") -}