File: filter.rb

package info (click to toggle)
coderay 1.1.3-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,368 kB
  • sloc: ruby: 9,987; makefile: 14; sh: 4; python: 1
file content (40 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download | duplicates (2)
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
require 'test/unit'
require 'coderay'

class FilterTest < Test::Unit::TestCase
  
  def test_creation
    filter = nil
    assert_nothing_raised do
      filter = CodeRay.encoder :filter
    end
    assert CodeRay::Encoders::Filter < CodeRay::Encoders::Encoder
    assert_kind_of CodeRay::Encoders::Encoder, filter
  end
  
  def test_filtering_text_tokens
    tokens = CodeRay::Tokens.new
    10.times do |i|
      tokens.text_token i.to_s, :index
    end
    assert_equal tokens, CodeRay::Encoders::Filter.new.encode_tokens(tokens)
    assert_equal CodeRay::Tokens, tokens.filter.class
    assert_equal tokens, tokens.filter
  end
  
  def test_filtering_block_tokens
    tokens = CodeRay::Tokens.new
    10.times do |i|
      tokens.begin_group :index
      tokens.text_token i.to_s, :content
      tokens.end_group :index
      tokens.begin_line :index
      tokens.text_token i.to_s, :content
      tokens.end_line :index
    end
    assert_equal tokens, CodeRay::Encoders::Filter.new.encode_tokens(tokens)
    assert_equal CodeRay::Tokens, tokens.filter.class
    assert_equal tokens, tokens.filter
  end
  
end