Coverage for hdl_registers/test/unit/test_html_translator.py: 100%

49 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-09-29 22:03 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the hdl_registers project, a HDL register generator fast enough to be run 

5# in real time. 

6# https://hdl-registers.com 

7# https://gitlab.com/tsfpga/hdl_registers 

8# -------------------------------------------------------------------------------------------------- 

9 

10import unittest 

11 

12from hdl_registers.html_translator import HtmlTranslator 

13 

14 

15class TestTranslator(unittest.TestCase): 

16 def setUp(self): 

17 self.html_translator = HtmlTranslator() 

18 

19 def test_markdown_parser_can_handle_annotating_sentences(self): 

20 expected = "This sentence <strong>should have a large portion</strong> in bold face" 

21 text = r"This sentence **should have a large portion** in bold face" 

22 assert expected in self.html_translator.translate(text) 

23 

24 expected = "This sentence <em>should have a large portion</em> in italics" 

25 text = "This sentence *should have a large portion* in italics" 

26 assert expected in self.html_translator.translate(text) 

27 

28 def test_markdown_parser_can_handle_escaped_asterisks(self): 

29 expected = "Part of this sentence **should be surrounded** by double asterisks" 

30 text = r"Part of this sentence \*\*should be surrounded\*\* by double asterisks" 

31 assert expected in self.html_translator.translate(text) 

32 

33 expected = "Part of this sentence *should be surrounded* by asterisks" 

34 text = r"Part of this sentence \*should be surrounded\* by asterisks" 

35 assert expected in self.html_translator.translate(text) 

36 

37 expected = ( 

38 "Part of this sentence <em>*should be in italics and surrounded*</em> by asterisks" 

39 ) 

40 text = r"Part of this sentence *\*should be in italics and surrounded\** by asterisks" 

41 assert expected in self.html_translator.translate(text) 

42 

43 expected = ( 

44 "Part of this sentence *<em>should be in italics and surrounded</em>* by asterisks" 

45 ) 

46 text = r"Part of this sentence \**should be in italics and surrounded*\* by asterisks" 

47 assert expected in self.html_translator.translate(text) 

48 

49 expected = "Part of this sentence should have an <em>*</em> in italics" 

50 text = r"Part of this sentence should have an *\** in italics" 

51 assert expected in self.html_translator.translate(text) 

52 

53 def test_line_breaks(self): 

54 expected = "Two empty lines<br />\n<br />\nbetween paragraphs." 

55 text = "Two empty lines\n\nbetween paragraphs." 

56 assert expected in self.html_translator.translate(text) 

57 

58 expected = "Three empty lines<br />\n<br />\nbetween paragraphs." 

59 text = "Three empty lines\n\n\nbetween paragraphs." 

60 assert expected in self.html_translator.translate(text) 

61 

62 expected = r"Escaped \n\n\n should not result in paragraph break." 

63 text = r"Escaped \n\n\n should not result in paragraph break." 

64 assert expected in self.html_translator.translate(text) 

65 

66 expected = "One empty line means same paragraph." 

67 text = "One empty line\nmeans same paragraph." 

68 assert expected in self.html_translator.translate(text) 

69 

70 def test_literal_underscore_can_be_used(self): 

71 # We do not translate underscores, unlike some markdown 

72 expected = "This sentence <strong>contains_underscores</strong> in some_places" 

73 text = r"This sentence **contains_underscores** in some_places" 

74 assert expected in self.html_translator.translate(text) 

75 

76 def test_angle_brackets_should_be_translated_to_html(self): 

77 expected = "This string &lt;&lt; contains &gt; brackets &gt;&lt;" 

78 text = "This string << contains > brackets ><" 

79 assert expected in self.html_translator.translate(text)