@xincli/opentui-core 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (476) hide show
  1. package/README.md +63 -0
  2. package/dev/keypress-debug-renderer.ts +148 -0
  3. package/dev/keypress-debug.ts +43 -0
  4. package/dev/print-env-vars.ts +32 -0
  5. package/dev/test-tmux-graphics-334.sh +68 -0
  6. package/dev/test-tmux-theme-queries.sh +151 -0
  7. package/dev/thai-debug-test.ts +68 -0
  8. package/dev/theme-mode.ts +290 -0
  9. package/docs/development.md +144 -0
  10. package/package.json +102 -0
  11. package/prebuilt/aarch64-android/libopentui.so +0 -0
  12. package/scripts/build-android.ts +226 -0
  13. package/scripts/build-native-termux.sh +525 -0
  14. package/scripts/build.ts +530 -0
  15. package/scripts/dist-test.ts +312 -0
  16. package/scripts/package-prebuilt.ts +110 -0
  17. package/scripts/publish.ts +60 -0
  18. package/scripts/test-node-hook.mjs +16 -0
  19. package/scripts/test-node.ts +241 -0
  20. package/scripts/vendor-deps.sh +73 -0
  21. package/src/NativeSpanFeed.ts +375 -0
  22. package/src/Renderable.ts +1878 -0
  23. package/src/__snapshots__/buffer.test.ts.snap +28 -0
  24. package/src/animation/Timeline.test.ts +2709 -0
  25. package/src/animation/Timeline.ts +598 -0
  26. package/src/ansi.ts +22 -0
  27. package/src/audio.ts +479 -0
  28. package/src/benchmark/attenuation-benchmark.ts +81 -0
  29. package/src/benchmark/audio-playback-benchmark.ts +344 -0
  30. package/src/benchmark/box-draw-benchmark.ts +1042 -0
  31. package/src/benchmark/colormatrix-benchmark.ts +123 -0
  32. package/src/benchmark/gain-benchmark.ts +80 -0
  33. package/src/benchmark/latest-all-bench-run.json +707 -0
  34. package/src/benchmark/latest-async-bench-run.json +336 -0
  35. package/src/benchmark/latest-default-bench-run.json +657 -0
  36. package/src/benchmark/latest-large-bench-run.json +707 -0
  37. package/src/benchmark/latest-quick-bench-run.json +207 -0
  38. package/src/benchmark/layout-benchmark.ts +2547 -0
  39. package/src/benchmark/markdown-benchmark.ts +1796 -0
  40. package/src/benchmark/native-span-feed-async-benchmark.ts +355 -0
  41. package/src/benchmark/native-span-feed-benchmark.md +56 -0
  42. package/src/benchmark/native-span-feed-benchmark.ts +596 -0
  43. package/src/benchmark/native-span-feed-compare.ts +280 -0
  44. package/src/benchmark/render-traversal-benchmark.ts +928 -0
  45. package/src/benchmark/text-buffer-render-benchmark.ts +874 -0
  46. package/src/benchmark/text-table-benchmark.ts +948 -0
  47. package/src/buffer.test.ts +292 -0
  48. package/src/buffer.ts +564 -0
  49. package/src/console.test.ts +629 -0
  50. package/src/console.ts +1253 -0
  51. package/src/edit-buffer.test.ts +1852 -0
  52. package/src/edit-buffer.ts +417 -0
  53. package/src/editor-view.test.ts +1056 -0
  54. package/src/editor-view.ts +290 -0
  55. package/src/index.ts +25 -0
  56. package/src/lib/KeyHandler.integration.test.ts +292 -0
  57. package/src/lib/KeyHandler.stopPropagation.test.ts +289 -0
  58. package/src/lib/KeyHandler.test.ts +662 -0
  59. package/src/lib/KeyHandler.ts +222 -0
  60. package/src/lib/RGBA.test.ts +60 -0
  61. package/src/lib/RGBA.ts +343 -0
  62. package/src/lib/ascii.font.ts +330 -0
  63. package/src/lib/border.test.ts +83 -0
  64. package/src/lib/border.ts +170 -0
  65. package/src/lib/bunfs.test.ts +27 -0
  66. package/src/lib/bunfs.ts +18 -0
  67. package/src/lib/clipboard.test.ts +63 -0
  68. package/src/lib/clipboard.ts +41 -0
  69. package/src/lib/clock.ts +35 -0
  70. package/src/lib/data-paths.test.ts +133 -0
  71. package/src/lib/data-paths.ts +109 -0
  72. package/src/lib/debounce.ts +106 -0
  73. package/src/lib/detect-links.test.ts +98 -0
  74. package/src/lib/detect-links.ts +56 -0
  75. package/src/lib/env.test.ts +228 -0
  76. package/src/lib/env.ts +209 -0
  77. package/src/lib/extmarks-history.ts +51 -0
  78. package/src/lib/extmarks-multiwidth.test.ts +324 -0
  79. package/src/lib/extmarks.test.ts +3547 -0
  80. package/src/lib/extmarks.ts +861 -0
  81. package/src/lib/fonts/block.json +405 -0
  82. package/src/lib/fonts/grid.json +265 -0
  83. package/src/lib/fonts/huge.json +741 -0
  84. package/src/lib/fonts/pallet.json +314 -0
  85. package/src/lib/fonts/shade.json +591 -0
  86. package/src/lib/fonts/slick.json +321 -0
  87. package/src/lib/fonts/tiny.json +69 -0
  88. package/src/lib/hast-styled-text.ts +59 -0
  89. package/src/lib/index.ts +22 -0
  90. package/src/lib/keybinding.internal.test.ts +342 -0
  91. package/src/lib/keybinding.internal.ts +182 -0
  92. package/src/lib/objects-in-viewport.test.ts +789 -0
  93. package/src/lib/objects-in-viewport.ts +153 -0
  94. package/src/lib/output.capture.ts +58 -0
  95. package/src/lib/parse.keypress-kitty.protocol.test.ts +347 -0
  96. package/src/lib/parse.keypress-kitty.test.ts +712 -0
  97. package/src/lib/parse.keypress-kitty.ts +470 -0
  98. package/src/lib/parse.keypress.test.ts +2020 -0
  99. package/src/lib/parse.keypress.ts +480 -0
  100. package/src/lib/parse.mouse.test.ts +552 -0
  101. package/src/lib/parse.mouse.ts +232 -0
  102. package/src/lib/paste.ts +18 -0
  103. package/src/lib/queue.ts +65 -0
  104. package/src/lib/render-geometry.ts +36 -0
  105. package/src/lib/renderable.validations.test.ts +87 -0
  106. package/src/lib/renderable.validations.ts +83 -0
  107. package/src/lib/scroll-acceleration.ts +98 -0
  108. package/src/lib/selection.ts +261 -0
  109. package/src/lib/singleton.ts +34 -0
  110. package/src/lib/stdin-parser.test.ts +2439 -0
  111. package/src/lib/stdin-parser.ts +2007 -0
  112. package/src/lib/styled-text.ts +178 -0
  113. package/src/lib/terminal-capability-detection.test.ts +226 -0
  114. package/src/lib/terminal-capability-detection.ts +98 -0
  115. package/src/lib/terminal-palette.test.ts +954 -0
  116. package/src/lib/terminal-palette.ts +441 -0
  117. package/src/lib/tree-sitter/assets/README.md +119 -0
  118. package/src/lib/tree-sitter/assets/javascript/highlights.scm +205 -0
  119. package/src/lib/tree-sitter/assets/javascript/tree-sitter-javascript.wasm +0 -0
  120. package/src/lib/tree-sitter/assets/markdown/highlights.scm +150 -0
  121. package/src/lib/tree-sitter/assets/markdown/injections.scm +27 -0
  122. package/src/lib/tree-sitter/assets/markdown/tree-sitter-markdown.wasm +0 -0
  123. package/src/lib/tree-sitter/assets/markdown_inline/highlights.scm +115 -0
  124. package/src/lib/tree-sitter/assets/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  125. package/src/lib/tree-sitter/assets/typescript/highlights.scm +604 -0
  126. package/src/lib/tree-sitter/assets/typescript/tree-sitter-typescript.wasm +0 -0
  127. package/src/lib/tree-sitter/assets/update.ts +360 -0
  128. package/src/lib/tree-sitter/assets/zig/highlights.scm +284 -0
  129. package/src/lib/tree-sitter/assets/zig/tree-sitter-zig.wasm +0 -0
  130. package/src/lib/tree-sitter/assets.d.ts +9 -0
  131. package/src/lib/tree-sitter/cache.test.ts +291 -0
  132. package/src/lib/tree-sitter/client.test.ts +1434 -0
  133. package/src/lib/tree-sitter/client.ts +847 -0
  134. package/src/lib/tree-sitter/default-parsers.ts +133 -0
  135. package/src/lib/tree-sitter/download-utils.ts +148 -0
  136. package/src/lib/tree-sitter/index.ts +75 -0
  137. package/src/lib/tree-sitter/parser.worker.ts +1098 -0
  138. package/src/lib/tree-sitter/parsers-config.ts +81 -0
  139. package/src/lib/tree-sitter/resolve-ft.test.ts +55 -0
  140. package/src/lib/tree-sitter/resolve-ft.ts +189 -0
  141. package/src/lib/tree-sitter/types.ts +132 -0
  142. package/src/lib/tree-sitter/update-assets.ts +10 -0
  143. package/src/lib/tree-sitter-styled-text.test.ts +1253 -0
  144. package/src/lib/tree-sitter-styled-text.ts +314 -0
  145. package/src/lib/validate-dir-name.ts +55 -0
  146. package/src/lib/yoga.options.test.ts +628 -0
  147. package/src/lib/yoga.options.ts +346 -0
  148. package/src/native-event-worker-repro.test.ts +48 -0
  149. package/src/native-event-worker-repro.worker.ts +9 -0
  150. package/src/native-handle.test.ts +221 -0
  151. package/src/platform/ffi.test.ts +516 -0
  152. package/src/platform/ffi.ts +653 -0
  153. package/src/platform/runtime.test.ts +52 -0
  154. package/src/platform/runtime.ts +121 -0
  155. package/src/platform/test.ts +45 -0
  156. package/src/platform/worker-handler-cleanup.fixture.ts +12 -0
  157. package/src/platform/worker-onmessage-startup.fixture.ts +10 -0
  158. package/src/platform/worker-startup.fixture.ts +9 -0
  159. package/src/platform/worker.node-test.ts +153 -0
  160. package/src/platform/worker.ts +425 -0
  161. package/src/plugins/core-slot.ts +579 -0
  162. package/src/plugins/registry.ts +402 -0
  163. package/src/plugins/types.ts +46 -0
  164. package/src/post/effects.ts +948 -0
  165. package/src/post/filters.ts +512 -0
  166. package/src/post/matrices.ts +288 -0
  167. package/src/renderables/ASCIIFont.ts +219 -0
  168. package/src/renderables/Box.test.ts +474 -0
  169. package/src/renderables/Box.ts +353 -0
  170. package/src/renderables/Code.test.ts +2388 -0
  171. package/src/renderables/Code.ts +555 -0
  172. package/src/renderables/Diff.regression.test.ts +381 -0
  173. package/src/renderables/Diff.test.ts +3212 -0
  174. package/src/renderables/Diff.ts +1278 -0
  175. package/src/renderables/EditBufferRenderable.test.ts +288 -0
  176. package/src/renderables/EditBufferRenderable.ts +1152 -0
  177. package/src/renderables/FrameBuffer.ts +47 -0
  178. package/src/renderables/Input.test.ts +1310 -0
  179. package/src/renderables/Input.ts +273 -0
  180. package/src/renderables/LineNumberRenderable.ts +725 -0
  181. package/src/renderables/Markdown.ts +2144 -0
  182. package/src/renderables/ScrollBar.ts +423 -0
  183. package/src/renderables/ScrollBox.ts +903 -0
  184. package/src/renderables/Select.test.ts +1134 -0
  185. package/src/renderables/Select.ts +535 -0
  186. package/src/renderables/Slider.test.ts +456 -0
  187. package/src/renderables/Slider.ts +342 -0
  188. package/src/renderables/TabSelect.test.ts +238 -0
  189. package/src/renderables/TabSelect.ts +447 -0
  190. package/src/renderables/Text.selection-buffer.test.ts +118 -0
  191. package/src/renderables/Text.test.ts +2662 -0
  192. package/src/renderables/Text.ts +147 -0
  193. package/src/renderables/TextBufferRenderable.ts +504 -0
  194. package/src/renderables/TextNode.test.ts +1137 -0
  195. package/src/renderables/TextNode.ts +379 -0
  196. package/src/renderables/TextTable.test.ts +1411 -0
  197. package/src/renderables/TextTable.ts +1434 -0
  198. package/src/renderables/Textarea.ts +425 -0
  199. package/src/renderables/TimeToFirstDraw.ts +89 -0
  200. package/src/renderables/__snapshots__/Code.test.ts.snap +13 -0
  201. package/src/renderables/__snapshots__/Diff.test.ts.snap +785 -0
  202. package/src/renderables/__snapshots__/Text.test.ts.snap +421 -0
  203. package/src/renderables/__snapshots__/TextTable.test.ts.snap +215 -0
  204. package/src/renderables/__tests__/Code.test.ts +55 -0
  205. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +144 -0
  206. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +827 -0
  207. package/src/renderables/__tests__/LineNumberRenderable.test.ts +1906 -0
  208. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +85 -0
  209. package/src/renderables/__tests__/Markdown.code-colors.test.ts +288 -0
  210. package/src/renderables/__tests__/Markdown.test.ts +4175 -0
  211. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +87 -0
  212. package/src/renderables/__tests__/Textarea.buffer.test.ts +683 -0
  213. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +675 -0
  214. package/src/renderables/__tests__/Textarea.editing.test.ts +2120 -0
  215. package/src/renderables/__tests__/Textarea.error-handling.test.ts +35 -0
  216. package/src/renderables/__tests__/Textarea.events.test.ts +738 -0
  217. package/src/renderables/__tests__/Textarea.highlights.test.ts +590 -0
  218. package/src/renderables/__tests__/Textarea.keybinding.test.ts +3275 -0
  219. package/src/renderables/__tests__/Textarea.paste.test.ts +357 -0
  220. package/src/renderables/__tests__/Textarea.rendering.test.ts +1927 -0
  221. package/src/renderables/__tests__/Textarea.scroll.test.ts +733 -0
  222. package/src/renderables/__tests__/Textarea.selection.test.ts +1589 -0
  223. package/src/renderables/__tests__/Textarea.stress.test.ts +670 -0
  224. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +383 -0
  225. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +310 -0
  226. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +221 -0
  227. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +89 -0
  228. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +457 -0
  229. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +158 -0
  230. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +387 -0
  231. package/src/renderables/__tests__/markdown-parser.test.ts +241 -0
  232. package/src/renderables/__tests__/renderable-test-utils.ts +60 -0
  233. package/src/renderables/composition/README.md +8 -0
  234. package/src/renderables/composition/VRenderable.ts +32 -0
  235. package/src/renderables/composition/constructs.ts +127 -0
  236. package/src/renderables/composition/vnode.ts +277 -0
  237. package/src/renderables/index.ts +23 -0
  238. package/src/renderables/markdown-parser.ts +79 -0
  239. package/src/renderer-theme-mode.ts +199 -0
  240. package/src/renderer.ts +4975 -0
  241. package/src/runtime-plugin-support-configure.ts +63 -0
  242. package/src/runtime-plugin-support.ts +13 -0
  243. package/src/runtime-plugin.ts +626 -0
  244. package/src/specs/terminal-startup.md +64 -0
  245. package/src/syntax-style.test.ts +841 -0
  246. package/src/syntax-style.ts +274 -0
  247. package/src/testing/README.md +219 -0
  248. package/src/testing/bun-test-node.ts +880 -0
  249. package/src/testing/capture-spans.test.ts +216 -0
  250. package/src/testing/integration.test.ts +276 -0
  251. package/src/testing/manual-clock.ts +117 -0
  252. package/src/testing/mock-keys.test.ts +1378 -0
  253. package/src/testing/mock-keys.ts +457 -0
  254. package/src/testing/mock-mouse.test.ts +218 -0
  255. package/src/testing/mock-mouse.ts +247 -0
  256. package/src/testing/mock-tree-sitter-client.ts +81 -0
  257. package/src/testing/spy.ts +13 -0
  258. package/src/testing/terminal-capabilities.ts +47 -0
  259. package/src/testing/test-recorder.test.ts +410 -0
  260. package/src/testing/test-recorder.ts +133 -0
  261. package/src/testing/test-renderer.ts +375 -0
  262. package/src/testing/test-renderer.wait.test.ts +278 -0
  263. package/src/testing/test-streams.ts +31 -0
  264. package/src/testing.ts +9 -0
  265. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +481 -0
  266. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +19 -0
  267. package/src/tests/__snapshots__/scrollbox.test.ts.snap +29 -0
  268. package/src/tests/absolute-positioning.snapshot.test.ts +638 -0
  269. package/src/tests/allocator-stats.test.ts +53 -0
  270. package/src/tests/audio.test.ts +303 -0
  271. package/src/tests/destroy-during-render.test.ts +200 -0
  272. package/src/tests/destroy-on-exit.fixture.ts +36 -0
  273. package/src/tests/destroy-on-exit.test.ts +62 -0
  274. package/src/tests/ffi-borrowed-pointer-callsites.test.ts +153 -0
  275. package/src/tests/hover-cursor.test.ts +98 -0
  276. package/src/tests/native-backed-measurement-lifecycle.test.ts +133 -0
  277. package/src/tests/native-backed-measurement-parity.test.ts +322 -0
  278. package/src/tests/native-span-feed-async.test.ts +173 -0
  279. package/src/tests/native-span-feed-close.test.ts +120 -0
  280. package/src/tests/native-span-feed-coverage.test.ts +227 -0
  281. package/src/tests/native-span-feed-edge-cases.test.ts +384 -0
  282. package/src/tests/native-span-feed-use-after-free.test.ts +45 -0
  283. package/src/tests/opacity.test.ts +123 -0
  284. package/src/tests/renderable.snapshot.test.ts +524 -0
  285. package/src/tests/renderable.test.ts +1851 -0
  286. package/src/tests/renderer.clock.test.ts +270 -0
  287. package/src/tests/renderer.console-startup.test.ts +2151 -0
  288. package/src/tests/renderer.control.test.ts +458 -0
  289. package/src/tests/renderer.core-slot-binding.test.ts +962 -0
  290. package/src/tests/renderer.cursor.test.ts +26 -0
  291. package/src/tests/renderer.custom-stdout.test.ts +1112 -0
  292. package/src/tests/renderer.destroy-during-render.test.ts +147 -0
  293. package/src/tests/renderer.focus-restore.test.ts +257 -0
  294. package/src/tests/renderer.focus.test.ts +329 -0
  295. package/src/tests/renderer.idle.test.ts +219 -0
  296. package/src/tests/renderer.input.test.ts +2615 -0
  297. package/src/tests/renderer.kitty-flags.test.ts +195 -0
  298. package/src/tests/renderer.lifecycle.test.ts +34 -0
  299. package/src/tests/renderer.mouse.test.ts +1315 -0
  300. package/src/tests/renderer.notifications.test.ts +27 -0
  301. package/src/tests/renderer.palette.test.ts +1199 -0
  302. package/src/tests/renderer.remote.test.ts +247 -0
  303. package/src/tests/renderer.render-stats.test.ts +146 -0
  304. package/src/tests/renderer.scrollback-surface.test.ts +474 -0
  305. package/src/tests/renderer.selection.test.ts +138 -0
  306. package/src/tests/renderer.slot-registry.test.ts +684 -0
  307. package/src/tests/renderer.tracker.test.ts +202 -0
  308. package/src/tests/renderer.useMouse.test.ts +83 -0
  309. package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +76 -0
  310. package/src/tests/runtime-plugin-node-modules-import-like-string.fixture.ts +48 -0
  311. package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +43 -0
  312. package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +67 -0
  313. package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +72 -0
  314. package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +44 -0
  315. package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +85 -0
  316. package/src/tests/runtime-plugin-path-alias.fixture.ts +43 -0
  317. package/src/tests/runtime-plugin-resolve-roots.fixture.ts +65 -0
  318. package/src/tests/runtime-plugin-support-configure.fixture.ts +31 -0
  319. package/src/tests/runtime-plugin-support-late-addition.fixture.ts +17 -0
  320. package/src/tests/runtime-plugin-support.fixture.ts +11 -0
  321. package/src/tests/runtime-plugin-support.test.ts +54 -0
  322. package/src/tests/runtime-plugin-windows-file-url.fixture.ts +30 -0
  323. package/src/tests/runtime-plugin.fixture.ts +40 -0
  324. package/src/tests/runtime-plugin.test.ts +369 -0
  325. package/src/tests/scrollbox-culling-bug.test.ts +114 -0
  326. package/src/tests/scrollbox-hitgrid-resize.test.ts +136 -0
  327. package/src/tests/scrollbox-hitgrid.test.ts +909 -0
  328. package/src/tests/scrollbox.test.ts +1895 -0
  329. package/src/tests/wrap-resize-perf.test.ts +276 -0
  330. package/src/tests/yoga-api-coverage.test.ts +409 -0
  331. package/src/tests/yoga-callback-stress.test.ts +122 -0
  332. package/src/tests/yoga-ffi.test.ts +117 -0
  333. package/src/tests/yoga-setters.test.ts +921 -0
  334. package/src/tests/yoga-upstream/YGAlignBaselineTest.test.ts +124 -0
  335. package/src/tests/yoga-upstream/YGComputedBorderTest.test.ts +27 -0
  336. package/src/tests/yoga-upstream/YGComputedMarginTest.test.ts +27 -0
  337. package/src/tests/yoga-upstream/YGComputedPaddingTest.test.ts +27 -0
  338. package/src/tests/yoga-upstream/YGDirtiedTest.test.ts +157 -0
  339. package/src/tests/yoga-upstream/YGErrataTest.test.ts +40 -0
  340. package/src/tests/yoga-upstream/YGFlexBasisAuto.test.ts +23 -0
  341. package/src/tests/yoga-upstream/YGHasNewLayout.test.ts +81 -0
  342. package/src/tests/yoga-upstream/YGMeasureCacheTest.test.ts +31 -0
  343. package/src/tests/yoga-upstream/YGMeasureTest.test.ts +70 -0
  344. package/src/tests/yoga-upstream/generated/YGAbsolutePositionTest.test.ts +1864 -0
  345. package/src/tests/yoga-upstream/generated/YGAlignContentTest.test.ts +5829 -0
  346. package/src/tests/yoga-upstream/generated/YGAlignItemsTest.test.ts +2444 -0
  347. package/src/tests/yoga-upstream/generated/YGAlignSelfTest.test.ts +293 -0
  348. package/src/tests/yoga-upstream/generated/YGAndroidNewsFeed.test.ts +315 -0
  349. package/src/tests/yoga-upstream/generated/YGAspectRatioTest.test.ts +231 -0
  350. package/src/tests/yoga-upstream/generated/YGAutoTest.test.ts +347 -0
  351. package/src/tests/yoga-upstream/generated/YGBorderTest.test.ts +256 -0
  352. package/src/tests/yoga-upstream/generated/YGBoxSizingTest.test.ts +2747 -0
  353. package/src/tests/yoga-upstream/generated/YGDimensionTest.test.ts +129 -0
  354. package/src/tests/yoga-upstream/generated/YGDisplayContentsTest.test.ts +109 -0
  355. package/src/tests/yoga-upstream/generated/YGDisplayTest.test.ts +1097 -0
  356. package/src/tests/yoga-upstream/generated/YGFlexDirectionTest.test.ts +4562 -0
  357. package/src/tests/yoga-upstream/generated/YGFlexTest.test.ts +677 -0
  358. package/src/tests/yoga-upstream/generated/YGFlexWrapTest.test.ts +2071 -0
  359. package/src/tests/yoga-upstream/generated/YGGapTest.test.ts +3303 -0
  360. package/src/tests/yoga-upstream/generated/YGIntrinsicSizeTest.test.ts +582 -0
  361. package/src/tests/yoga-upstream/generated/YGJustifyContentTest.test.ts +2150 -0
  362. package/src/tests/yoga-upstream/generated/YGMarginTest.test.ts +1963 -0
  363. package/src/tests/yoga-upstream/generated/YGMinMaxDimensionTest.test.ts +1446 -0
  364. package/src/tests/yoga-upstream/generated/YGPaddingTest.test.ts +354 -0
  365. package/src/tests/yoga-upstream/generated/YGPercentageTest.test.ts +1760 -0
  366. package/src/tests/yoga-upstream/generated/YGRoundingTest.test.ts +1161 -0
  367. package/src/tests/yoga-upstream/generated/YGSizeOverflowTest.test.ts +207 -0
  368. package/src/tests/yoga-upstream/generated/YGStaticPositionTest.test.ts +6338 -0
  369. package/src/tests/yoga-upstream/tools/MeasureCounter.ts +54 -0
  370. package/src/tests/yoga-upstream/tools/utils.ts +81 -0
  371. package/src/text-buffer-view.test.ts +722 -0
  372. package/src/text-buffer-view.ts +193 -0
  373. package/src/text-buffer.test.ts +512 -0
  374. package/src/text-buffer.ts +250 -0
  375. package/src/types.ts +199 -0
  376. package/src/utils.ts +88 -0
  377. package/src/yoga.ts +1146 -0
  378. package/src/zig/ansi.zig +502 -0
  379. package/src/zig/audio.zig +1206 -0
  380. package/src/zig/bench/README.md +50 -0
  381. package/src/zig/bench/buffer-color-blending_bench.zig +350 -0
  382. package/src/zig/bench/buffer-draw-box_bench.zig +786 -0
  383. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +894 -0
  384. package/src/zig/bench/edit-buffer_bench.zig +476 -0
  385. package/src/zig/bench/editor-view_bench.zig +169 -0
  386. package/src/zig/bench/native-span-feed_bench.zig +107 -0
  387. package/src/zig/bench/rope-markers_bench.zig +713 -0
  388. package/src/zig/bench/rope_bench.zig +514 -0
  389. package/src/zig/bench/styled-text_bench.zig +476 -0
  390. package/src/zig/bench/text-buffer-coords_bench.zig +362 -0
  391. package/src/zig/bench/text-buffer-view_bench.zig +459 -0
  392. package/src/zig/bench/text-chunk-graphemes_bench.zig +272 -0
  393. package/src/zig/bench/utf8_bench.zig +799 -0
  394. package/src/zig/bench-utils.zig +431 -0
  395. package/src/zig/bench.zig +223 -0
  396. package/src/zig/buffer-methods.zig +215 -0
  397. package/src/zig/buffer.zig +2515 -0
  398. package/src/zig/build.zig +700 -0
  399. package/src/zig/build.zig.zon +19 -0
  400. package/src/zig/edit-buffer.zig +900 -0
  401. package/src/zig/editor-view.zig +812 -0
  402. package/src/zig/event-bus.zig +28 -0
  403. package/src/zig/event-emitter.zig +65 -0
  404. package/src/zig/file-logger.zig +92 -0
  405. package/src/zig/grapheme.zig +838 -0
  406. package/src/zig/handles.zig +267 -0
  407. package/src/zig/lib.zig +2813 -0
  408. package/src/zig/link.zig +349 -0
  409. package/src/zig/logger.zig +43 -0
  410. package/src/zig/mem-registry.zig +126 -0
  411. package/src/zig/miniaudio_shim.c +21 -0
  412. package/src/zig/native-renderable.zig +112 -0
  413. package/src/zig/native-span-feed-bench-lib.zig +7 -0
  414. package/src/zig/native-span-feed.zig +747 -0
  415. package/src/zig/renderer-output.zig +677 -0
  416. package/src/zig/renderer.zig +2106 -0
  417. package/src/zig/rope.zig +1220 -0
  418. package/src/zig/split-scrollback.zig +88 -0
  419. package/src/zig/syntax-style.zig +174 -0
  420. package/src/zig/terminal.zig +1652 -0
  421. package/src/zig/test.zig +82 -0
  422. package/src/zig/tests/README.md +18 -0
  423. package/src/zig/tests/ansi_test.zig +18 -0
  424. package/src/zig/tests/audio_test.zig +439 -0
  425. package/src/zig/tests/buffer-methods_test.zig +1111 -0
  426. package/src/zig/tests/buffer_test.zig +2926 -0
  427. package/src/zig/tests/edit-buffer-history_test.zig +299 -0
  428. package/src/zig/tests/edit-buffer_test.zig +1688 -0
  429. package/src/zig/tests/editor-view_test.zig +3454 -0
  430. package/src/zig/tests/event-emitter_test.zig +249 -0
  431. package/src/zig/tests/grapheme_test.zig +1329 -0
  432. package/src/zig/tests/handles_test.zig +123 -0
  433. package/src/zig/tests/link_test.zig +220 -0
  434. package/src/zig/tests/mem-registry_test.zig +473 -0
  435. package/src/zig/tests/memory_leak_regression_test.zig +234 -0
  436. package/src/zig/tests/native-renderable_test.zig +16 -0
  437. package/src/zig/tests/native-span-feed_test.zig +1266 -0
  438. package/src/zig/tests/renderer_test.zig +2604 -0
  439. package/src/zig/tests/rope-nested_test.zig +712 -0
  440. package/src/zig/tests/rope_fuzz_test.zig +238 -0
  441. package/src/zig/tests/rope_test.zig +2362 -0
  442. package/src/zig/tests/segment-merge.test.zig +148 -0
  443. package/src/zig/tests/split-scrollback_test.zig +70 -0
  444. package/src/zig/tests/syntax-style_test.zig +558 -0
  445. package/src/zig/tests/terminal_test.zig +1489 -0
  446. package/src/zig/tests/test-renderer.zig +126 -0
  447. package/src/zig/tests/text-buffer-drawing_test.zig +3291 -0
  448. package/src/zig/tests/text-buffer-highlights_test.zig +706 -0
  449. package/src/zig/tests/text-buffer-iterators_test.zig +776 -0
  450. package/src/zig/tests/text-buffer-segment_test.zig +320 -0
  451. package/src/zig/tests/text-buffer-selection_test.zig +1056 -0
  452. package/src/zig/tests/text-buffer-selection_viewport_test.zig +358 -0
  453. package/src/zig/tests/text-buffer-view_test.zig +3672 -0
  454. package/src/zig/tests/text-buffer_test.zig +2191 -0
  455. package/src/zig/tests/unicode-width-map.zon +3909 -0
  456. package/src/zig/tests/utf8_no_zwj_test.zig +260 -0
  457. package/src/zig/tests/utf8_test.zig +4060 -0
  458. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +267 -0
  459. package/src/zig/tests/utf8_wcwidth_test.zig +357 -0
  460. package/src/zig/tests/word-wrap-editing_test.zig +498 -0
  461. package/src/zig/tests/wrap-cache-perf_test.zig +113 -0
  462. package/src/zig/tests/yoga_test.zig +65 -0
  463. package/src/zig/text-buffer-iterators.zig +496 -0
  464. package/src/zig/text-buffer-segment.zig +403 -0
  465. package/src/zig/text-buffer-view.zig +1428 -0
  466. package/src/zig/text-buffer.zig +1272 -0
  467. package/src/zig/utf8.zig +1954 -0
  468. package/src/zig/utils.zig +12 -0
  469. package/src/zig/uucode-stub.zig +76 -0
  470. package/src/zig/vendor/miniaudio/miniaudio.h +93468 -0
  471. package/src/zig/yoga.zig +658 -0
  472. package/src/zig-structs.ts +381 -0
  473. package/src/zig.ts +5260 -0
  474. package/tsconfig.build.json +17 -0
  475. package/tsconfig.json +27 -0
  476. package/tsconfig.node-test.json +138 -0
