#!/usr/bin/python # -*- coding: UTF-8 -*- # # Author: Pau Sanchez (contact@pausanchez.com) # Version: v1.0 # Last Modified: 2010/09/15 # # For the latest version check out: # http://www.codigomanso.com/en/projects # # My blog: # http://www.codigomanso.com/en/ - English Version # http://www.codigomanso.com/es/ - Spanish Version # from bbcodeparser import bbcodeparser from bbcodebuilder import bbcodebuilder import random import unittest class BBCodeTests(unittest.TestCase): def setUp (self): self.bbcode = bbcodeparser() return def testConstructor (self): self.assertEqual (bbcodeparser ('whatever').html(), 'whatever') self.assertEqual (bbcodeparser ('[b]bold[/b]').html(), 'bold') self.assertEqual (str (bbcodeparser ('[b]bold[/b]')), '[b]bold[/b]') return def testBold (self): self.assertEqual (self.bbcode.parse ('whatever').html(), 'whatever') self.assertEqual (self.bbcode.parse ('[b]bold[/b]').html(), 'bold') self.assertEqual (self.bbcode.parse ('[B]bold[/b]').html(), 'bold') self.assertEqual (self.bbcode.parse ('this is [B]bold[/B]').html(), 'this is bold') return def testItalic (self): self.assertEqual (self.bbcode.parse ('[i]italic[/i]').html(), 'italic') return def testUnderline (self): self.assertEqual (self.bbcode.parse ('[u]italic[/u]').html(), 'italic') return def testURLs (self): self.assertEqual ( self.bbcode.parse ('[url]http://www.google.com[/url]').html(), 'http://www.google.com' ) self.assertEqual ( self.bbcode.parse ('[url=http://www.google.com]Google[/url]').html(), 'Google' ) self.assertEqual ( self.bbcode.parse ('[url="http://www.google.com"]Google[/url]').html(), 'Google' ) self.assertEqual ( self.bbcode.parse ('[url="http://www.google.com" title="Search Engine"]Google[/url]').html(), 'Google' ) self.assertEqual ( self.bbcode.parse ('[url link="http://www.google.com"]Google[/url]').html(), 'Google' ) return def testPTag (self): self.assertEqual ( self.bbcode.parse ('[p color=#0000ff]blue[/p]').html(), u'
blue
' ) self.assertEqual ( self.bbcode.parse ('[p size=12]12pt font[/p]').html(), u'12pt font
' ) self.assertEqual ( self.bbcode.parse ('[p font=arial]arial[/p]').html(), u'arial
' ) self.assertEqual ( self.bbcode.parse ('[p font=arial color=blue size=14]blue 14pt arial').html(), u'blue 14pt arial
' ) self.assertEqual ( self.bbcode.parse ('[p class=whatever]text[/p]').html(), u'text
' ) return def testColorTag (self): self.assertEqual ( self.bbcode.parse ('[color=#0000ff]blue[/color]').html(), u'blue' ) return def testSizeTag (self): self.assertEqual ( self.bbcode.parse ('[size=12]12pt font[/size]').html(), u'12pt font' ) return def testEmail(self): self.assertEqual ( self.bbcode.parse ('[email]asdf@asdf.com[/email]').html(), u'asdf@asdf.com' ) self.assertEqual ( self.bbcode.parse ('[email=john@smith.com]John Smith[/email]').html(), u'John Smith' ) return def testImgTag (self): self.assertEqual ( self.bbcode.parse ('[img]http://www.codigomanso.com/image.jpg[/img]').html(), u'
'
)
self.assertEqual (
self.bbcode.parse ('[img="This is the ALT of the image"]http://www.codigomanso.com/image.jpg[/img]').html(),
u'
'
)
self.assertEqual (
self.bbcode.parse ('[img=320x200]http://www.codigomanso.com/image.jpg[/img]').html(),
u'
'
)
self.assertEqual (
self.bbcode.parse ('[img=320x200 title="Image Test"]http://www.codigomanso.com/image.jpg[/img]').html(),
u'
'
)
self.assertEqual (
self.bbcode.parse ('[img="whatever" width=320 height="212" title="Image Test"]http://www.codigomanso.com/image.jpg[/img]').html(),
u'
'
)
return
def testGoogleURL (self):
self.assertEqual (
self.bbcode.parse ('[google]asdf[/google]').html(),
u'asdf'
)
self.assertEqual (
self.bbcode.parse ('[google]Tom Hanks[/google]').html(),
u'Tom Hanks'
)
return
def testWikipediaURL (self):
self.assertEqual (
self.bbcode.parse ('[wikipedia]Tom Hanks[/wikipedia]').html(),
u'Tom Hanks'
)
self.assertEqual (
self.bbcode.parse ('[wikipedia language=en]Tom Hanks[/wikipedia]').html(),
u'Tom Hanks'
)
self.assertEqual (
self.bbcode.parse ('[wikipedia lang=es]Tom Hanks[/wikipedia]').html(),
u'Tom Hanks'
)
self.assertEqual (
self.bbcode.parse ('[wikipedia=es]Tom Hanks[/wikipedia]').html(),
u'Tom Hanks'
)
return
def testListTags (self):
self.assertEqual (
self.bbcode.parse ('[ul][li]item 1[/li][li]item 2[/li][/ul]').html(),
u'bold
' ) self.assertEqual ( self.bbcode.parse ('[p][b]a ').html(), 'a <b>
' ) self.assertEqual ( self.bbcode.parse ('[ol][li]item 1[li]item 2[/li][/ol]').html(), u'This is bold and this italic and this is red and this is also red.
fix bold and italic
http://www.codigomanso.com/
Codigo Manso
Codigo Manso
| big |
|---|