MCPcopy
hub / github.com/yjs/yjs / testBasicFormat

Function testBasicFormat

tests/y-text.tests.js:1291–1324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1289 * @param {t.TestCase} tc
1290 */
1291export const testBasicFormat = tc => {
1292 const { users, text0 } = init(tc, { users: 2 })
1293 let eventDelta
1294 text0.observe(event => {
1295 eventDelta = event.delta
1296 })
1297 text0.insert(0, 'abc', { bold: true })
1298 t.assert(text0.toString() === 'abc', 'Basic insert with attributes works')
1299 t.compare(text0.toDelta(), delta.create().insert('abc', { bold: true }).done())
1300 t.compare(eventDelta, delta.create().insert('abc', { bold: true }))
1301 text0.delete(0, 1)
1302 t.assert(text0.toString() === 'bc', 'Basic delete on formatted works (position 0)')
1303 t.compare(text0.toDelta(), delta.create().insert('bc', { bold: true }).done())
1304 t.compare(eventDelta, delta.create().delete(1))
1305 text0.delete(1, 1)
1306 t.assert(text0.toString() === 'b', 'Basic delete works (position 1)')
1307 t.compare(text0.toDelta(), delta.create().insert('b', { bold: true }).done())
1308 t.compare(eventDelta, delta.create().retain(1).delete(1))
1309 text0.insert(0, 'z', { bold: true })
1310 t.assert(text0.toString() === 'zb')
1311 t.compare(text0.toDelta(), delta.create().insert('zb', { bold: true }).done())
1312 t.compare(eventDelta, delta.create().insert('z', { bold: true }))
1313 // @ts-ignore
1314 t.assert(text0._start.right.right.right.content.str === 'b', 'Does not insert duplicate attribute marker')
1315 text0.insert(0, 'y')
1316 t.assert(text0.toString() === 'yzb')
1317 t.compare(text0.toDelta(), delta.create().insert('y').insert('zb', { bold: true }).done())
1318 t.compare(eventDelta, delta.create().insert('y'))
1319 text0.format(0, 2, { bold: null })
1320 t.assert(text0.toString() === 'yzb')
1321 t.compare(text0.toDelta(), delta.create().insert('yz').insert('b', { bold: true }).done())
1322 t.compare(eventDelta, delta.create().retain(1).retain(1, { bold: null }))
1323 compare(users)
1324}
1325
1326/**
1327 * @param {t.TestCase} tc

Callers

nothing calls this directly

Calls 8

initFunction · 0.85
compareFunction · 0.85
observeMethod · 0.80
insertMethod · 0.80
toStringMethod · 0.80
toDeltaMethod · 0.80
formatMethod · 0.80
deleteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…