@@ -0,0 +1,776 @@
1
+ const std = @import("std");
2
+ const testing = std.testing;
3
+ const iter_mod = @import("../text-buffer-iterators.zig");
4
+ const seg_mod = @import("../text-buffer-segment.zig");
5
+ const text_buffer = @import("../text-buffer.zig");
6
+ const gp = @import("../grapheme.zig");
7
+ const link = @import("../link.zig");
8
+
9
+ const Segment = seg_mod.Segment;
10
+ const UnifiedRope = seg_mod.UnifiedRope;
11
+ const LineInfo = iter_mod.LineInfo;
12
+ const TextChunk = seg_mod.TextChunk;
13
+ const TextBuffer = text_buffer.UnifiedTextBuffer;
14
+
15
+ test "walkLines - empty rope" {
16
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
17
+ defer arena.deinit();
18
+ const allocator = arena.allocator();
19
+
20
+ var rope = try UnifiedRope.init(allocator);
21
+
22
+ const Context = struct {
23
+ count: u32 = 0,
24
+ first_line: ?LineInfo = null,
25
+
26
+ fn callback(ctx_ptr: *anyopaque, line_info: LineInfo) void {
27
+ const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_ptr)));
28
+ if (ctx.count == 0) {
29
+ ctx.first_line = line_info;
30
+ }
31
+ ctx.count += 1;
32
+ }
33
+ };
34
+
35
+ var ctx: Context = .{};
36
+ iter_mod.walkLines(&rope, &ctx, Context.callback, true);
37
+
38
+ try testing.expectEqual(@as(u32, 1), ctx.count);
39
+ }
40
+
41
+ test "walkLines - single text segment" {
42
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
43
+ defer arena.deinit();
44
+ const allocator = arena.allocator();
45
+
46
+ var rope = try UnifiedRope.init(allocator);
47
+ try rope.append(.{ .linestart = {} });
48
+ try rope.append(.{
49
+ .text = TextChunk{
50
+ .mem_id = 0,
51
+ .byte_start = 0,
52
+ .byte_end = 10,
53
+ .width = 10,
54
+ .flags = 0,
55
+ },
56
+ });
57
+
58
+ const Context = struct {
59
+ lines: std.ArrayListUnmanaged(LineInfo),
60
+ allocator: std.mem.Allocator,
61
+
62
+ fn callback(ctx_ptr: *anyopaque, line_info: LineInfo) void {
63
+ const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_ptr)));
64
+ ctx.lines.append(ctx.allocator, line_info) catch {};
65
+ }
66
+ };
67
+
68
+ var ctx: Context = .{ .lines = .{}, .allocator = allocator };
69
+ defer ctx.lines.deinit(allocator);
70
+
71
+ iter_mod.walkLines(&rope, &ctx, Context.callback, true);
72
+
73
+ try testing.expectEqual(@as(usize, 1), ctx.lines.items.len);
74
+ try testing.expectEqual(@as(u32, 10), ctx.lines.items[0].width_cols);
75
+ }
76
+
77
+ test "walkLines - text + break + text" {
78
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
79
+ defer arena.deinit();
80
+ const allocator = arena.allocator();
81
+
82
+ var rope = try UnifiedRope.init(allocator);
83
+ try rope.append(.{ .linestart = {} });
84
+ try rope.append(.{
85
+ .text = TextChunk{
86
+ .mem_id = 0,
87
+ .byte_start = 0,
88
+ .byte_end = 10,
89
+ .width = 10,
90
+ .flags = 0,
91
+ },
92
+ });
93
+ try rope.append(.{ .brk = {} });
94
+ try rope.append(.{ .linestart = {} });
95
+ try rope.append(.{
96
+ .text = TextChunk{
97
+ .mem_id = 0,
98
+ .byte_start = 10,
99
+ .byte_end = 15,
100
+ .width = 5,
101
+ .flags = 0,
102
+ },
103
+ });
104
+
105
+ const Context = struct {
106
+ lines: std.ArrayListUnmanaged(LineInfo),
107
+ allocator: std.mem.Allocator,
108
+
109
+ fn callback(ctx_ptr: *anyopaque, line_info: LineInfo) void {
110
+ const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_ptr)));
111
+ ctx.lines.append(ctx.allocator, line_info) catch {};
112
+ }
113
+ };
114
+
115
+ var ctx: Context = .{ .lines = .{}, .allocator = allocator };
116
+ defer ctx.lines.deinit(allocator);
117
+
118
+ iter_mod.walkLines(&rope, &ctx, Context.callback, true);
119
+
120
+ try testing.expectEqual(@as(usize, 2), ctx.lines.items.len);
121
+
122
+ try testing.expectEqual(@as(u32, 0), ctx.lines.items[0].line_idx);
123
+ try testing.expectEqual(@as(u32, 10), ctx.lines.items[0].width_cols);
124
+ try testing.expectEqual(@as(u32, 0), ctx.lines.items[0].col_offset);
125
+
126
+ try testing.expectEqual(@as(u32, 1), ctx.lines.items[1].line_idx);
127
+ try testing.expectEqual(@as(u32, 5), ctx.lines.items[1].width_cols);
128
+ try testing.expectEqual(@as(u32, 11), ctx.lines.items[1].col_offset);
129
+ }
130
+
131
+ test "walkLines - exclude newlines in offset" {
132
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
133
+ defer arena.deinit();
134
+ const allocator = arena.allocator();
135
+
136
+ var rope = try UnifiedRope.init(allocator);
137
+ try rope.append(.{ .linestart = {} });
138
+ try rope.append(.{
139
+ .text = TextChunk{
140
+ .mem_id = 0,
141
+ .byte_start = 0,
142
+ .byte_end = 10,
143
+ .width = 10,
144
+ .flags = 0,
145
+ },
146
+ });
147
+ try rope.append(.{ .brk = {} });
148
+ try rope.append(.{ .linestart = {} });
149
+ try rope.append(.{
150
+ .text = TextChunk{
151
+ .mem_id = 0,
152
+ .byte_start = 10,
153
+ .byte_end = 15,
154
+ .width = 5,
155
+ .flags = 0,
156
+ },
157
+ });
158
+
159
+ const Context = struct {
160
+ lines: std.ArrayListUnmanaged(LineInfo),
161
+ allocator: std.mem.Allocator,
162
+
163
+ fn callback(ctx_ptr: *anyopaque, line_info: LineInfo) void {
164
+ const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_ptr)));
165
+ ctx.lines.append(ctx.allocator, line_info) catch {};
166
+ }
167
+ };
168
+
169
+ var ctx: Context = .{ .lines = .{}, .allocator = allocator };
170
+ defer ctx.lines.deinit(allocator);
171
+
172
+ iter_mod.walkLines(&rope, &ctx, Context.callback, false);
173
+
174
+ try testing.expectEqual(@as(usize, 2), ctx.lines.items.len);
175
+
176
+ try testing.expectEqual(@as(u32, 0), ctx.lines.items[0].line_idx);
177
+ try testing.expectEqual(@as(u32, 10), ctx.lines.items[0].width_cols);
178
+ try testing.expectEqual(@as(u32, 0), ctx.lines.items[0].col_offset);
179
+
180
+ try testing.expectEqual(@as(u32, 1), ctx.lines.items[1].line_idx);
181
+ try testing.expectEqual(@as(u32, 5), ctx.lines.items[1].width_cols);
182
+ try testing.expectEqual(@as(u32, 10), ctx.lines.items[1].col_offset);
183
+ }
184
+
185
+ test "coordsToOffset - valid coordinates" {
186
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
187
+ defer arena.deinit();
188
+ const allocator = arena.allocator();
189
+
190
+ var rope = try UnifiedRope.init(allocator);
191
+ try rope.append(.{ .linestart = {} });
192
+ try rope.append(.{
193
+ .text = TextChunk{
194
+ .mem_id = 0,
195
+ .byte_start = 0,
196
+ .byte_end = 10,
197
+ .width = 10,
198
+ .flags = 0,
199
+ },
200
+ });
201
+ try rope.append(.{ .brk = {} });
202
+ try rope.append(.{ .linestart = {} });
203
+ try rope.append(.{
204
+ .text = TextChunk{
205
+ .mem_id = 0,
206
+ .byte_start = 10,
207
+ .byte_end = 15,
208
+ .width = 5,
209
+ .flags = 0,
210
+ },
211
+ });
212
+
213
+ const offset1 = iter_mod.coordsToOffset(&rope, 0, 5);
214
+ try testing.expect(offset1 != null);
215
+ try testing.expectEqual(@as(u32, 5), offset1.?);
216
+
217
+ const offset2 = iter_mod.coordsToOffset(&rope, 1, 0);
218
+ try testing.expect(offset2 != null);
219
+ try testing.expectEqual(@as(u32, 11), offset2.?);
220
+
221
+ const offset3 = iter_mod.coordsToOffset(&rope, 1, 3);
222
+ try testing.expect(offset3 != null);
223
+ try testing.expectEqual(@as(u32, 14), offset3.?);
224
+ }
225
+
226
+ test "offsetToCoords - valid offsets" {
227
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
228
+ defer arena.deinit();
229
+ const allocator = arena.allocator();
230
+
231
+ var rope = try UnifiedRope.init(allocator);
232
+ try rope.append(.{ .linestart = {} });
233
+ try rope.append(.{
234
+ .text = TextChunk{
235
+ .mem_id = 0,
236
+ .byte_start = 0,
237
+ .byte_end = 10,
238
+ .width = 10,
239
+ .flags = 0,
240
+ },
241
+ });
242
+ try rope.append(.{ .brk = {} });
243
+ try rope.append(.{ .linestart = {} });
244
+ try rope.append(.{
245
+ .text = TextChunk{
246
+ .mem_id = 0,
247
+ .byte_start = 10,
248
+ .byte_end = 15,
249
+ .width = 5,
250
+ .flags = 0,
251
+ },
252
+ });
253
+
254
+ const coords1 = iter_mod.offsetToCoords(&rope, 5);
255
+ try testing.expect(coords1 != null);
256
+ try testing.expectEqual(@as(u32, 0), coords1.?.row);
257
+ try testing.expectEqual(@as(u32, 5), coords1.?.col);
258
+
259
+ const coords2 = iter_mod.offsetToCoords(&rope, 10);
260
+ try testing.expect(coords2 != null);
261
+ try testing.expectEqual(@as(u32, 0), coords2.?.row);
262
+ try testing.expectEqual(@as(u32, 10), coords2.?.col);
263
+
264
+ const coords2b = iter_mod.offsetToCoords(&rope, 11);
265
+ try testing.expect(coords2b != null);
266
+ try testing.expectEqual(@as(u32, 1), coords2b.?.row);
267
+ try testing.expectEqual(@as(u32, 0), coords2b.?.col);
268
+
269
+ const coords3 = iter_mod.offsetToCoords(&rope, 14);
270
+ try testing.expect(coords3 != null);
271
+ try testing.expectEqual(@as(u32, 1), coords3.?.row);
272
+ try testing.expectEqual(@as(u32, 3), coords3.?.col);
273
+ }
274
+
275
+ test "Helper functions" {
276
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
277
+ defer arena.deinit();
278
+ const allocator = arena.allocator();
279
+
280
+ var rope = try UnifiedRope.init(allocator);
281
+ try rope.append(.{ .linestart = {} });
282
+ try rope.append(.{
283
+ .text = TextChunk{
284
+ .mem_id = 0,
285
+ .byte_start = 0,
286
+ .byte_end = 10,
287
+ .width = 10,
288
+ .flags = 0,
289
+ },
290
+ });
291
+ try rope.append(.{ .brk = {} });
292
+ try rope.append(.{ .linestart = {} });
293
+ try rope.append(.{
294
+ .text = TextChunk{
295
+ .mem_id = 0,
296
+ .byte_start = 10,
297
+ .byte_end = 15,
298
+ .width = 5,
299
+ .flags = 0,
300
+ },
301
+ });
302
+
303
+ try testing.expectEqual(@as(u32, 2), iter_mod.getLineCount(&rope));
304
+ try testing.expectEqual(@as(u32, 10), iter_mod.getMaxLineWidth(&rope));
305
+ try testing.expectEqual(@as(u32, 15), iter_mod.getTotalWidth(&rope));
306
+ }
307
+
308
+ test "coordsToOffset and offsetToCoords - round trip" {
309
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
310
+ defer arena.deinit();
311
+ const allocator = arena.allocator();
312
+
313
+ var rope = try UnifiedRope.init(allocator);
314
+ try rope.append(.{ .linestart = {} });
315
+ try rope.append(.{
316
+ .text = TextChunk{
317
+ .mem_id = 0,
318
+ .byte_start = 0,
319
+ .byte_end = 10,
320
+ .width = 10,
321
+ .flags = 0,
322
+ },
323
+ });
324
+ try rope.append(.{ .brk = {} });
325
+ try rope.append(.{ .linestart = {} });
326
+ try rope.append(.{
327
+ .text = TextChunk{
328
+ .mem_id = 0,
329
+ .byte_start = 10,
330
+ .byte_end = 18,
331
+ .width = 8,
332
+ .flags = 0,
333
+ },
334
+ });
335
+
336
+ const test_cases = [_]struct { row: u32, col: u32 }{
337
+ .{ .row = 0, .col = 0 },
338
+ .{ .row = 0, .col = 5 },
339
+ .{ .row = 0, .col = 9 },
340
+ .{ .row = 1, .col = 0 },
341
+ .{ .row = 1, .col = 4 },
342
+ .{ .row = 1, .col = 7 },
343
+ };
344
+
345
+ for (test_cases) |tc| {
346
+ const offset = iter_mod.coordsToOffset(&rope, tc.row, tc.col);
347
+ try testing.expect(offset != null);
348
+
349
+ const coords = iter_mod.offsetToCoords(&rope, offset.?);
350
+ try testing.expect(coords != null);
351
+ try testing.expectEqual(tc.row, coords.?.row);
352
+ try testing.expectEqual(tc.col, coords.?.col);
353
+ }
354
+ }
355
+
356
+ test "getGraphemeWidthAt - ASCII text" {
357
+ const pool = gp.initGlobalPool(testing.allocator);
358
+ defer gp.deinitGlobalPool();
359
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
360
+ defer link.deinitGlobalLinkPool();
361
+
362
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
363
+ defer tb.deinit();
364
+
365
+ try tb.setText("Hello");
366
+
367
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
368
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
369
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 2, tb.tabWidth(), tb.widthMethod()));
370
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
371
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 4, tb.tabWidth(), tb.widthMethod()));
372
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
373
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 10, tb.tabWidth(), tb.widthMethod()));
374
+ }
375
+
376
+ test "getGraphemeWidthAt - emoji and wide characters" {
377
+ const pool = gp.initGlobalPool(testing.allocator);
378
+ defer gp.deinitGlobalPool();
379
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
380
+ defer link.deinitGlobalLinkPool();
381
+
382
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
383
+ defer tb.deinit();
384
+
385
+ try tb.setText("a😀b");
386
+
387
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
388
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
389
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
390
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 4, tb.tabWidth(), tb.widthMethod()));
391
+ }
392
+
393
+ test "getGraphemeWidthAt - multiple chunks" {
394
+ const pool = gp.initGlobalPool(testing.allocator);
395
+ defer gp.deinitGlobalPool();
396
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
397
+ defer link.deinitGlobalLinkPool();
398
+
399
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
400
+ defer tb.deinit();
401
+
402
+ try tb.setText("Hello World");
403
+
404
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
405
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 4, tb.tabWidth(), tb.widthMethod()));
406
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
407
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 6, tb.tabWidth(), tb.widthMethod()));
408
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 10, tb.tabWidth(), tb.widthMethod()));
409
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 11, tb.tabWidth(), tb.widthMethod()));
410
+ }
411
+
412
+ test "getGraphemeWidthAt - empty line" {
413
+ const pool = gp.initGlobalPool(testing.allocator);
414
+ defer gp.deinitGlobalPool();
415
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
416
+ defer link.deinitGlobalLinkPool();
417
+
418
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
419
+ defer tb.deinit();
420
+
421
+ try tb.setText("");
422
+
423
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
424
+ }
425
+
426
+ test "getGraphemeWidthAt - at chunk boundary" {
427
+ const pool = gp.initGlobalPool(testing.allocator);
428
+ defer gp.deinitGlobalPool();
429
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
430
+ defer link.deinitGlobalLinkPool();
431
+
432
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
433
+ defer tb.deinit();
434
+
435
+ try tb.setText("abcdef");
436
+
437
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
438
+ }
439
+
440
+ test "getGraphemeWidthAt - after break segment" {
441
+ const pool = gp.initGlobalPool(testing.allocator);
442
+ defer gp.deinitGlobalPool();
443
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
444
+ defer link.deinitGlobalLinkPool();
445
+
446
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
447
+ defer tb.deinit();
448
+
449
+ try tb.setText("abc\ndef");
450
+
451
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
452
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
453
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 1, 0, tb.tabWidth(), tb.widthMethod()));
454
+ }
455
+
456
+ test "getPrevGraphemeWidth - ASCII text" {
457
+ const pool = gp.initGlobalPool(testing.allocator);
458
+ defer gp.deinitGlobalPool();
459
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
460
+ defer link.deinitGlobalLinkPool();
461
+
462
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
463
+ defer tb.deinit();
464
+
465
+ try tb.setText("Hello");
466
+
467
+ try testing.expectEqual(@as(u32, 0), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
468
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
469
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 2, tb.tabWidth(), tb.widthMethod()));
470
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
471
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 4, tb.tabWidth(), tb.widthMethod()));
472
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
473
+ }
474
+
475
+ test "getPrevGraphemeWidth - emoji and wide characters" {
476
+ const pool = gp.initGlobalPool(testing.allocator);
477
+ defer gp.deinitGlobalPool();
478
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
479
+ defer link.deinitGlobalLinkPool();
480
+
481
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
482
+ defer tb.deinit();
483
+
484
+ try tb.setText("a😀b");
485
+
486
+ try testing.expectEqual(@as(u32, 0), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
487
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
488
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
489
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 4, tb.tabWidth(), tb.widthMethod()));
490
+ }
491
+
492
+ test "getPrevGraphemeWidth - at chunk boundary" {
493
+ const pool = gp.initGlobalPool(testing.allocator);
494
+ defer gp.deinitGlobalPool();
495
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
496
+ defer link.deinitGlobalLinkPool();
497
+
498
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
499
+ defer tb.deinit();
500
+
501
+ try tb.setText("abcdef");
502
+
503
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
504
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 4, tb.tabWidth(), tb.widthMethod()));
505
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
506
+ }
507
+
508
+ test "getPrevGraphemeWidth - emoji at chunk boundary" {
509
+ const pool = gp.initGlobalPool(testing.allocator);
510
+ defer gp.deinitGlobalPool();
511
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
512
+ defer link.deinitGlobalLinkPool();
513
+
514
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
515
+ defer tb.deinit();
516
+
517
+ try tb.setText("a😀b");
518
+
519
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
520
+ }
521
+
522
+ test "getPrevGraphemeWidth - multiple chunks" {
523
+ const pool = gp.initGlobalPool(testing.allocator);
524
+ defer gp.deinitGlobalPool();
525
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
526
+ defer link.deinitGlobalLinkPool();
527
+
528
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
529
+ defer tb.deinit();
530
+
531
+ try tb.setText("Hello 😀");
532
+
533
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
534
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
535
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 6, tb.tabWidth(), tb.widthMethod()));
536
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 8, tb.tabWidth(), tb.widthMethod()));
537
+ }
538
+
539
+ test "getPrevGraphemeWidth - empty line" {
540
+ const pool = gp.initGlobalPool(testing.allocator);
541
+ defer gp.deinitGlobalPool();
542
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
543
+ defer link.deinitGlobalLinkPool();
544
+
545
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
546
+ defer tb.deinit();
547
+
548
+ try tb.setText("");
549
+
550
+ try testing.expectEqual(@as(u32, 0), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
551
+ }
552
+
553
+ test "getPrevGraphemeWidth - col beyond line width" {
554
+ const pool = gp.initGlobalPool(testing.allocator);
555
+ defer gp.deinitGlobalPool();
556
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
557
+ defer link.deinitGlobalLinkPool();
558
+
559
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
560
+ defer tb.deinit();
561
+
562
+ try tb.setText("abc");
563
+
564
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 100, tb.tabWidth(), tb.widthMethod()));
565
+ }
566
+
567
+ test "getPrevGraphemeWidth - multiline" {
568
+ const pool = gp.initGlobalPool(testing.allocator);
569
+ defer gp.deinitGlobalPool();
570
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
571
+ defer link.deinitGlobalLinkPool();
572
+
573
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
574
+ defer tb.deinit();
575
+
576
+ try tb.setText("abc\n😀xyz");
577
+
578
+ try testing.expectEqual(@as(u32, 0), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
579
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
580
+ try testing.expectEqual(@as(u32, 0), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 1, 0, tb.tabWidth(), tb.widthMethod()));
581
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 1, 2, tb.tabWidth(), tb.widthMethod()));
582
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 1, 3, tb.tabWidth(), tb.widthMethod()));
583
+ }
584
+
585
+ test "getGraphemeWidthAt - CJK characters (Chinese)" {
586
+ const pool = gp.initGlobalPool(testing.allocator);
587
+ defer gp.deinitGlobalPool();
588
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
589
+ defer link.deinitGlobalLinkPool();
590
+
591
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
592
+ defer tb.deinit();
593
+
594
+ try tb.setText("a世界b");
595
+
596
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
597
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
598
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
599
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
600
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 6, tb.tabWidth(), tb.widthMethod()));
601
+ }
602
+
603
+ test "getGraphemeWidthAt - various emoji including star" {
604
+ const pool = gp.initGlobalPool(testing.allocator);
605
+ defer gp.deinitGlobalPool();
606
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
607
+ defer link.deinitGlobalLinkPool();
608
+
609
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
610
+ defer tb.deinit();
611
+
612
+ try tb.setText("🌟🎉");
613
+
614
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
615
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 2, tb.tabWidth(), tb.widthMethod()));
616
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 4, tb.tabWidth(), tb.widthMethod()));
617
+ }
618
+
619
+ test "getGraphemeWidthAt - tab characters" {
620
+ const pool = gp.initGlobalPool(testing.allocator);
621
+ defer gp.deinitGlobalPool();
622
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
623
+ defer link.deinitGlobalLinkPool();
624
+
625
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
626
+ defer tb.deinit();
627
+ tb.setTabWidth(4);
628
+
629
+ try tb.setText("a\tb\t\tc");
630
+
631
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
632
+ try testing.expectEqual(@as(u32, 4), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
633
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
634
+ try testing.expectEqual(@as(u32, 4), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 6, tb.tabWidth(), tb.widthMethod()));
635
+ try testing.expectEqual(@as(u32, 4), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 10, tb.tabWidth(), tb.widthMethod()));
636
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 14, tb.tabWidth(), tb.widthMethod()));
637
+ }
638
+
639
+ test "getGraphemeWidthAt - tab with different tab_width" {
640
+ const pool = gp.initGlobalPool(testing.allocator);
641
+ defer gp.deinitGlobalPool();
642
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
643
+ defer link.deinitGlobalLinkPool();
644
+
645
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
646
+ defer tb.deinit();
647
+
648
+ try tb.setText("x\ty");
649
+
650
+ tb.setTabWidth(2);
651
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 1, 2, .unicode));
652
+
653
+ tb.setTabWidth(8);
654
+ try testing.expectEqual(@as(u32, 8), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 1, 8, .unicode));
655
+ }
656
+
657
+ test "getGraphemeWidthAt - middle of wide character" {
658
+ const pool = gp.initGlobalPool(testing.allocator);
659
+ defer gp.deinitGlobalPool();
660
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
661
+ defer link.deinitGlobalLinkPool();
662
+
663
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
664
+ defer tb.deinit();
665
+
666
+ try tb.setText("世");
667
+
668
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
669
+ const result = iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod());
670
+ _ = result;
671
+ }
672
+
673
+ test "getGraphemeWidthAt - invalid row" {
674
+ const pool = gp.initGlobalPool(testing.allocator);
675
+ defer gp.deinitGlobalPool();
676
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
677
+ defer link.deinitGlobalLinkPool();
678
+
679
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
680
+ defer tb.deinit();
681
+
682
+ try tb.setText("test");
683
+
684
+ try testing.expectEqual(@as(u32, 0), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 5, 0, tb.tabWidth(), tb.widthMethod()));
685
+ }
686
+
687
+ test "getPrevGraphemeWidth - CJK characters" {
688
+ const pool = gp.initGlobalPool(testing.allocator);
689
+ defer gp.deinitGlobalPool();
690
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
691
+ defer link.deinitGlobalLinkPool();
692
+
693
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
694
+ defer tb.deinit();
695
+
696
+ try tb.setText("a世界b");
697
+
698
+ try testing.expectEqual(@as(u32, 0), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
699
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
700
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
701
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
702
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 6, tb.tabWidth(), tb.widthMethod()));
703
+ }
704
+
705
+ test "getPrevGraphemeWidth - star emoji" {
706
+ const pool = gp.initGlobalPool(testing.allocator);
707
+ defer gp.deinitGlobalPool();
708
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
709
+ defer link.deinitGlobalLinkPool();
710
+
711
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
712
+ defer tb.deinit();
713
+
714
+ try tb.setText("x🌟y");
715
+
716
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
717
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 3, tb.tabWidth(), tb.widthMethod()));
718
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 4, tb.tabWidth(), tb.widthMethod()));
719
+ }
720
+
721
+ test "getPrevGraphemeWidth - tabs" {
722
+ const pool = gp.initGlobalPool(testing.allocator);
723
+ defer gp.deinitGlobalPool();
724
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
725
+ defer link.deinitGlobalLinkPool();
726
+
727
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
728
+ defer tb.deinit();
729
+ tb.setTabWidth(4);
730
+
731
+ try tb.setText("a\tb");
732
+
733
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
734
+ try testing.expectEqual(@as(u32, 4), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 5, tb.tabWidth(), tb.widthMethod()));
735
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 6, tb.tabWidth(), tb.widthMethod()));
736
+ }
737
+
738
+ test "getPrevGraphemeWidth - invalid row" {
739
+ const pool = gp.initGlobalPool(testing.allocator);
740
+ defer gp.deinitGlobalPool();
741
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
742
+ defer link.deinitGlobalLinkPool();
743
+
744
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
745
+ defer tb.deinit();
746
+
747
+ try tb.setText("test");
748
+
749
+ try testing.expectEqual(@as(u32, 0), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 10, 5, tb.tabWidth(), tb.widthMethod()));
750
+ }
751
+
752
+ test "getGraphemeWidthAt and getPrevGraphemeWidth - mixed content" {
753
+ const pool = gp.initGlobalPool(testing.allocator);
754
+ defer gp.deinitGlobalPool();
755
+ const link_pool = link.initGlobalLinkPool(testing.allocator);
756
+ defer link.deinitGlobalLinkPool();
757
+
758
+ var tb = try TextBuffer.init(testing.allocator, pool, link_pool, .unicode);
759
+ defer tb.deinit();
760
+ tb.setTabWidth(4);
761
+
762
+ try tb.setText("Hi\t世🌟!");
763
+
764
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 0, tb.tabWidth(), tb.widthMethod()));
765
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
766
+ try testing.expectEqual(@as(u32, 4), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 2, tb.tabWidth(), tb.widthMethod()));
767
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 6, tb.tabWidth(), tb.widthMethod()));
768
+ try testing.expectEqual(@as(u32, 2), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 8, tb.tabWidth(), tb.widthMethod()));
769
+ try testing.expectEqual(@as(u32, 1), iter_mod.getGraphemeWidthAt(tb.rope(), tb.memRegistry(), 0, 10, tb.tabWidth(), tb.widthMethod()));
770
+
771
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 1, tb.tabWidth(), tb.widthMethod()));
772
+ try testing.expectEqual(@as(u32, 1), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 2, tb.tabWidth(), tb.widthMethod()));
773
+ try testing.expectEqual(@as(u32, 4), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 6, tb.tabWidth(), tb.widthMethod()));
774
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 8, tb.tabWidth(), tb.widthMethod()));
775
+ try testing.expectEqual(@as(u32, 2), iter_mod.getPrevGraphemeWidth(tb.rope(), tb.memRegistry(), 0, 10, tb.tabWidth(), tb.widthMethod()));
776
+ }