✨ feat(vscode): 代码阅读的输入参数排成带表头和边框的表格
This commit is contained in:
1 parent
6416cdf714
commit
83adefdf5e
10 files changed
+197
-24
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import type { PropertyRow } from './types'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { toBlockViews } from '../../../src/codeReader/blockView'
|
||||
import { createPythonAdapter } from '../../../src/codeReader/languages/python'
|
||||
import { WASM_DIR, withBlocks } from '../../../src/codeReader/testSupport'
|
||||
import { pythonZhTranslator } from '../../../src/codeReader/translators/pythonZh'
|
||||
import { subRowsLayout, tableCells } from './subRows'
|
||||
|
||||
const x = { text: 'x', role: 'variable' as const, offset: 4 }
|
||||
|
||||
describe('属性行下面的子行怎么排', () => {
|
||||
it('给了列名的排成表格,没给的排成列表,没有子行的不展开', () => {
|
||||
const items = [{ cells: [[x], []] }]
|
||||
expect(subRowsLayout({ label: '输入参数', value: [], items, columns: ['名称', '类型', '默认值'] })).toBe('table')
|
||||
expect(subRowsLayout({ label: '导入项', value: [], items })).toBe('list')
|
||||
expect(subRowsLayout({ label: '输入参数', value: [], items: [], columns: ['名称', '类型', '默认值'] })).toBeUndefined()
|
||||
expect(subRowsLayout({ label: '名称', value: [x] })).toBeUndefined()
|
||||
})
|
||||
|
||||
it('表格的格子按列名的列数取:少给的留空,多给的不显示', () => {
|
||||
expect(tableCells({ cells: [[x]] }, ['名称', '类型', '默认值'])).toEqual([[x], [], []])
|
||||
expect(tableCells({ cells: [[x], [x], [x], [x]] }, ['名称', '类型'])).toEqual([[x], [x]])
|
||||
})
|
||||
|
||||
it('真实的 Python 函数:输入参数排成表格,导入项、字典的各项排成列表', async () => {
|
||||
const source = [
|
||||
'from m import a',
|
||||
'def f(k: int, v=1): pass',
|
||||
'D = {"k": 1}',
|
||||
].join('\n')
|
||||
const py = createPythonAdapter(WASM_DIR)
|
||||
const views = await withBlocks(py, 'python', source, blocks => toBlockViews(blocks, source, py, pythonZhTranslator))
|
||||
const layouts = views.flatMap(view => 'properties' in view ? view.properties.flatMap((row: PropertyRow) => subRowsLayout(row) ? [[row.label, subRowsLayout(row)]] : []) : [])
|
||||
expect(layouts).toEqual([['导入项', 'list'], ['输入参数', 'table'], ['值', 'list']])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user