-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added enry_detect_language First of many. Pushing for review. How's it look? * updated changes to function file forgot to save the file, so these didn't get pushed * update to error handling * added return * added all enry funcitons Problem: IsTest won't register for some reason(EnryIsTest doesn't show under registered objects, "make" returns error: "tables/tables.go:63:31: undefined: enry.EnryIsTest") * commented EnryIsTest out for now * modified directory, minor if statement changes * updated tests for each function enry_is_binary needs work * spelled enry correctly * updated enry_is_binary_test.go input filecontents not filepath now * some formatting fixes * add some documentation to the README Co-authored-by: Patrick DeVivo <[email protected]>
- Loading branch information
1 parent
32ba86d
commit 96f3c4e
Showing
25 changed files
with
505 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package funcs | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
type EnryDetectLanguage struct{} | ||
|
||
func (f *EnryDetectLanguage) Args() int { return 2 } | ||
func (f *EnryDetectLanguage) Deterministic() bool { return true } | ||
func (f *EnryDetectLanguage) Apply(context *sqlite.Context, value ...sqlite.Value) { | ||
if lang := enry.GetLanguage(value[0].Text(), value[1].Blob()); lang == "" { | ||
context.ResultNull() | ||
return | ||
} else { | ||
context.ResultText(lang) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package funcs | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/askgitdev/askgit/tables/internal/tools" | ||
) | ||
|
||
func TestEnryDetectLanguage(t *testing.T) { | ||
path := "./testdata/main.go" | ||
fileContents, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
rows, err := FixtureDatabase.Query("SELECT enry_detect_language(?,?)", path, fileContents) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
rowNum, contents, err := tools.RowContent(rows) | ||
if err != nil { | ||
t.Fatalf("err %d at row %d", err, rowNum) | ||
} | ||
|
||
if contents[0][0] != "Go" { | ||
t.Fatalf("expected string: %s, got %s", "Go", contents[0][0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package funcs | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
type EnryIsBinary struct{} | ||
|
||
func (f *EnryIsBinary) Args() int { return 1 } | ||
func (f *EnryIsBinary) Deterministic() bool { return true } | ||
func (f *EnryIsBinary) Apply(context *sqlite.Context, value ...sqlite.Value) { | ||
if enry.IsBinary(value[0].Blob()) { | ||
context.ResultInt(1) | ||
} else { | ||
context.ResultInt(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package funcs | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/askgitdev/askgit/tables/internal/tools" | ||
) | ||
|
||
func TestEnryIsBinary(t *testing.T) { | ||
path := "./testdata/binary" | ||
fileContents, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
rows, err := FixtureDatabase.Query("SELECT enry_is_binary(?)", fileContents) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
rowNum, contents, err := tools.RowContent(rows) | ||
if err != nil { | ||
t.Fatalf("err %d at row %d", err, rowNum) | ||
} | ||
|
||
if contents[0][0] != "1" { | ||
t.Fatalf("expected string: %s, got %s", "1", contents[0][0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package funcs | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
type EnryIsConfiguration struct{} | ||
|
||
func (f *EnryIsConfiguration) Args() int { return 1 } | ||
func (f *EnryIsConfiguration) Deterministic() bool { return true } | ||
func (f *EnryIsConfiguration) Apply(context *sqlite.Context, value ...sqlite.Value) { | ||
if enry.IsConfiguration(value[0].Text()) { | ||
context.ResultInt(1) | ||
} else { | ||
context.ResultInt(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package funcs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/askgitdev/askgit/tables/internal/tools" | ||
) | ||
|
||
func TestEnryIsConfiguration(t *testing.T) { | ||
path := "./testdata/configuration.json" // from here -> https://github.com/go-enry/go-enry/tree/master/_testdata | ||
rows, err := FixtureDatabase.Query("SELECT enry_is_configuration(?)", path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
rowNum, contents, err := tools.RowContent(rows) | ||
if err != nil { | ||
t.Fatalf("err %d at row %d", err, rowNum) | ||
} | ||
|
||
if contents[0][0] != "1" { | ||
t.Fatalf("expected string: %s, got %s", "1", contents[0][0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package funcs | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
type EnryIsDocumentation struct{} | ||
|
||
func (f *EnryIsDocumentation) Args() int { return 1 } | ||
func (f *EnryIsDocumentation) Deterministic() bool { return true } | ||
func (f *EnryIsDocumentation) Apply(context *sqlite.Context, value ...sqlite.Value) { | ||
if enry.IsDocumentation(value[0].Text()) { | ||
context.ResultInt(1) | ||
} else { | ||
context.ResultInt(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package funcs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/askgitdev/askgit/tables/internal/tools" | ||
) | ||
|
||
func TestEnryIsDocumentation(t *testing.T) { | ||
path := "./README.md" | ||
rows, err := FixtureDatabase.Query("SELECT enry_is_documentation(?)", path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
rowNum, contents, err := tools.RowContent(rows) | ||
if err != nil { | ||
t.Fatalf("err %d at row %d", err, rowNum) | ||
} | ||
|
||
if contents[0][0] != "1" { | ||
t.Fatalf("expected string: %s, got %s", "1", contents[0][0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package funcs | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
type EnryIsDotFile struct{} | ||
|
||
func (f *EnryIsDotFile) Args() int { return 1 } | ||
func (f *EnryIsDotFile) Deterministic() bool { return true } | ||
func (f *EnryIsDotFile) Apply(context *sqlite.Context, value ...sqlite.Value) { | ||
if enry.IsDotFile(value[0].Text()) { | ||
context.ResultInt(1) | ||
} else { | ||
context.ResultInt(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package funcs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/askgitdev/askgit/tables/internal/tools" | ||
) | ||
|
||
func TestEnryIsDotFile(t *testing.T) { | ||
path := "./testdata/.hidden" | ||
rows, err := FixtureDatabase.Query("SELECT enry_is_dot_file(?)", path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
rowNum, contents, err := tools.RowContent(rows) | ||
if err != nil { | ||
t.Fatalf("err %d at row %d", err, rowNum) | ||
} | ||
|
||
if contents[0][0] != "1" { | ||
t.Fatalf("expected string: %s, got %s", "1", contents[0][0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package funcs | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
type EnryIsGenerated struct{} | ||
|
||
func (f *EnryIsGenerated) Args() int { return 2 } | ||
func (f *EnryIsGenerated) Deterministic() bool { return true } | ||
func (f *EnryIsGenerated) Apply(context *sqlite.Context, value ...sqlite.Value) { | ||
if enry.IsGenerated(value[0].Text(), value[1].Blob()) { | ||
context.ResultInt(1) | ||
} else { | ||
context.ResultInt(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package funcs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/askgitdev/askgit/tables/internal/tools" | ||
) | ||
|
||
func TestEnryIsGenerated(t *testing.T) { | ||
path := ".xcworkspacedata" | ||
rows, err := FixtureDatabase.Query("SELECT enry_is_generated(?, ?)", path, "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
rowNum, contents, err := tools.RowContent(rows) | ||
if err != nil { | ||
t.Fatalf("err %d at row %d", err, rowNum) | ||
} | ||
|
||
if contents[0][0] != "1" { | ||
t.Fatalf("expected string: %s, got %s", "1", contents[0][0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package funcs | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
type EnryIsImage struct{} | ||
|
||
func (f *EnryIsImage) Args() int { return 1 } | ||
func (f *EnryIsImage) Deterministic() bool { return true } | ||
func (f *EnryIsImage) Apply(context *sqlite.Context, value ...sqlite.Value) { | ||
if enry.IsImage(value[0].Text()) { | ||
context.ResultInt(1) | ||
} else { | ||
context.ResultInt(0) | ||
} | ||
} |
Oops, something went wrong.