Class: HTMLInputStreamTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
HTML5
Defined in:
lib/feed_tools/vendor/html5/tests/test_stream.rb

Constant Summary

Constants included from HTML5

HTML5::ASCII_LETTERS, HTML5::ASCII_LOWERCASE, HTML5::ASCII_UPPERCASE, HTML5::BOOLEAN_ATTRIBUTES, HTML5::CDATA_ELEMENTS, HTML5::CONTENT_MODEL_FLAGS, HTML5::DIGITS, HTML5::E, HTML5::ENCODINGS, HTML5::ENTITIES, HTML5::ENTITIES_WINDOWS1252, HTML5::FORMATTING_ELEMENTS, HTML5::HEADING_ELEMENTS, HTML5::HEX_DIGITS, HTML5::Marker, HTML5::RCDATA_ELEMENTS, HTML5::SCOPING_ELEMENTS, HTML5::SPACE_CHARACTERS, HTML5::SPECIAL_ELEMENTS, HTML5::TABLE_INSERT_MODE_ELEMENTS, HTML5::VERSION, HTML5::VOID_ELEMENTS

Instance Method Summary collapse

Methods included from HTML5

_, parse, parse_fragment

Instance Method Details

#test_bomObject



35
36
37
38
39
# File 'lib/feed_tools/vendor/html5/tests/test_stream.rb', line 35

def test_bom
  stream = HTMLInputStream.new("\xef\xbb\xbf" + "'")
  assert_equal('utf-8', stream.char_encoding)
  assert_equal("'", stream.char)
end

#test_char_asciiObject



8
9
10
11
12
# File 'lib/feed_tools/vendor/html5/tests/test_stream.rb', line 8

def test_char_ascii
  stream = HTMLInputStream.new("'", :encoding=>'ascii')
  assert_equal('ascii', stream.char_encoding)
  assert_equal("'", stream.char)
end

#test_char_nullObject



14
15
16
17
# File 'lib/feed_tools/vendor/html5/tests/test_stream.rb', line 14

def test_char_null
  stream = HTMLInputStream.new("\x00")
  assert_equal("\xef\xbf\xbd", stream.char)
end

#test_char_utf8Object



19
20
21
22
23
# File 'lib/feed_tools/vendor/html5/tests/test_stream.rb', line 19

def test_char_utf8
  stream = HTMLInputStream.new("\xe2\x80\x98", :encoding=>'utf-8')
  assert_equal('utf-8', stream.char_encoding)
  assert_equal("\xe2\x80\x98", stream.char)
end

#test_char_win1252Object



25
26
27
28
29
30
31
32
33
# File 'lib/feed_tools/vendor/html5/tests/test_stream.rb', line 25

def test_char_win1252
  stream = HTMLInputStream.new("\xa2\xc5\xf1\x92\x86")
  assert_equal('windows-1252', stream.char_encoding)
  assert_equal("\xc2\xa2", stream.char)
  assert_equal("\xc3\x85", stream.char)
  assert_equal("\xc3\xb1", stream.char)
  assert_equal("\xe2\x80\x99", stream.char)
  assert_equal("\xe2\x80\xa0", stream.char)
end

#test_newlinesObject



53
54
55
56
57
58
59
60
61
# File 'lib/feed_tools/vendor/html5/tests/test_stream.rb', line 53

def test_newlines
  stream = HTMLInputStream.new("\xef\xbb\xbf" + "a\nbb\r\nccc\rdddd")
  assert_equal([1,0], stream.position)
  assert_equal("a\nbb\n", stream.chars_until('c'))
  assert_equal([3,0], stream.position)
  assert_equal("ccc\ndddd", stream.chars_until('x'))
  assert_equal([4,4], stream.position)
  assert_equal([1,2,3], stream.instance_eval {@line_lengths})
end