mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-18 22:23:07 -03:00
test: add basic tests for crystal and delegating lexers
This commit is contained in:
1
spec/examples/crystal/lexer.cr.json
Normal file
1
spec/examples/crystal/lexer.cr.json
Normal file
File diff suppressed because one or more lines are too long
11
spec/examples/jinja+python/funko.py.j2
Normal file
11
spec/examples/jinja+python/funko.py.j2
Normal file
@ -0,0 +1,11 @@
|
||||
from flask import Flask, request
|
||||
|
||||
app = Flask("{{name}}")
|
||||
|
||||
@app.route('/')
|
||||
def handle():
|
||||
return "Hello World from Flask!"
|
||||
|
||||
@app.route('/ping')
|
||||
def ping():
|
||||
return "OK"
|
1
spec/examples/jinja+python/funko.py.j2.json
Normal file
1
spec/examples/jinja+python/funko.py.j2.json
Normal file
@ -0,0 +1 @@
|
||||
[{"type":"KeywordNamespace","value":"from"},{"type":"Text","value":" "},{"type":"NameNamespace","value":"flask"},{"type":"Text","value":" "},{"type":"KeywordNamespace","value":"import"},{"type":"Text","value":" "},{"type":"Name","value":"Flask"},{"type":"Punctuation","value":","},{"type":"Text","value":" "},{"type":"Name","value":"request"},{"type":"Text","value":"\n\n"},{"type":"Name","value":"app"},{"type":"Text","value":" "},{"type":"Operator","value":"="},{"type":"Text","value":" "},{"type":"Name","value":"Flask"},{"type":"Punctuation","value":"("},{"type":"LiteralStringDouble","value":"\""},{"type":"CommentPreproc","value":"{{"},{"type":"NameVariable","value":"name"},{"type":"CommentPreproc","value":"}}"},{"type":"LiteralStringDouble","value":"\")"},{"type":"Text","value":"\n\n"},{"type":"NameDecorator","value":"@app.route"},{"type":"Punctuation","value":"("},{"type":"LiteralStringSingle","value":"'/'"},{"type":"Punctuation","value":")"},{"type":"Text","value":"\n"},{"type":"Keyword","value":"def"},{"type":"Text","value":" "},{"type":"NameFunction","value":"handle"},{"type":"Punctuation","value":"():"},{"type":"Text","value":"\n "},{"type":"Keyword","value":"return"},{"type":"Text","value":" "},{"type":"LiteralStringDouble","value":"\"Hello World from Flask!\""},{"type":"Text","value":"\n\n"},{"type":"NameDecorator","value":"@app.route"},{"type":"Punctuation","value":"("},{"type":"LiteralStringSingle","value":"'/ping'"},{"type":"Punctuation","value":")"},{"type":"Text","value":"\n"},{"type":"Keyword","value":"def"},{"type":"Text","value":" "},{"type":"NameFunction","value":"ping"},{"type":"Punctuation","value":"():"},{"type":"Text","value":"\n "},{"type":"Keyword","value":"return"},{"type":"Text","value":" "},{"type":"LiteralStringDouble","value":"\"OK\""},{"type":"Text","value":"\n"}]
|
@ -3,6 +3,9 @@ require "./spec_helper"
|
||||
# These are the testcases from Pygments
|
||||
testcases = Dir.glob("#{__DIR__}/tests/**/*txt").sort
|
||||
|
||||
# These are custom testcases
|
||||
examples = Dir.glob("#{__DIR__}/examples/**/*.*").reject(&.ends_with? ".json").sort!
|
||||
|
||||
# These lexers don't load because of parsing issues
|
||||
failing_lexers = {
|
||||
"webgpu_shading_language",
|
||||
@ -51,6 +54,14 @@ not_my_fault = {
|
||||
|
||||
describe Tartrazine do
|
||||
describe "Lexer" do
|
||||
examples.each do |example|
|
||||
it "parses #{example}".split("/")[-2...].join("/") do
|
||||
lexer = Tartrazine.lexer(name: File.basename(File.dirname(example)).downcase)
|
||||
text = File.read(example)
|
||||
expected = Array(Tartrazine::Token).from_json(File.read("#{example}.json"))
|
||||
Tartrazine::RegexLexer.collapse_tokens(lexer.tokenizer(text).to_a).should eq expected
|
||||
end
|
||||
end
|
||||
testcases.each do |testcase|
|
||||
if known_bad.includes?(testcase)
|
||||
pending "parses #{testcase}".split("/")[-2...].join("/") do
|
||||
|
Reference in New Issue
Block a user