Skip to content

Commit

Permalink
tests: html: add tests for node comparisons
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Scherf <mail@florianscherf.de>
  • Loading branch information
fscherf committed Jul 6, 2023
1 parent 5877495 commit b1b30f3
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/test_0107_html_node_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
def test_node_comparisons():
from lona.html import Widget, Span, Node, Div
from lona.html.text_node import TextNode

class TestWidget(Widget):
def __init__(self, *nodes, **widget_data):
self.nodes = nodes
self.data = widget_data

# simple comparison
assert Div() == Div()
assert Div() is not Div()
assert Div() != Widget()
assert Div() != TextNode('')

# text nodes
assert TextNode('foo') == TextNode('foo')
assert TextNode('foo') != TextNode('bar')
assert TextNode('foo') is not TextNode('foo')

# legacy widgets
# TODO: remove in 2.0
assert TestWidget() == TestWidget()

assert TestWidget(Div()) == TestWidget(Div())
assert TestWidget(Div()) != TestWidget(Span())

assert TestWidget(foo=1) == TestWidget(foo=1)
assert TestWidget(foo=1) != TestWidget()
assert TestWidget(foo=1) != TestWidget(foo=2)
assert TestWidget(foo=1) != TestWidget(foo=1, bar=2)

# non node comparisons
assert Div() != 'Div'
assert Div() != object()

# namespace
assert Div() != Div(namespace='foo')
assert Div(namespace='foo') != Div(namespace='bar')

# tag name
assert Div() != Span()
assert Node(tag_name='div') != Node(tag_name='span')

# id list
assert Div(_id='foo') == Div(_id='foo')
assert Div(_id='foo') != Div()
assert Div(_id='foo') != Div(_id='foo bar')

# class list
assert Div(_class='foo') == Div(_class='foo')
assert Div(_class='foo') != Div()
assert Div(_class='foo') != Div(_class='foo bar')

# style
assert Div(style={'color': 'red'}) == Div(style={'color': 'red'})
assert Div(style={'color': 'red'}) != Div(style={'color': 'blue'})
assert Div(style={'color': 'red'}) != Div(style={'color': 'red', 'a': 'b'})

# attributes
assert Div(a=1) == Div(a=1)
assert Div(a=1) != Div(a=2)
assert Div(a=1) != Div(a=1, b=2)

# sub nodes
assert Div(Div()) == Div(Div())
assert Div(Div()) != Div(Div(a=1))
assert Div(Div()) != Div(Div(Span()))
assert Div(Div()) != Div()

# widget
assert Div(widget='foo') == Div(widget='foo')
assert Div(widget='foo') != Div()

# widget data
assert Div(widget_data=['foo']) == Div(widget_data=['foo'])
assert Div(widget_data=['foo']) != Div(widget_data=['foo', 'bar'])
assert Div(widget_data=['foo']) != Div()

0 comments on commit b1b30f3

Please sign in to comment.