1+ import textwrap
12import pytest
23from pywire_language_server .transpiler import Transpiler
34
@@ -12,14 +13,14 @@ def test_transpile_simple_interpolation():
1213 # This assertion is vague, we'll refine it as we implement.
1314
1415def test_transpile_python_section ():
15- source = """
16- ---
17- x = 1
18- def foo():
19- pass
20- ---
21- <h1>Hi</h1>
22- """
16+ source = textwrap . dedent ( """
17+ ---
18+ x = 1
19+ def foo():
20+ pass
21+ ---
22+ <h1>Hi</h1>
23+ """). strip ()
2324 transpiler = Transpiler (source )
2425 code , _ = transpiler .transpile ()
2526
@@ -36,22 +37,24 @@ def test_transpile_directive():
3637 assert "'/home'" in code
3738
3839def test_transpile_multiline_interpolation ():
39- source = """<div class={
40- 'active' if True
41- else 'inactive'
42- }></div>"""
40+ source = textwrap .dedent ("""
41+ <div class={
42+ 'active' if True
43+ else 'inactive'
44+ }></div>
45+ """ ).strip ()
4346 transpiler = Transpiler (source )
4447 code , _ = transpiler .transpile ()
4548
4649 assert "'active' if True" in code
4750 assert "else 'inactive'" in code
4851
4952def test_transpile_wrappers ():
50- source = """
51- <div $if={x > 1}></div>
52- <div $for={i in items}></div>
53- <div @click={do_something()}></div>
54- """
53+ source = textwrap . dedent ( """
54+ <div $if={x > 1}></div>
55+ <div $for={i in items}></div>
56+ <div @click={do_something()}></div>
57+ """ ). strip ()
5558 transpiler = Transpiler (source )
5659 code , _ = transpiler .transpile ()
5760
@@ -63,16 +66,16 @@ def test_transpile_wrappers():
6366
6467def test_explicit_property_mapping ():
6568 """Test that {count.value} maps 'count' correctly."""
66- source = """
67- ---
68- count = wire(0)
69- ---
70- <p>{count.value}</p>
71- """
69+ source = textwrap . dedent ( """
70+ ---
71+ count = wire(0)
72+ ---
73+ <p>{count.value}</p>
74+ """). strip ()
7275 transpiler = Transpiler (source )
7376 code , source_map = transpiler .transpile ()
7477
75- usage_line = 4
78+ usage_line = 3
7679 usage_col_start = 4 # { is at 3, count at 4
7780
7881 gen_loc = source_map .to_generated (usage_line , usage_col_start )
@@ -87,19 +90,19 @@ def test_explicit_property_mapping():
8790
8891def test_event_handler_mapping ():
8992 """Test @click={count.value += 1} mapping."""
90- source = """
91- ---
92- count = wire(0)
93- ---
94- <button @click={count.value += 1}>Inc</button>
95- """
93+ source = textwrap . dedent ( """
94+ ---
95+ count = wire(0)
96+ ---
97+ <button @click={count.value += 1}>Inc</button>
98+ """). strip ()
9699 transpiler = Transpiler (source )
97100 code , source_map = transpiler .transpile ()
98101
99102 # Usage: {count.value}
100103 # <button @click={count...
101104 # c is at 16.
102- usage_line = 4
105+ usage_line = 3
103106 usage_col_start = 16
104107
105108 gen_loc = source_map .to_generated (usage_line , usage_col_start )
0 commit comments