1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
require 'rouge/cli'
describe Rouge::CLI do
let(:argv) { [] }
subject { Rouge::CLI.parse(argv) }
describe Rouge::CLI::Help do
describe '-h' do
let(:argv) { %w(-h) }
it('parses') { assert { Rouge::CLI::Help === subject } }
end
describe '--help' do
let(:argv) { %w(--help) }
it('parses') { assert { Rouge::CLI::Help === subject } }
end
describe 'help' do
let(:argv) { %w(help) }
it('parses') { assert { Rouge::CLI::Help === subject } }
end
describe 'nil' do
let(:argv) { %w() }
it('parses') { assert { Rouge::CLI::Help === subject } }
end
end
describe Rouge::CLI::Highlight do
describe 'specifying a lexer' do
let(:argv) { %w(highlight -l ruby) }
it('parses') {
assert { Rouge::CLI::Highlight === subject }
assert { Rouge::Lexers::Ruby === subject.lexer }
}
end
describe 'guessing a lexer by mimetype' do
let(:argv) { %w(highlight -m application/javascript) }
it('parses') {
assert { Rouge::Lexers::Javascript === subject.lexer }
}
end
describe 'guessing a lexer by file contents' do
let(:argv) { %w(highlight -i bin/rougify) }
it('parses') {
assert { Rouge::Lexers::Ruby === subject.lexer }
}
end
describe 'escaping by default' do
let(:argv) { %w(highlight --escape -l ruby) }
it('parses') {
assert { Rouge::Lexers::Escape === subject.lexer }
assert { Rouge::Lexers::Ruby === subject.lexer.lang }
assert { subject.lexer.start == '<!' }
assert { subject.lexer.end == '!>' }
}
end
describe 'escaping with custom delimiters' do
let(:argv) { %w(highlight --escape-with [===[ ]===] -l ruby) }
it('parses') {
assert { Rouge::Lexers::Escape === subject.lexer }
assert { Rouge::Lexers::Ruby === subject.lexer.lang }
assert { subject.lexer.start == '[===[' }
assert { subject.lexer.end == ']===]' }
}
end
end
describe Rouge::CLI::List do
describe 'list' do
let(:argv) { %w(list) }
it('parses') { assert { Rouge::CLI::List === subject } }
it 'lists available lexers' do
out, err = capture_io { subject.run }
expected_tags = Rouge::Lexer.all.map(&:tag).sort
actual_tags = out.scan(/^([^\s]*?):/).flatten
assert_equal expected_tags, actual_tags, "err: #{err.inspect}"
end
end
end
end
|