Skip to content

Commit 3514e04

Browse files
committed
fix code match and add tests
1 parent 4a52dd7 commit 3514e04

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

tests/test_code_extraction.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ def test_code_block(self):
6868
'ijkl'
6969
""")
7070
self.assertEqual(result['code'], expected_code.strip())
71-
72-
# 验证清理后的文本
73-
expected_text = """
74-
I have the following string:
75-
How can I get the last four characters and store them in a string using Python?
76-
Like this:
77-
"""
78-
self.assertEqual(result['text'], text)
7971
self.assertEqual(result['formula'], '')
8072

8173
# def test_code_with_leading_trailing_spaces(self):
@@ -92,5 +84,28 @@ def test_code_block(self):
9284
# self.assertEqual(result['code'], '') # 不应该匹配多行行内代码
9385
# self.assertEqual(result['text'], text) # 原样保留
9486

87+
def test_indent_code_block(self):
88+
"""测试代码块"""
89+
text = """
90+
I have the following string: `"aaaabbbb"`
91+
How can I get the last four characters and store them in a string using Python?
92+
Like this:
93+
94+
print("hello world")
95+
print("hi")
96+
97+
"""
98+
99+
result = BaseMetric._extract_from_markdown(text)
100+
101+
# 验证提取的代码
102+
expected_code = ("""
103+
print("hello world")
104+
print("hi")
105+
""")
106+
self.assertEqual(result['code'], expected_code.strip())
107+
self.assertEqual(result['formula'], '')
108+
109+
95110
if __name__ == '__main__':
96111
unittest.main()

0 commit comments

Comments
 (0)