A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

67 lines
2.5 KiB

  1. # Copyright (C) 2012-2020 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. # SOFTWARE.
  20. import pytest
  21. from mwparserfromhell.nodes import Text
  22. class TestText:
  23. """Test cases for the Text node."""
  24. def test_str(self):
  25. """test Text.__str__()"""
  26. node = Text("foobar")
  27. assert "foobar" == str(node)
  28. node2 = Text("fóóbar")
  29. assert "fóóbar" == str(node2)
  30. def test_children(self):
  31. """test Text.__children__()"""
  32. node = Text("foobar")
  33. gen = node.__children__()
  34. with pytest.raises(StopIteration):
  35. next(gen)
  36. def test_strip(self):
  37. """test Text.__strip__()"""
  38. node = Text("foobar")
  39. assert node is node.__strip__()
  40. def test_showtree(self):
  41. """test Text.__showtree__()"""
  42. output = []
  43. node1 = Text("foobar")
  44. node2 = Text("fóóbar")
  45. node3 = Text("𐌲𐌿𐍄")
  46. node1.__showtree__(output.append, None, None)
  47. node2.__showtree__(output.append, None, None)
  48. node3.__showtree__(output.append, None, None)
  49. res = ["foobar", r"f\xf3\xf3bar", "\\U00010332\\U0001033f\\U00010344"]
  50. assert res == output
  51. def test_value(self):
  52. """test getter/setter for the value attribute"""
  53. node = Text("foobar")
  54. assert "foobar" == node.value
  55. assert isinstance(node.value, str)
  56. node.value = "héhéhé"
  57. assert "héhéhé" == node.value
  58. assert isinstance(node.value, str)