-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to pre-compile all regexes.
- Loading branch information
1 parent
87183b3
commit a729603
Showing
7 changed files
with
77 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/alecthomas/chroma/formatters" | ||
"github.com/alecthomas/chroma/lexers" | ||
"github.com/alecthomas/chroma/styles" | ||
"gopkg.in/alecthomas/kingpin.v3-unstable" | ||
) | ||
|
||
var ( | ||
filesArgs = kingpin.Arg("file", "Files to use to exercise lexers.").Required().ExistingFiles() | ||
) | ||
|
||
func main() { | ||
kingpin.CommandLine.Help = "Exercise linters against a list of files." | ||
kingpin.Parse() | ||
|
||
writer, err := formatters.NoOp.Format(ioutil.Discard, styles.SwapOff) | ||
kingpin.FatalIfError(err, "") | ||
|
||
for _, file := range *filesArgs { | ||
lexer := lexers.Match(file) | ||
if lexer == nil { | ||
fmt.Printf("warning: could not find lexer for %q\n", file) | ||
continue | ||
} | ||
text, err := ioutil.ReadFile(file) | ||
kingpin.FatalIfError(err, "") | ||
err = lexer.Tokenise(nil, string(text), writer) | ||
kingpin.FatalIfError(err, "%s failed to tokenise %q", lexer.Config().Name, file) | ||
fmt.Printf("ok: %q\n", file) | ||
} | ||
} |
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,21 @@ | ||
package lexers_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/alecthomas/chroma/formatters" | ||
"github.com/alecthomas/chroma/lexers" | ||
"github.com/alecthomas/chroma/styles" | ||
) | ||
|
||
func TestCompileAllRegexes(t *testing.T) { | ||
writer, err := formatters.NoOp.Format(ioutil.Discard, styles.SwapOff) | ||
assert.NoError(t, err) | ||
for _, lexer := range lexers.Registry.Lexers { | ||
err = lexer.Tokenise(nil, "", writer) | ||
assert.NoError(t, err, "%s failed", lexer.Config().Name) | ||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.