Parent

Included Modules

Class/Module Index [+]

Quicksearch

TestTreeWalkers

Public Instance Methods

concatenateCharacterTokens(tokens) click to toggle source
# File lib/feed_tools/vendor/html5/tests/test_treewalkers.rb, line 24
def concatenateCharacterTokens(tokens)
  charactersToken = nil
  for token in tokens
      type = token[:type]
      if [:Characters, :SpaceCharacters].include?(type)
          if charactersToken == nil
              charactersToken = {:type => :Characters, :data => token[:data]}
          else
              charactersToken[:data] += token[:data]
          end
      else
          if charactersToken != nil
              yield charactersToken
              charactersToken = nil
          end
          yield token
      end
  end
  yield charactersToken if charactersToken != nil
end
convertTokens(tokens) click to toggle source
# File lib/feed_tools/vendor/html5/tests/test_treewalkers.rb, line 45
def convertTokens(tokens)
  output = []
  indent = 0
  concatenateCharacterTokens(tokens) do |token|
    case token[:type]
    when :StartTag, :EmptyTag
      output << "#{' '*indent}<#{token[:name]}>"
      indent += 2
      for name, value in token[:data].to_a.sort
        next if name=='xmlns'
        output << "#{' '*indent}#{name}=\"#{value}\""
      end
      indent -= 2 if token[:type] == :EmptyTag
    when :EndTag
      indent -= 2
    when :Comment
      output << "#{' '*indent}<!-- #{token[:data]} -->"
    when :Doctype
      if token[:name] and token[:name].any?
        output << "#{' '*indent}<!DOCTYPE #{token[:name]}>"
      else
        output << "#{' '*indent}<!DOCTYPE >"
      end
    when :Characters, :SpaceCharacters
      output << "#{' '*indent}\"#{token[:data]}\""
    end
  end
  output.join("\n")
end
test_all_tokens() click to toggle source
# File lib/feed_tools/vendor/html5/tests/test_treewalkers.rb, line 115
def test_all_tokens
  expected = [
      {:data => [], :type => :StartTag, :name => 'html'},
      {:data => [], :type => :StartTag, :name => 'head'},
      {:data => [], :type => :EndTag,   :name => 'head'},
      {:data => [], :type => :StartTag, :name => 'body'},
      {:data => [], :type => :EndTag,   :name => 'body'},
      {:data => [], :type => :EndTag,   :name => 'html'}]
  for treeName, tree_class in $tree_types_to_test
    p = HTML5::HTMLParser.new(:tree => tree_class[:builder])
    document = p.parse("<html></html>")
    # document = tree_class.get(:adapter)(document)
    output = tree_class[:walker].new(document)
    expected.zip(output) do |expected_token, output_token|
      assert_equal(expected_token, output_token)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.