MCPcopy Index your code
hub / github.com/webpy/webpy / test_parser

Function test_parser

web/db.py:1704–1733  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1702
1703
1704def test_parser():
1705 def f(text, expected):
1706 p = Parser()
1707 nodes = list(p.parse(text))
1708 print(repr(text), nodes)
1709 assert nodes == expected, "Expected %r" % expected
1710
1711 f("Hello", [_Node("text", "Hello")])
1712 f("Hello $name", [_Node("text", "Hello "), _Node("param", "name")])
1713 f(
1714 "Hello $name.foo",
1715 [_Node("text", "Hello "), _Node("getattr", _Node("param", "name"), "foo")],
1716 )
1717 f(
1718 "WHERE id=$self.id LIMIT 1",
1719 [
1720 _Node("text", "WHERE id="),
1721 _Node("getattr", _Node("param", "self", None), "id"),
1722 _Node("text", " LIMIT 1"),
1723 ],
1724 )
1725
1726 f(
1727 "WHERE id=$self['id'] LIMIT 1",
1728 [
1729 _Node("text", "WHERE id="),
1730 _Node("getitem", _Node("param", "self", None), _Node("literal", "'id'")),
1731 _Node("text", " LIMIT 1"),
1732 ],
1733 )
1734
1735
1736def test_safeeval():

Callers 1

db.pyFile · 0.85

Calls 2

fFunction · 0.85
_NodeClass · 0.85

Tested by

no test coverage detected