mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 14:43:05 -03:00
Sync to linguist 7.2.0: heuristics.yml support (#189)
Sync \w Github Linguist v7.2.0 Includes new way of handling `heuristics.yml` and all `./data/*` re-generated using Github Linguist [v7.2.0](https://github.com/github/linguist/releases/tag/v7.2.0) release tag. - many new languages - better vendoring detection - update doc on update&known issues.
This commit is contained in:
61
data/heuristics_test.go
Normal file
61
data/heuristics_test.go
Normal file
@ -0,0 +1,61 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/src-d/enry.v1/data/rule"
|
||||
)
|
||||
|
||||
var testContentHeuristics = map[string]*Heuristics{
|
||||
".md": &Heuristics{ // final pattern for parsed YAML rule
|
||||
rule.Or(
|
||||
rule.MatchingLanguages("Markdown"),
|
||||
regexp.MustCompile(`(^[-A-Za-z0-9=#!\*\[|>])|<\/ | \A\z`),
|
||||
),
|
||||
rule.Or(
|
||||
rule.MatchingLanguages("GCC Machine Description"),
|
||||
regexp.MustCompile(`^(;;|\(define_)`),
|
||||
),
|
||||
rule.Always(
|
||||
rule.MatchingLanguages("Markdown"),
|
||||
),
|
||||
},
|
||||
".ms": &Heuristics{
|
||||
// Order defines precedence: And, Or, Not, Named, Always
|
||||
rule.And(
|
||||
rule.MatchingLanguages("Unix Assembly"),
|
||||
rule.Not(rule.MatchingLanguages(""), regexp.MustCompile(`/\*`)),
|
||||
rule.Or(
|
||||
rule.MatchingLanguages(""),
|
||||
regexp.MustCompile(`^\s*\.(?:include\s|globa?l\s|[A-Za-z][_A-Za-z0-9]*:)`),
|
||||
),
|
||||
),
|
||||
rule.Or(
|
||||
rule.MatchingLanguages("Roff"),
|
||||
regexp.MustCompile(`^[.''][A-Za-z]{2}(\s|$)`),
|
||||
),
|
||||
rule.Always(
|
||||
rule.MatchingLanguages("MAXScript"),
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
func TestContentHeuristic_MatchingAlways(t *testing.T) {
|
||||
lang := testContentHeuristics[".md"].matchString("")
|
||||
assert.Equal(t, []string{"Markdown"}, lang)
|
||||
|
||||
lang = testContentHeuristics[".ms"].matchString("")
|
||||
assert.Equal(t, []string{"MAXScript"}, lang)
|
||||
}
|
||||
|
||||
func TestContentHeuristic_MatchingAnd(t *testing.T) {
|
||||
lang := testContentHeuristics[".md"].matchString(";;")
|
||||
assert.Equal(t, []string{"GCC Machine Description"}, lang)
|
||||
}
|
||||
|
||||
func TestContentHeuristic_MatchingOr(t *testing.T) {
|
||||
lang := testContentHeuristics[".ms"].matchString(" .include \"math.s\"")
|
||||
assert.Equal(t, []string{"Unix Assembly"}, lang)
|
||||
}
|
Reference in New Issue
Block a user