1+ import textwrap
2+ import unittest
3+
14from codeinclude .resolver import select
25
36CODE_BLOCK_EXAMPLE = """
811this is a trailing line
912"""
1013
11- def test_lines ():
12- result = select (CODE_BLOCK_EXAMPLE , lines = "2,6" )
13- assert result == ("this is the first line\n "
14- "\n "
15- "⋯\n "
16- "\n "
17- "this is a trailing line\n " )
18-
19- def test_inside_block ():
20- result = select (CODE_BLOCK_EXAMPLE , inside_block = "blockstarter" )
21- assert result == " block content\n "
22-
23- def test_whole_block ():
24- result = select (CODE_BLOCK_EXAMPLE , block = "blockstarter" )
25- assert result == ("blockstarter {\n "
26- " block content\n "
27- "}\n " )
14+
15+ class ResolverTest (unittest .TestCase ):
16+ def test_lines (self ):
17+ result = select (CODE_BLOCK_EXAMPLE , lines = "2,6" )
18+ self .assertEquals (("this is the first line\n "
19+ "\n "
20+ "⋯\n "
21+ "\n "
22+ "this is a trailing line\n " ),
23+ result )
24+
25+ def test_inside_block (self ):
26+ result = select (CODE_BLOCK_EXAMPLE , inside_block = "blockstarter" )
27+ self .assertEquals (" block content\n " , result )
28+
29+ def test_whole_block (self ):
30+ result = select (CODE_BLOCK_EXAMPLE , block = "blockstarter" )
31+ self .assertEquals (("blockstarter {\n "
32+ " block content\n "
33+ "}\n " ),
34+ result )
35+
36+ def test_inside_block_content_on_last_line (self ):
37+ result = select (
38+ textwrap .dedent (
39+ """
40+ foo {
41+ if (true) {
42+ bar();
43+ } }
44+ /* The line above contains both the closing curly bracket for `if` and for `foo` */
45+ """ ),
46+ inside_block = "foo" )
47+ self .assertEquals ((" if (true) {\n "
48+ " bar();\n " ),
49+ result )
50+
51+ def test_inside_block_curly_on_same_line (self ):
52+ result = select (
53+ textwrap .dedent (
54+ """
55+ foo {
56+ /* {} */
57+ }
58+ """ ),
59+ inside_block = "foo" )
60+ self .assertEquals (" /* {} */\n " , result )
61+
62+ def test_inside_block_multiple_curly_on_same_line (self ):
63+ result = select (
64+ textwrap .dedent (
65+ """
66+ //
67+ foo {
68+ /* {} {@code bar} {@link baz} */
69+ }
70+ """ ),
71+ inside_block = "foo" )
72+ self .assertEquals (" /* {} {@code bar} {@link baz} */\n " , result )
0 commit comments