8 # comment string for Elisp
11 # simulate calling from pylit main
12 keyw
= { 'comment_string':COMMENT_STRING
}
19 def test(actual_iter
, expected_iter
):
20 """Compare all lines in `actual_iter` with lines in `expected_iter`"""
22 for line
in actual_iter
:
25 for line
in expected_iter
:
27 if len(actual
) == len(expected
):
31 for i
in range(0, min(len(actual
),len(expected
))):
32 if actual
[i
] != expected
[i
]:
37 return "Failed (expected: %s, got: %s)" \
45 sc_in
= IdentityFilter([
46 ";; This should be stripped.\n",
47 "This should be not.\n"
49 sc_out
= IdentityFilter([
50 "This should be stripped.\n",
51 "This should be not.\n"
54 blank_lines
= IdentityFilter([
60 c2t_in_1
= IdentityFilter([
63 c2t_out_1
= IdentityFilter([
64 ";; .. |elisp> ;;;Commentary:\n",
66 c2t_in_2
= IdentityFilter([
71 c2t_out_2
= IdentityFilter([
72 ";; .. |elisp> ;;;Commentary:\n",
82 # test ElispCode2TextFilter with one sample line
83 f
= ElispCode2TextFilter(c2t_in_1
, **keyw
)
84 print "ElispCode2TextFilter with sample line: %s" \
87 # test ElispText2CodeFilter with one sample line
88 f
= ElispText2CodeFilter(c2t_out_1
, **keyw
)
89 print "ElispText2CodeFilter with sample line: %s" \
92 # test ElispCode2TextFilter with one sample para
93 f
= ElispCode2TextFilter(c2t_in_2
, **keyw
)
94 print "ElispCode2TextFilter with sample paragraph: %s" \
97 # test ElispText2CodeFilter with one sample para
98 f
= ElispText2CodeFilter(c2t_out_2
, **keyw
)
99 print "ElispText2CodeFilter with sample paragraph: %s" \
102 # round-trip test code->txt->code with sample line
103 f
= ElispText2CodeFilter(ElispCode2TextFilter(c2t_in_1
, **keyw
), **keyw
)
104 print "round-trip test code->txt->code with sample line: %s" \
107 # round-trip test code->txt->code with sample line
108 f
= ElispCode2TextFilter(ElispText2CodeFilter(c2t_out_1
, **keyw
), **keyw
)
109 print "round-trip test txt->code->txt with sample line: %s" \
112 # DISABLED 2007-02-21 -- these need the reverse of strip_comments(),
113 # that is a function that prefix comment_string to non-code lines.
114 # But that would be duplicating PyLit's code here, so just forget it.
116 # round-trip test code->txt->code with sample para
117 #f = ElispText2CodeFilter(IdentityFilter(ElispCode2TextFilter(c2t_in_2,
119 #print "round-trip test code->txt->code with sample paragraph: %s" \
120 # % test(f, c2t_in_2)
122 # round-trip test code->txt->code with sample para
123 #f = strip_comments(ElispCode2TextFilter(
124 # strip_indent(ElispText2CodeFilter(c2t_out_2, **keyw)), **keyw))
125 #print "round-trip test txt->code->txt with sample paragraph: %s" \
126 # % test(f, c2t_out_2)
128 # txt->code should preserve blank lines
129 f
= ElispText2CodeFilter(blank_lines
, **keyw
)
130 print "txt->code with blank lines: %s" \
131 % test(f
, blank_lines
)
133 # code->txt should preserve blank lines
134 f
= ElispCode2TextFilter(blank_lines
, **keyw
)
135 print "code->txt with blank lines: %s" \
136 % test(f
, blank_lines
)
138 # round-trip test txt->code->txt
139 f
= ElispText2CodeFilter(ElispCode2TextFilter(blank_lines
, **keyw
), **keyw
)
140 print "round-trip test txt->code->txt with blank lines: %s" \
141 % test(f
, blank_lines
)
143 # round-trip test code->txt->code
144 f
= ElispCode2TextFilter(ElispText2CodeFilter(blank_lines
, **keyw
), **keyw
)
145 print "round-trip test txt->code->txt with blank lines: %s" \
146 % test(f
, blank_lines
)