def test_upper(self): return #return unless RUBY_VERSION > '1.8.7' encoder = Encoder() str = eval('8224.chr(Encoding::UTF_8)') self.assertEqual('†', encoder.encode(str, str), 'unicode char encoded correctly') str = eval( '9824.chr(Encoding::UTF_8)+9827.chr(Encoding::UTF_8)+9829.chr(Encoding::UTF_8)+9830.chr(Encoding::UTF_8)' ) self.assertEqual('♠♣♥♦', encoder.encode(str, str), 'unicode chars encoded correctly')
def test_upper(self): return #return unless RUBY_VERSION > '1.8.7' encoder = Encoder() str = eval( '8224.chr(Encoding::UTF_8)' ) self.assertEqual( '†', encoder.encode( str, str ), 'unicode char encoded correctly' ) str = eval( '9824.chr(Encoding::UTF_8)+9827.chr(Encoding::UTF_8)+9829.chr(Encoding::UTF_8)+9830.chr(Encoding::UTF_8)' ) self.assertEqual( '♠♣♥♦', encoder.encode( str, str ), 'unicode chars encoded correctly' )
def test_numeric(self): encoder = Encoder() self.assertEqual( '&<>"'', encoder.encode_hex( '&<>"\'' ), 'default chars encoded numerically correctly' ) self.assertEqual( '&<>"'', encoder.encode( '&<>"\'' ), 'does not impact default chars encoded correctly' ) self.assertEqual( 'hello', encoder.encode_hex( 'hello', '' ), 'no chars encoded when no chars requested' ) self.assertEqual( 'hello', encoder.encode_hex( 'hello', 'e' ), 'requested chars encoded correctly' ) self.assertEqual( 'hello', encoder.encode( 'hello', 'e' ), 'requested chars encoded correctly' )
def test_numeric(self): encoder = Encoder() self.assertEqual('&<>"'', encoder.encode_hex('&<>"\''), 'default chars encoded numerically correctly') self.assertEqual('&<>"'', encoder.encode('&<>"\''), 'does not impact default chars encoded correctly') self.assertEqual('hello', encoder.encode_hex('hello', ''), 'no chars encoded when no chars requested') self.assertEqual('hello', encoder.encode_hex('hello', 'e'), 'requested chars encoded correctly') self.assertEqual('hello', encoder.encode('hello', 'e'), 'requested chars encoded correctly')
def test_lower(self): encoder = Encoder() self.assertEqual( '&<>"'', encoder.encode( '&<>"\'' ), 'default chars encoded when chars is nil' ) self.assertEqual( '&<>"'', encoder.encode( '&<>"\'', '' ), 'encodes when chars is empty' ) self.assertEqual( 'hello', encoder.encode( 'hello', 'e' ), 'requested chars encoded correctly' ) self.assertEqual( 'hell0', encoder.encode( 'hell0', 0 ), 'zero encodes correctly' ) self.assertEqual( '&bar', encoder.encode( '&bar', 'a&' ), 'ampersand is not double encoded' ) self.assertEqual( 'hello', encoder.encode( 'hello' ), 'no encodes when default chars is nil' ) self.assertEqual( 'hello', encoder.encode( 'hello', '' ), 'no encodes when default chars is empty' ) deadbeef = chr(222) + chr(173) + chr(190) + chr(239) self.assertEqual( 'Þ­¾ï', encoder.encode( deadbeef, deadbeef ), 'hex codes encoded correctly' ) self.assertEqual( 'Þ­¾ï', encoder.encode( deadbeef ), 'hex codes encoded correctly when chars is nil' ) self.assertEqual( 'Þ­¾ï', encoder.encode( deadbeef, '' ), 'hex codes encoded correctly when chars is empty' )
def test_lower(self): encoder = Encoder() self.assertEqual('&<>"'', encoder.encode('&<>"\''), 'default chars encoded when chars is nil') self.assertEqual('&<>"'', encoder.encode('&<>"\'', ''), 'encodes when chars is empty') self.assertEqual('hello', encoder.encode('hello', 'e'), 'requested chars encoded correctly') self.assertEqual('hell0', encoder.encode('hell0', 0), 'zero encodes correctly') self.assertEqual('&bar', encoder.encode('&bar', 'a&'), 'ampersand is not double encoded') self.assertEqual('hello', encoder.encode('hello'), 'no encodes when default chars is nil') self.assertEqual('hello', encoder.encode('hello', ''), 'no encodes when default chars is empty') deadbeef = chr(222) + chr(173) + chr(190) + chr(239) self.assertEqual('Þ­¾ï', encoder.encode(deadbeef, deadbeef), 'hex codes encoded correctly') self.assertEqual('Þ­¾ï', encoder.encode(deadbeef), 'hex codes encoded correctly when chars is nil') self.assertEqual('Þ­¾ï', encoder.encode(deadbeef, ''), 'hex codes encoded correctly when chars is empty')