Skip to content

Commit

Permalink
add support upper and mixed case extensions (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
iyoshiha authored Dec 11, 2023
1 parent 332d02c commit 1d771cb
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 1 deletion.
32 changes: 32 additions & 0 deletions pkg/finder/finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,38 @@ func Test_FileSystemFinderAbsPath(t *testing.T) {
}
}

func Test_FileSystemFinderUpperCaseExtention(t *testing.T) {
fsFinder := FileSystemFinderInit(
WithPathRoots("../../test/fixtures/uppercase-extention"),
)

files, err := fsFinder.Find()

if len(files) < 1 {
t.Errorf("Unable to find files")
}

if err != nil {
t.Errorf("Unable to find files")
}
}

func Test_FileSystemFinderMixedCaseExtention(t *testing.T) {
fsFinder := FileSystemFinderInit(
WithPathRoots("../../test/fixtures/mixedcase-extention"),
)

files, err := fsFinder.Find()

if len(files) < 1 {
t.Errorf("Unable to find files")
}

if err != nil {
t.Errorf("Unable to find files")
}
}

func Test_FileFinderBadPath(t *testing.T) {
fsFinder := FileSystemFinderInit(
WithPathRoots(
Expand Down
2 changes: 1 addition & 1 deletion pkg/finder/fsfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (fsf FileSystemFinder) findOne(pathRoot string) ([]FileMetadata, error) {

for _, fileType := range fsf.FileTypes {
for _, extension := range fileType.Extensions {
if extension == walkFileExtension {
if strings.EqualFold(extension, walkFileExtension) {
fileMetadata := FileMetadata{dirEntry.Name(), path, fileType}
matchingFiles = append(matchingFiles, fileMetadata)
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/mixedcase-extention/good.CSv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
first_name,last_name,username
Rob,Pike,rob
Ken,Thompson,ken
Robert,Griesemer,gri
13 changes: 13 additions & 0 deletions test/fixtures/mixedcase-extention/good.HCl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
io_mode = "async"

service "http" "web_proxy" {
listen_addr = "127.0.0.1:8080"

process "main" {
command = ["/usr/local/bin/awesome-app", "server"]
}

process "mgmt" {
command = ["/usr/local/bin/awesome-app", "mgmt"]
}
}
8 changes: 8 additions & 0 deletions test/fixtures/mixedcase-extention/good.INi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Version]
First=name
second=value

[Empty]

[Last]
1=2
5 changes: 5 additions & 0 deletions test/fixtures/mixedcase-extention/good.JSon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test": {
"name": "test"
}
}
15 changes: 15 additions & 0 deletions test/fixtures/mixedcase-extention/good.PList
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
46 changes: 46 additions & 0 deletions test/fixtures/mixedcase-extention/good.PRoperties
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# You are reading a comment in ".properties" file.
! The exclamation mark can also be used for comments.
# Lines with "properties" contain a key and a value separated by a delimiting character.
# There are 3 delimiting characters: '=' (equal), ':' (colon) and whitespace (space, \t and \f).
website = https://en.wikipedia.org/
language : English
topic .properties files
# A word on a line will just create a key with no value.
empty
# White space that appears between the key, the value and the delimiter is ignored.
# This means that the following are equivalent (other than for readability).
hello=hello
hello = hello
# Keys with the same name will be overwritten by the key that is the furthest in a file.
# For example the final value for "duplicateKey" will be "second".
duplicateKey = first
duplicateKey = second
# To use the delimiter characters inside a key, you need to escape them with a \.
# However, there is no need to do this in the value.
delimiterCharacters\:\=\ = This is the value for the key "delimiterCharacters\:\=\ "
# Adding a \ at the end of a line means that the value continues to the next line.
multiline = This line \
continues
# If you want your value to include a \, it should be escaped by another \.
path = c:\\wiki\\templates
# This means that if the number of \ at the end of the line is even, the next line is not included in the value.
# In the following example, the value for "evenKey" is "This is on one line\".
evenKey = This is on one line\\
# This line is a normal comment and is not included in the value for "evenKey"
# If the number of \ is odd, then the next line is included in the value.
# In the following example, the value for "oddKey" is "This is line one and\#This is line two".
oddKey = This is line one and\\\
# This is line two
# White space characters are removed before each line.
# Make sure to add your spaces before your \ if you need them on the next line.
# In the following example, the value for "welcome" is "Welcome to Wikipedia!".
welcome = Welcome to \
Wikipedia!
# If you need to add newlines and carriage returns, they need to be escaped using \n and \r respectively.
# You can also optionally escape tabs with \t for readability purposes.
valueWithEscapes = This is a newline\n and a carriage return\r and a tab\t.
# You can also use Unicode escape characters (maximum of four hexadecimal digits).
# In the following example, the value for "encodedHelloInJapanese" is "こんにちは".
encodedHelloInJapanese = \u3053\u3093\u306b\u3061\u306f
# But with more modern file encodings like UTF-8, you can directly use supported characters.
helloInJapanese = こんにちは
33 changes: 33 additions & 0 deletions test/fixtures/mixedcase-extention/good.TOml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates

[database]
server = "192.168.1.1"
ports = [ 8000, 8001, 8002 ]
connection_max = 5000
enabled = true

[servers]

# Indentation (tabs and/or spaces) is allowed but not required
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"

[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"

[clients]
data = [ ["gamma", "delta"], [1, 2] ]

# Line breaks are OK when inside arrays
hosts = [
"alpha",
"omega"
]
1 change: 1 addition & 0 deletions test/fixtures/mixedcase-extention/good.YAml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: test
4 changes: 4 additions & 0 deletions test/fixtures/uppercase-extention/good.CSV
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
first_name,last_name,username
Rob,Pike,rob
Ken,Thompson,ken
Robert,Griesemer,gri
13 changes: 13 additions & 0 deletions test/fixtures/uppercase-extention/good.HCL
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
io_mode = "async"

service "http" "web_proxy" {
listen_addr = "127.0.0.1:8080"

process "main" {
command = ["/usr/local/bin/awesome-app", "server"]
}

process "mgmt" {
command = ["/usr/local/bin/awesome-app", "mgmt"]
}
}
8 changes: 8 additions & 0 deletions test/fixtures/uppercase-extention/good.INI
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Version]
First=name
second=value

[Empty]

[Last]
1=2
5 changes: 5 additions & 0 deletions test/fixtures/uppercase-extention/good.JSON
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test": {
"name": "test"
}
}
15 changes: 15 additions & 0 deletions test/fixtures/uppercase-extention/good.PLIST
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
46 changes: 46 additions & 0 deletions test/fixtures/uppercase-extention/good.PROPERTIES
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# You are reading a comment in ".properties" file.
! The exclamation mark can also be used for comments.
# Lines with "properties" contain a key and a value separated by a delimiting character.
# There are 3 delimiting characters: '=' (equal), ':' (colon) and whitespace (space, \t and \f).
website = https://en.wikipedia.org/
language : English
topic .properties files
# A word on a line will just create a key with no value.
empty
# White space that appears between the key, the value and the delimiter is ignored.
# This means that the following are equivalent (other than for readability).
hello=hello
hello = hello
# Keys with the same name will be overwritten by the key that is the furthest in a file.
# For example the final value for "duplicateKey" will be "second".
duplicateKey = first
duplicateKey = second
# To use the delimiter characters inside a key, you need to escape them with a \.
# However, there is no need to do this in the value.
delimiterCharacters\:\=\ = This is the value for the key "delimiterCharacters\:\=\ "
# Adding a \ at the end of a line means that the value continues to the next line.
multiline = This line \
continues
# If you want your value to include a \, it should be escaped by another \.
path = c:\\wiki\\templates
# This means that if the number of \ at the end of the line is even, the next line is not included in the value.
# In the following example, the value for "evenKey" is "This is on one line\".
evenKey = This is on one line\\
# This line is a normal comment and is not included in the value for "evenKey"
# If the number of \ is odd, then the next line is included in the value.
# In the following example, the value for "oddKey" is "This is line one and\#This is line two".
oddKey = This is line one and\\\
# This is line two
# White space characters are removed before each line.
# Make sure to add your spaces before your \ if you need them on the next line.
# In the following example, the value for "welcome" is "Welcome to Wikipedia!".
welcome = Welcome to \
Wikipedia!
# If you need to add newlines and carriage returns, they need to be escaped using \n and \r respectively.
# You can also optionally escape tabs with \t for readability purposes.
valueWithEscapes = This is a newline\n and a carriage return\r and a tab\t.
# You can also use Unicode escape characters (maximum of four hexadecimal digits).
# In the following example, the value for "encodedHelloInJapanese" is "こんにちは".
encodedHelloInJapanese = \u3053\u3093\u306b\u3061\u306f
# But with more modern file encodings like UTF-8, you can directly use supported characters.
helloInJapanese = こんにちは
33 changes: 33 additions & 0 deletions test/fixtures/uppercase-extention/good.TOML
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates

[database]
server = "192.168.1.1"
ports = [ 8000, 8001, 8002 ]
connection_max = 5000
enabled = true

[servers]

# Indentation (tabs and/or spaces) is allowed but not required
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"

[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"

[clients]
data = [ ["gamma", "delta"], [1, 2] ]

# Line breaks are OK when inside arrays
hosts = [
"alpha",
"omega"
]
1 change: 1 addition & 0 deletions test/fixtures/uppercase-extention/good.YAML
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: test

0 comments on commit 1d771cb

Please sign in to comment.