mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 01:19:31 +08:00
Models often close a fenced block on the same line as the last content. Require only an optional newline before the closing fence so mermaid and chart payloads are extracted instead of returned still-fenced.
17 lines
588 B
Python
17 lines
588 B
Python
"""Regression tests for visualize.utils.extract_code_block."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from deeptutor.agents.visualize.utils import extract_code_block
|
|
|
|
|
|
def test_extract_code_block_closing_fence_without_leading_newline() -> None:
|
|
raw = "```mermaid\ngraph TD\n A-->B```"
|
|
assert extract_code_block(raw, "mermaid") == "graph TD\n A-->B"
|
|
assert extract_code_block(raw) == "graph TD\n A-->B"
|
|
|
|
|
|
def test_extract_code_block_normal_fenced_block() -> None:
|
|
raw = "```javascript\nconst x = 1;\n```"
|
|
assert extract_code_block(raw, "javascript") == "const x = 1;"
|