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

49 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-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/hdl_registers/hdl_registers 

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

9 

10# Standard libraries 

11import unittest 

12 

13# First party libraries 

14from hdl_registers.html_translator import HtmlTranslator 

15 

16 

17class TestTranslator(unittest.TestCase): 

18 def setUp(self): 

19 self.html_translator = HtmlTranslator() 

20 

21 def test_markdown_parser_can_handle_annotating_sentences(self): 

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

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

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

25 

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

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

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

29 

30 def test_markdown_parser_can_handle_escaped_asterisks(self): 

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

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

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

34 

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

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

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

38 

39 expected = ( 

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

41 ) 

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

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

44 

45 expected = ( 

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

47 ) 

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

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

50 

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

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

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

54 

55 def test_line_breaks(self): 

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

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

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

59 

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

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

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

63 

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

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

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

67 

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

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

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

71 

72 def test_literal_underscore_can_be_used(self): 

73 # We do not translate underscores, unlike some markdown 

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

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

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

77 

78 def test_angle_brackets_should_be_translated_to_html(self): 

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

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

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