@fairyhunter13/opentui-core 0.1.114 → 0.1.116
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.
- package/3d/SpriteResourceManager.d.ts +74 -0
- package/3d/SpriteUtils.d.ts +13 -0
- package/3d/TextureUtils.d.ts +24 -0
- package/3d/ThreeRenderable.d.ts +40 -0
- package/3d/WGPURenderer.d.ts +61 -0
- package/3d/animation/ExplodingSpriteEffect.d.ts +71 -0
- package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +76 -0
- package/3d/animation/SpriteAnimator.d.ts +124 -0
- package/3d/animation/SpriteParticleGenerator.d.ts +62 -0
- package/3d/canvas.d.ts +44 -0
- package/3d/index.d.ts +12 -0
- package/3d/physics/PlanckPhysicsAdapter.d.ts +19 -0
- package/3d/physics/RapierPhysicsAdapter.d.ts +19 -0
- package/3d/physics/physics-interface.d.ts +27 -0
- package/3d.d.ts +2 -0
- package/3d.js +34041 -0
- package/3d.js.map +155 -0
- package/LICENSE +21 -0
- package/NativeSpanFeed.d.ts +41 -0
- package/Renderable.d.ts +334 -0
- package/animation/Timeline.d.ts +126 -0
- package/ansi.d.ts +13 -0
- package/buffer.d.ts +111 -0
- package/console.d.ts +144 -0
- package/edit-buffer.d.ts +98 -0
- package/editor-view.d.ts +73 -0
- package/index-dcj62y8t.js +20614 -0
- package/index-dcj62y8t.js.map +67 -0
- package/index-jyrhjc34.js +411 -0
- package/index-jyrhjc34.js.map +10 -0
- package/index-wc7ae60z.js +12299 -0
- package/index-wc7ae60z.js.map +42 -0
- package/index.d.ts +23 -0
- package/index.js +478 -0
- package/index.js.map +9 -0
- package/lib/KeyHandler.d.ts +61 -0
- package/lib/RGBA.d.ts +25 -0
- package/lib/ascii.font.d.ts +508 -0
- package/lib/border.d.ts +51 -0
- package/lib/bunfs.d.ts +7 -0
- package/lib/clipboard.d.ts +17 -0
- package/lib/clock.d.ts +15 -0
- package/lib/data-paths.d.ts +26 -0
- package/lib/debounce.d.ts +42 -0
- package/lib/detect-links.d.ts +6 -0
- package/lib/env.d.ts +42 -0
- package/lib/extmarks-history.d.ts +17 -0
- package/lib/extmarks.d.ts +89 -0
- package/lib/hast-styled-text.d.ts +17 -0
- package/lib/index.d.ts +21 -0
- package/lib/keymapping.d.ts +25 -0
- package/lib/objects-in-viewport.d.ts +24 -0
- package/lib/output.capture.d.ts +24 -0
- package/lib/parse.keypress-kitty.d.ts +2 -0
- package/lib/parse.keypress.d.ts +26 -0
- package/lib/parse.mouse.d.ts +30 -0
- package/lib/paste.d.ts +7 -0
- package/lib/queue.d.ts +15 -0
- package/lib/renderable.validations.d.ts +12 -0
- package/lib/scroll-acceleration.d.ts +43 -0
- package/lib/selection.d.ts +63 -0
- package/lib/singleton.d.ts +7 -0
- package/lib/stdin-parser.d.ts +87 -0
- package/lib/styled-text.d.ts +63 -0
- package/lib/terminal-capability-detection.d.ts +30 -0
- package/lib/terminal-palette.d.ts +50 -0
- package/lib/tree-sitter/assets/update.d.ts +11 -0
- package/lib/tree-sitter/client.d.ts +47 -0
- package/lib/tree-sitter/default-parsers.d.ts +2 -0
- package/lib/tree-sitter/download-utils.d.ts +21 -0
- package/lib/tree-sitter/index.d.ts +8 -0
- package/lib/tree-sitter/parser.worker.d.ts +1 -0
- package/lib/tree-sitter/parsers-config.d.ts +53 -0
- package/lib/tree-sitter/resolve-ft.d.ts +5 -0
- package/lib/tree-sitter/types.d.ts +82 -0
- package/lib/tree-sitter-styled-text.d.ts +14 -0
- package/lib/validate-dir-name.d.ts +1 -0
- package/lib/yoga.options.d.ts +32 -0
- package/package.json +53 -62
- package/parser.worker.js +899 -0
- package/parser.worker.js.map +12 -0
- package/plugins/core-slot.d.ts +72 -0
- package/plugins/registry.d.ts +42 -0
- package/plugins/types.d.ts +34 -0
- package/post/effects.d.ts +147 -0
- package/post/filters.d.ts +65 -0
- package/post/matrices.d.ts +20 -0
- package/renderables/ASCIIFont.d.ts +52 -0
- package/renderables/Box.d.ts +81 -0
- package/renderables/Code.d.ts +78 -0
- package/renderables/Diff.d.ts +142 -0
- package/renderables/EditBufferRenderable.d.ts +237 -0
- package/renderables/FrameBuffer.d.ts +16 -0
- package/renderables/Input.d.ts +67 -0
- package/renderables/LineNumberRenderable.d.ts +78 -0
- package/renderables/Markdown.d.ts +185 -0
- package/renderables/ScrollBar.d.ts +77 -0
- package/renderables/ScrollBox.d.ts +124 -0
- package/renderables/Select.d.ts +115 -0
- package/renderables/Slider.d.ts +47 -0
- package/renderables/TabSelect.d.ts +96 -0
- package/renderables/Text.d.ts +36 -0
- package/renderables/TextBufferRenderable.d.ts +105 -0
- package/renderables/TextNode.d.ts +91 -0
- package/renderables/TextTable.d.ts +140 -0
- package/renderables/Textarea.d.ts +63 -0
- package/renderables/TimeToFirstDraw.d.ts +24 -0
- package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
- package/renderables/composition/VRenderable.d.ts +16 -0
- package/renderables/composition/constructs.d.ts +35 -0
- package/renderables/composition/vnode.d.ts +46 -0
- package/renderables/index.d.ts +23 -0
- package/renderables/markdown-parser.d.ts +10 -0
- package/renderer.d.ts +419 -0
- package/runtime-plugin-support.d.ts +3 -0
- package/runtime-plugin-support.js +29 -0
- package/runtime-plugin-support.js.map +10 -0
- package/runtime-plugin.d.ts +16 -0
- package/runtime-plugin.js +16 -0
- package/runtime-plugin.js.map +9 -0
- package/syntax-style.d.ts +54 -0
- package/testing/manual-clock.d.ts +17 -0
- package/testing/mock-keys.d.ts +81 -0
- package/testing/mock-mouse.d.ts +38 -0
- package/testing/mock-tree-sitter-client.d.ts +23 -0
- package/testing/spy.d.ts +7 -0
- package/testing/test-recorder.d.ts +61 -0
- package/testing/test-renderer.d.ts +23 -0
- package/testing.d.ts +6 -0
- package/testing.js +697 -0
- package/testing.js.map +15 -0
- package/text-buffer-view.d.ts +42 -0
- package/text-buffer.d.ts +67 -0
- package/types.d.ts +139 -0
- package/utils.d.ts +14 -0
- package/zig-structs.d.ts +155 -0
- package/zig.d.ts +353 -0
- package/dev/keypress-debug-renderer.ts +0 -148
- package/dev/keypress-debug.ts +0 -43
- package/dev/print-env-vars.ts +0 -32
- package/dev/test-tmux-graphics-334.sh +0 -68
- package/dev/thai-debug-test.ts +0 -68
- package/docs/development.md +0 -144
- package/scripts/build.ts +0 -400
- package/scripts/publish.ts +0 -60
- package/src/3d/SpriteResourceManager.ts +0 -286
- package/src/3d/SpriteUtils.ts +0 -70
- package/src/3d/TextureUtils.ts +0 -196
- package/src/3d/ThreeRenderable.ts +0 -197
- package/src/3d/WGPURenderer.ts +0 -294
- package/src/3d/animation/ExplodingSpriteEffect.ts +0 -513
- package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +0 -429
- package/src/3d/animation/SpriteAnimator.ts +0 -633
- package/src/3d/animation/SpriteParticleGenerator.ts +0 -435
- package/src/3d/canvas.ts +0 -464
- package/src/3d/index.ts +0 -12
- package/src/3d/physics/PlanckPhysicsAdapter.ts +0 -72
- package/src/3d/physics/RapierPhysicsAdapter.ts +0 -66
- package/src/3d/physics/physics-interface.ts +0 -31
- package/src/3d/shaders/supersampling.wgsl +0 -201
- package/src/3d.ts +0 -3
- package/src/NativeSpanFeed.ts +0 -300
- package/src/Renderable.ts +0 -1704
- package/src/__snapshots__/buffer.test.ts.snap +0 -28
- package/src/animation/Timeline.test.ts +0 -2709
- package/src/animation/Timeline.ts +0 -598
- package/src/ansi.ts +0 -18
- package/src/benchmark/attenuation-benchmark.ts +0 -81
- package/src/benchmark/colormatrix-benchmark.ts +0 -128
- package/src/benchmark/gain-benchmark.ts +0 -80
- package/src/benchmark/latest-all-bench-run.json +0 -707
- package/src/benchmark/latest-async-bench-run.json +0 -336
- package/src/benchmark/latest-default-bench-run.json +0 -657
- package/src/benchmark/latest-large-bench-run.json +0 -707
- package/src/benchmark/latest-quick-bench-run.json +0 -207
- package/src/benchmark/markdown-benchmark.ts +0 -1796
- package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
- package/src/benchmark/native-span-feed-benchmark.md +0 -56
- package/src/benchmark/native-span-feed-benchmark.ts +0 -596
- package/src/benchmark/native-span-feed-compare.ts +0 -280
- package/src/benchmark/renderer-benchmark.ts +0 -754
- package/src/benchmark/text-table-benchmark.ts +0 -948
- package/src/buffer.test.ts +0 -291
- package/src/buffer.ts +0 -554
- package/src/console.test.ts +0 -612
- package/src/console.ts +0 -1254
- package/src/edit-buffer.test.ts +0 -1769
- package/src/edit-buffer.ts +0 -411
- package/src/editor-view.test.ts +0 -1032
- package/src/editor-view.ts +0 -284
- package/src/examples/ascii-font-selection-demo.ts +0 -245
- package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
- package/src/examples/assets/concrete.png +0 -0
- package/src/examples/assets/crate.png +0 -0
- package/src/examples/assets/crate_emissive.png +0 -0
- package/src/examples/assets/forrest_background.png +0 -0
- package/src/examples/assets/hast-example.json +0 -1018
- package/src/examples/assets/heart.png +0 -0
- package/src/examples/assets/main_char_heavy_attack.png +0 -0
- package/src/examples/assets/main_char_idle.png +0 -0
- package/src/examples/assets/main_char_jump_end.png +0 -0
- package/src/examples/assets/main_char_jump_landing.png +0 -0
- package/src/examples/assets/main_char_jump_start.png +0 -0
- package/src/examples/assets/main_char_run_loop.png +0 -0
- package/src/examples/assets/roughness_map.jpg +0 -0
- package/src/examples/build.ts +0 -115
- package/src/examples/code-demo.ts +0 -924
- package/src/examples/console-demo.ts +0 -358
- package/src/examples/core-plugin-slots-demo.ts +0 -759
- package/src/examples/diff-demo.ts +0 -701
- package/src/examples/draggable-three-demo.ts +0 -259
- package/src/examples/editor-demo.ts +0 -322
- package/src/examples/extmarks-demo.ts +0 -196
- package/src/examples/focus-restore-demo.ts +0 -310
- package/src/examples/fonts.ts +0 -245
- package/src/examples/fractal-shader-demo.ts +0 -268
- package/src/examples/framebuffer-demo.ts +0 -674
- package/src/examples/full-unicode-demo.ts +0 -241
- package/src/examples/golden-star-demo.ts +0 -933
- package/src/examples/grayscale-buffer-demo.ts +0 -249
- package/src/examples/hast-syntax-highlighting-demo.ts +0 -129
- package/src/examples/index.ts +0 -926
- package/src/examples/input-demo.ts +0 -377
- package/src/examples/input-select-layout-demo.ts +0 -425
- package/src/examples/install.sh +0 -143
- package/src/examples/keypress-debug-demo.ts +0 -452
- package/src/examples/lib/HexList.ts +0 -122
- package/src/examples/lib/PaletteGrid.ts +0 -125
- package/src/examples/lib/standalone-keys.ts +0 -25
- package/src/examples/lib/tab-controller.ts +0 -243
- package/src/examples/lights-phong-demo.ts +0 -290
- package/src/examples/link-demo.ts +0 -220
- package/src/examples/live-state-demo.ts +0 -480
- package/src/examples/markdown-demo.ts +0 -725
- package/src/examples/mouse-interaction-demo.ts +0 -428
- package/src/examples/nested-zindex-demo.ts +0 -357
- package/src/examples/opacity-example.ts +0 -235
- package/src/examples/opentui-demo.ts +0 -1057
- package/src/examples/physx-planck-2d-demo.ts +0 -623
- package/src/examples/physx-rapier-2d-demo.ts +0 -655
- package/src/examples/relative-positioning-demo.ts +0 -323
- package/src/examples/scroll-example.ts +0 -214
- package/src/examples/scrollbox-mouse-test.ts +0 -112
- package/src/examples/scrollbox-overlay-hit-test.ts +0 -206
- package/src/examples/select-demo.ts +0 -237
- package/src/examples/shader-cube-demo.ts +0 -1015
- package/src/examples/simple-layout-example.ts +0 -591
- package/src/examples/slider-demo.ts +0 -617
- package/src/examples/split-mode-demo.ts +0 -453
- package/src/examples/sprite-animation-demo.ts +0 -443
- package/src/examples/sprite-particle-generator-demo.ts +0 -486
- package/src/examples/static-sprite-demo.ts +0 -193
- package/src/examples/sticky-scroll-example.ts +0 -308
- package/src/examples/styled-text-demo.ts +0 -282
- package/src/examples/tab-select-demo.ts +0 -219
- package/src/examples/terminal-title.ts +0 -29
- package/src/examples/terminal.ts +0 -305
- package/src/examples/text-node-demo.ts +0 -416
- package/src/examples/text-selection-demo.ts +0 -377
- package/src/examples/text-table-demo.ts +0 -503
- package/src/examples/text-truncation-demo.ts +0 -481
- package/src/examples/text-wrap.ts +0 -757
- package/src/examples/texture-loading-demo.ts +0 -259
- package/src/examples/timeline-example.ts +0 -670
- package/src/examples/transparency-demo.ts +0 -400
- package/src/examples/vnode-composition-demo.ts +0 -404
- package/src/examples/wide-grapheme-overlay-demo.ts +0 -280
- package/src/index.ts +0 -24
- package/src/lib/KeyHandler.integration.test.ts +0 -292
- package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
- package/src/lib/KeyHandler.test.ts +0 -662
- package/src/lib/KeyHandler.ts +0 -222
- package/src/lib/RGBA.test.ts +0 -984
- package/src/lib/RGBA.ts +0 -204
- package/src/lib/ascii.font.ts +0 -330
- package/src/lib/border.test.ts +0 -83
- package/src/lib/border.ts +0 -170
- package/src/lib/bunfs.test.ts +0 -27
- package/src/lib/bunfs.ts +0 -18
- package/src/lib/clipboard.test.ts +0 -41
- package/src/lib/clipboard.ts +0 -47
- package/src/lib/clock.ts +0 -35
- package/src/lib/data-paths.test.ts +0 -133
- package/src/lib/data-paths.ts +0 -109
- package/src/lib/debounce.ts +0 -106
- package/src/lib/detect-links.test.ts +0 -98
- package/src/lib/detect-links.ts +0 -56
- package/src/lib/env.test.ts +0 -228
- package/src/lib/env.ts +0 -209
- package/src/lib/extmarks-history.ts +0 -51
- package/src/lib/extmarks-multiwidth.test.ts +0 -322
- package/src/lib/extmarks.test.ts +0 -3457
- package/src/lib/extmarks.ts +0 -843
- package/src/lib/fonts/block.json +0 -405
- package/src/lib/fonts/grid.json +0 -265
- package/src/lib/fonts/huge.json +0 -741
- package/src/lib/fonts/pallet.json +0 -314
- package/src/lib/fonts/shade.json +0 -591
- package/src/lib/fonts/slick.json +0 -321
- package/src/lib/fonts/tiny.json +0 -69
- package/src/lib/hast-styled-text.ts +0 -59
- package/src/lib/index.ts +0 -21
- package/src/lib/keymapping.test.ts +0 -317
- package/src/lib/keymapping.ts +0 -115
- package/src/lib/objects-in-viewport.test.ts +0 -787
- package/src/lib/objects-in-viewport.ts +0 -153
- package/src/lib/output.capture.ts +0 -58
- package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -340
- package/src/lib/parse.keypress-kitty.test.ts +0 -663
- package/src/lib/parse.keypress-kitty.ts +0 -439
- package/src/lib/parse.keypress.test.ts +0 -1849
- package/src/lib/parse.keypress.ts +0 -397
- package/src/lib/parse.mouse.test.ts +0 -552
- package/src/lib/parse.mouse.ts +0 -232
- package/src/lib/paste.ts +0 -16
- package/src/lib/queue.ts +0 -65
- package/src/lib/renderable.validations.test.ts +0 -87
- package/src/lib/renderable.validations.ts +0 -83
- package/src/lib/scroll-acceleration.ts +0 -98
- package/src/lib/selection.ts +0 -240
- package/src/lib/singleton.ts +0 -28
- package/src/lib/stdin-parser.test.ts +0 -2290
- package/src/lib/stdin-parser.ts +0 -1810
- package/src/lib/styled-text.ts +0 -178
- package/src/lib/terminal-capability-detection.test.ts +0 -202
- package/src/lib/terminal-capability-detection.ts +0 -79
- package/src/lib/terminal-palette.test.ts +0 -878
- package/src/lib/terminal-palette.ts +0 -383
- package/src/lib/tree-sitter/assets/README.md +0 -118
- package/src/lib/tree-sitter/assets/update.ts +0 -334
- package/src/lib/tree-sitter/assets.d.ts +0 -9
- package/src/lib/tree-sitter/cache.test.ts +0 -273
- package/src/lib/tree-sitter/client.test.ts +0 -1165
- package/src/lib/tree-sitter/client.ts +0 -607
- package/src/lib/tree-sitter/default-parsers.ts +0 -86
- package/src/lib/tree-sitter/download-utils.ts +0 -148
- package/src/lib/tree-sitter/index.ts +0 -28
- package/src/lib/tree-sitter/parser.worker.ts +0 -1042
- package/src/lib/tree-sitter/parsers-config.ts +0 -81
- package/src/lib/tree-sitter/resolve-ft.test.ts +0 -55
- package/src/lib/tree-sitter/resolve-ft.ts +0 -189
- package/src/lib/tree-sitter/types.ts +0 -82
- package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
- package/src/lib/tree-sitter-styled-text.ts +0 -306
- package/src/lib/validate-dir-name.ts +0 -55
- package/src/lib/yoga.options.test.ts +0 -628
- package/src/lib/yoga.options.ts +0 -346
- package/src/plugins/core-slot.ts +0 -579
- package/src/plugins/registry.ts +0 -402
- package/src/plugins/types.ts +0 -46
- package/src/post/effects.ts +0 -930
- package/src/post/filters.ts +0 -489
- package/src/post/matrices.ts +0 -288
- package/src/renderables/ASCIIFont.ts +0 -219
- package/src/renderables/Box.test.ts +0 -205
- package/src/renderables/Box.ts +0 -326
- package/src/renderables/Code.test.ts +0 -2062
- package/src/renderables/Code.ts +0 -357
- package/src/renderables/Diff.regression.test.ts +0 -226
- package/src/renderables/Diff.test.ts +0 -3101
- package/src/renderables/Diff.ts +0 -1211
- package/src/renderables/EditBufferRenderable.test.ts +0 -288
- package/src/renderables/EditBufferRenderable.ts +0 -1166
- package/src/renderables/FrameBuffer.ts +0 -47
- package/src/renderables/Input.test.ts +0 -1228
- package/src/renderables/Input.ts +0 -247
- package/src/renderables/LineNumberRenderable.ts +0 -724
- package/src/renderables/Markdown.ts +0 -1393
- package/src/renderables/ScrollBar.ts +0 -422
- package/src/renderables/ScrollBox.ts +0 -883
- package/src/renderables/Select.test.ts +0 -1033
- package/src/renderables/Select.ts +0 -524
- package/src/renderables/Slider.test.ts +0 -456
- package/src/renderables/Slider.ts +0 -342
- package/src/renderables/TabSelect.test.ts +0 -197
- package/src/renderables/TabSelect.ts +0 -455
- package/src/renderables/Text.selection-buffer.test.ts +0 -123
- package/src/renderables/Text.test.ts +0 -2660
- package/src/renderables/Text.ts +0 -147
- package/src/renderables/TextBufferRenderable.ts +0 -518
- package/src/renderables/TextNode.test.ts +0 -1058
- package/src/renderables/TextNode.ts +0 -325
- package/src/renderables/TextTable.test.ts +0 -1421
- package/src/renderables/TextTable.ts +0 -1344
- package/src/renderables/Textarea.ts +0 -430
- package/src/renderables/TimeToFirstDraw.ts +0 -89
- package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
- package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
- package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
- package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -816
- package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1865
- package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
- package/src/renderables/__tests__/Markdown.code-colors.test.ts +0 -242
- package/src/renderables/__tests__/Markdown.test.ts +0 -2518
- package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
- package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -682
- package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
- package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2041
- package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
- package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
- package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
- package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3149
- package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
- package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1866
- package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
- package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1590
- package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
- package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
- package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
- package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
- package/src/renderables/__tests__/markdown-parser.test.ts +0 -217
- package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
- package/src/renderables/composition/README.md +0 -8
- package/src/renderables/composition/VRenderable.ts +0 -32
- package/src/renderables/composition/constructs.ts +0 -127
- package/src/renderables/composition/vnode.ts +0 -289
- package/src/renderables/index.ts +0 -23
- package/src/renderables/markdown-parser.ts +0 -66
- package/src/renderer.ts +0 -2681
- package/src/runtime-plugin-support.ts +0 -39
- package/src/runtime-plugin.ts +0 -615
- package/src/syntax-style.test.ts +0 -841
- package/src/syntax-style.ts +0 -257
- package/src/testing/README.md +0 -210
- package/src/testing/capture-spans.test.ts +0 -194
- package/src/testing/integration.test.ts +0 -276
- package/src/testing/manual-clock.ts +0 -117
- package/src/testing/mock-keys.test.ts +0 -1378
- package/src/testing/mock-keys.ts +0 -457
- package/src/testing/mock-mouse.test.ts +0 -218
- package/src/testing/mock-mouse.ts +0 -247
- package/src/testing/mock-tree-sitter-client.ts +0 -73
- package/src/testing/spy.ts +0 -13
- package/src/testing/test-recorder.test.ts +0 -415
- package/src/testing/test-recorder.ts +0 -145
- package/src/testing/test-renderer.ts +0 -132
- package/src/testing.ts +0 -7
- package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
- package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
- package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
- package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
- package/src/tests/allocator-stats.test.ts +0 -38
- package/src/tests/destroy-during-render.test.ts +0 -200
- package/src/tests/destroy-on-exit.fixture.ts +0 -36
- package/src/tests/destroy-on-exit.test.ts +0 -41
- package/src/tests/hover-cursor.test.ts +0 -98
- package/src/tests/native-span-feed-async.test.ts +0 -173
- package/src/tests/native-span-feed-close.test.ts +0 -120
- package/src/tests/native-span-feed-coverage.test.ts +0 -227
- package/src/tests/native-span-feed-edge-cases.test.ts +0 -352
- package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
- package/src/tests/opacity.test.ts +0 -123
- package/src/tests/renderable.snapshot.test.ts +0 -524
- package/src/tests/renderable.test.ts +0 -1281
- package/src/tests/renderer.clock.test.ts +0 -158
- package/src/tests/renderer.console-startup.test.ts +0 -185
- package/src/tests/renderer.control.test.ts +0 -425
- package/src/tests/renderer.core-slot-binding.test.ts +0 -952
- package/src/tests/renderer.cursor.test.ts +0 -26
- package/src/tests/renderer.destroy-during-render.test.ts +0 -147
- package/src/tests/renderer.focus-restore.test.ts +0 -257
- package/src/tests/renderer.focus.test.ts +0 -294
- package/src/tests/renderer.idle.test.ts +0 -219
- package/src/tests/renderer.input.test.ts +0 -2237
- package/src/tests/renderer.kitty-flags.test.ts +0 -195
- package/src/tests/renderer.mouse.test.ts +0 -1274
- package/src/tests/renderer.palette.test.ts +0 -629
- package/src/tests/renderer.selection.test.ts +0 -49
- package/src/tests/renderer.slot-registry.test.ts +0 -684
- package/src/tests/renderer.useMouse.test.ts +0 -47
- package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +0 -76
- package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +0 -43
- package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +0 -67
- package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +0 -72
- package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +0 -44
- package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +0 -85
- package/src/tests/runtime-plugin-path-alias.fixture.ts +0 -43
- package/src/tests/runtime-plugin-resolve-roots.fixture.ts +0 -65
- package/src/tests/runtime-plugin-support.fixture.ts +0 -11
- package/src/tests/runtime-plugin-support.test.ts +0 -19
- package/src/tests/runtime-plugin-windows-file-url.fixture.ts +0 -30
- package/src/tests/runtime-plugin.fixture.ts +0 -40
- package/src/tests/runtime-plugin.test.ts +0 -354
- package/src/tests/scrollbox-culling-bug.test.ts +0 -114
- package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
- package/src/tests/scrollbox-hitgrid.test.ts +0 -909
- package/src/tests/scrollbox.test.ts +0 -1530
- package/src/tests/wrap-resize-perf.test.ts +0 -276
- package/src/tests/yoga-setters.test.ts +0 -921
- package/src/text-buffer-view.test.ts +0 -705
- package/src/text-buffer-view.ts +0 -189
- package/src/text-buffer.test.ts +0 -347
- package/src/text-buffer.ts +0 -250
- package/src/types.ts +0 -161
- package/src/utils.ts +0 -88
- package/src/zig/ansi.zig +0 -268
- package/src/zig/bench/README.md +0 -50
- package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -887
- package/src/zig/bench/edit-buffer_bench.zig +0 -476
- package/src/zig/bench/native-span-feed_bench.zig +0 -100
- package/src/zig/bench/rope-markers_bench.zig +0 -713
- package/src/zig/bench/rope_bench.zig +0 -514
- package/src/zig/bench/styled-text_bench.zig +0 -470
- package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
- package/src/zig/bench/text-buffer-view_bench.zig +0 -459
- package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -273
- package/src/zig/bench/utf8_bench.zig +0 -799
- package/src/zig/bench-utils.zig +0 -431
- package/src/zig/bench.zig +0 -217
- package/src/zig/buffer-methods.zig +0 -211
- package/src/zig/buffer.zig +0 -2281
- package/src/zig/build.zig +0 -289
- package/src/zig/build.zig.zon +0 -16
- package/src/zig/edit-buffer.zig +0 -825
- package/src/zig/editor-view.zig +0 -802
- package/src/zig/event-bus.zig +0 -13
- package/src/zig/event-emitter.zig +0 -65
- package/src/zig/file-logger.zig +0 -92
- package/src/zig/grapheme.zig +0 -599
- package/src/zig/lib.zig +0 -1854
- package/src/zig/link.zig +0 -333
- package/src/zig/logger.zig +0 -43
- package/src/zig/mem-registry.zig +0 -125
- package/src/zig/native-span-feed-bench-lib.zig +0 -7
- package/src/zig/native-span-feed.zig +0 -708
- package/src/zig/renderer.zig +0 -1393
- package/src/zig/rope.zig +0 -1220
- package/src/zig/syntax-style.zig +0 -161
- package/src/zig/terminal.zig +0 -987
- package/src/zig/test.zig +0 -72
- package/src/zig/tests/README.md +0 -18
- package/src/zig/tests/buffer-methods_test.zig +0 -1109
- package/src/zig/tests/buffer_test.zig +0 -2557
- package/src/zig/tests/edit-buffer-history_test.zig +0 -271
- package/src/zig/tests/edit-buffer_test.zig +0 -1689
- package/src/zig/tests/editor-view_test.zig +0 -3299
- package/src/zig/tests/event-emitter_test.zig +0 -249
- package/src/zig/tests/grapheme_test.zig +0 -1304
- package/src/zig/tests/link_test.zig +0 -190
- package/src/zig/tests/mem-registry_test.zig +0 -473
- package/src/zig/tests/memory_leak_regression_test.zig +0 -159
- package/src/zig/tests/native-span-feed_test.zig +0 -1264
- package/src/zig/tests/renderer_test.zig +0 -1017
- package/src/zig/tests/rope-nested_test.zig +0 -712
- package/src/zig/tests/rope_fuzz_test.zig +0 -238
- package/src/zig/tests/rope_test.zig +0 -2362
- package/src/zig/tests/segment-merge.test.zig +0 -148
- package/src/zig/tests/syntax-style_test.zig +0 -557
- package/src/zig/tests/terminal_test.zig +0 -754
- package/src/zig/tests/text-buffer-drawing_test.zig +0 -3237
- package/src/zig/tests/text-buffer-highlights_test.zig +0 -666
- package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
- package/src/zig/tests/text-buffer-segment_test.zig +0 -320
- package/src/zig/tests/text-buffer-selection_test.zig +0 -1035
- package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
- package/src/zig/tests/text-buffer-view_test.zig +0 -3649
- package/src/zig/tests/text-buffer_test.zig +0 -2191
- package/src/zig/tests/unicode-width-map.zon +0 -3909
- package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
- package/src/zig/tests/utf8_test.zig +0 -4057
- package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
- package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
- package/src/zig/tests/word-wrap-editing_test.zig +0 -498
- package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
- package/src/zig/text-buffer-iterators.zig +0 -499
- package/src/zig/text-buffer-segment.zig +0 -404
- package/src/zig/text-buffer-view.zig +0 -1371
- package/src/zig/text-buffer.zig +0 -1180
- package/src/zig/utf8.zig +0 -1948
- package/src/zig/utils.zig +0 -9
- package/src/zig-structs.ts +0 -261
- package/src/zig.ts +0 -3884
- package/tsconfig.build.json +0 -24
- package/tsconfig.json +0 -27
- /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
|
@@ -1,2362 +0,0 @@
|
|
|
1
|
-
const std = @import("std");
|
|
2
|
-
const rope_mod = @import("../rope.zig");
|
|
3
|
-
|
|
4
|
-
const SimpleItem = struct {
|
|
5
|
-
value: u32,
|
|
6
|
-
|
|
7
|
-
pub fn empty() SimpleItem {
|
|
8
|
-
return .{ .value = 0 };
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
pub fn is_empty(self: *const SimpleItem) bool {
|
|
12
|
-
return self.value == 0;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const ItemWithMetrics = struct {
|
|
17
|
-
value: u32,
|
|
18
|
-
size: u32,
|
|
19
|
-
|
|
20
|
-
pub const Metrics = struct {
|
|
21
|
-
total_size: u32 = 0,
|
|
22
|
-
|
|
23
|
-
pub fn add(self: *Metrics, other: Metrics) void {
|
|
24
|
-
self.total_size += other.total_size;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
pub fn measure(self: *const ItemWithMetrics) Metrics {
|
|
29
|
-
return .{ .total_size = self.size };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
pub fn empty() ItemWithMetrics {
|
|
33
|
-
return .{ .value = 0, .size = 0 };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
pub fn is_empty(self: *const ItemWithMetrics) bool {
|
|
37
|
-
return self.value == 0 and self.size == 0;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//===== Basic Rope Tests =====
|
|
42
|
-
|
|
43
|
-
test "Rope - can initialize with arena allocator" {
|
|
44
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
45
|
-
defer arena.deinit();
|
|
46
|
-
|
|
47
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
48
|
-
var rope = try RopeType.init(arena.allocator());
|
|
49
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count()); // Sentinel filtered
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
test "Rope - from_item creates single item rope" {
|
|
53
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
54
|
-
defer arena.deinit();
|
|
55
|
-
|
|
56
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
57
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 42 });
|
|
58
|
-
|
|
59
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
60
|
-
const item = rope.get(0);
|
|
61
|
-
try std.testing.expect(item != null);
|
|
62
|
-
try std.testing.expectEqual(@as(u32, 42), item.?.value);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
test "Rope - from_slice creates rope from multiple items" {
|
|
66
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
67
|
-
defer arena.deinit();
|
|
68
|
-
|
|
69
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
70
|
-
const items = [_]SimpleItem{
|
|
71
|
-
.{ .value = 1 },
|
|
72
|
-
.{ .value = 2 },
|
|
73
|
-
.{ .value = 3 },
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
77
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
78
|
-
|
|
79
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
80
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
81
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(2).?.value);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
test "Rope - get with out of bounds returns null" {
|
|
85
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
86
|
-
defer arena.deinit();
|
|
87
|
-
|
|
88
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
89
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
90
|
-
|
|
91
|
-
try std.testing.expect(rope.get(100) == null);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//===== Insert Tests =====
|
|
95
|
-
|
|
96
|
-
test "Rope - insert at beginning" {
|
|
97
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
98
|
-
defer arena.deinit();
|
|
99
|
-
|
|
100
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
101
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
102
|
-
|
|
103
|
-
try rope.insert(0, .{ .value = 0 });
|
|
104
|
-
|
|
105
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
106
|
-
try std.testing.expectEqual(@as(u32, 0), rope.get(0).?.value);
|
|
107
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(1).?.value);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
test "Rope - insert at end" {
|
|
111
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
112
|
-
defer arena.deinit();
|
|
113
|
-
|
|
114
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
115
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
116
|
-
|
|
117
|
-
try rope.insert(1, .{ .value = 2 });
|
|
118
|
-
|
|
119
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
120
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
121
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
test "Rope - multiple inserts" {
|
|
125
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
126
|
-
defer arena.deinit();
|
|
127
|
-
|
|
128
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
129
|
-
var rope = try RopeType.init(arena.allocator());
|
|
130
|
-
|
|
131
|
-
try rope.insert(0, .{ .value = 1 });
|
|
132
|
-
try rope.insert(1, .{ .value = 2 });
|
|
133
|
-
try rope.insert(2, .{ .value = 3 });
|
|
134
|
-
|
|
135
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count()); // Sentinel filtered
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//===== Delete Tests =====
|
|
139
|
-
|
|
140
|
-
test "Rope - delete at beginning" {
|
|
141
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
142
|
-
defer arena.deinit();
|
|
143
|
-
|
|
144
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
145
|
-
const items = [_]SimpleItem{
|
|
146
|
-
.{ .value = 1 },
|
|
147
|
-
.{ .value = 2 },
|
|
148
|
-
.{ .value = 3 },
|
|
149
|
-
};
|
|
150
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
151
|
-
|
|
152
|
-
try rope.delete(0);
|
|
153
|
-
|
|
154
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
155
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(0).?.value);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
test "Rope - delete in middle" {
|
|
159
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
160
|
-
defer arena.deinit();
|
|
161
|
-
|
|
162
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
163
|
-
const items = [_]SimpleItem{
|
|
164
|
-
.{ .value = 1 },
|
|
165
|
-
.{ .value = 2 },
|
|
166
|
-
.{ .value = 3 },
|
|
167
|
-
};
|
|
168
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
169
|
-
|
|
170
|
-
try rope.delete(1);
|
|
171
|
-
|
|
172
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
173
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
174
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(1).?.value);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
//===== Walk Tests =====
|
|
178
|
-
|
|
179
|
-
test "Rope - walk all items" {
|
|
180
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
181
|
-
defer arena.deinit();
|
|
182
|
-
|
|
183
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
184
|
-
const items = [_]SimpleItem{
|
|
185
|
-
.{ .value = 10 },
|
|
186
|
-
.{ .value = 20 },
|
|
187
|
-
.{ .value = 30 },
|
|
188
|
-
};
|
|
189
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
190
|
-
|
|
191
|
-
const Context = struct {
|
|
192
|
-
sum: u32 = 0,
|
|
193
|
-
|
|
194
|
-
fn walker(ctx: *anyopaque, data: *const SimpleItem, index: u32) RopeType.Node.WalkerResult {
|
|
195
|
-
_ = index;
|
|
196
|
-
const self = @as(*@This(), @ptrCast(@alignCast(ctx)));
|
|
197
|
-
self.sum += data.value;
|
|
198
|
-
return .{};
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
var ctx = Context{};
|
|
203
|
-
try rope.walk(&ctx, Context.walker);
|
|
204
|
-
|
|
205
|
-
try std.testing.expectEqual(@as(u32, 60), ctx.sum);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
test "Rope - walk with early exit" {
|
|
209
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
210
|
-
defer arena.deinit();
|
|
211
|
-
|
|
212
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
213
|
-
const items = [_]SimpleItem{
|
|
214
|
-
.{ .value = 1 },
|
|
215
|
-
.{ .value = 2 },
|
|
216
|
-
.{ .value = 3 },
|
|
217
|
-
};
|
|
218
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
219
|
-
|
|
220
|
-
const Context = struct {
|
|
221
|
-
count: u32 = 0,
|
|
222
|
-
|
|
223
|
-
fn walker(ctx: *anyopaque, data: *const SimpleItem, index: u32) RopeType.Node.WalkerResult {
|
|
224
|
-
_ = index;
|
|
225
|
-
const self = @as(*@This(), @ptrCast(@alignCast(ctx)));
|
|
226
|
-
self.count += 1;
|
|
227
|
-
if (data.value == 2) {
|
|
228
|
-
return .{ .keep_walking = false };
|
|
229
|
-
}
|
|
230
|
-
return .{};
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
var ctx = Context{};
|
|
235
|
-
try rope.walk(&ctx, Context.walker);
|
|
236
|
-
|
|
237
|
-
try std.testing.expectEqual(@as(u32, 2), ctx.count);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
//===== Metrics Tests =====
|
|
241
|
-
|
|
242
|
-
test "Rope - custom metrics are tracked" {
|
|
243
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
244
|
-
defer arena.deinit();
|
|
245
|
-
|
|
246
|
-
const RopeType = rope_mod.Rope(ItemWithMetrics);
|
|
247
|
-
const items = [_]ItemWithMetrics{
|
|
248
|
-
.{ .value = 1, .size = 10 },
|
|
249
|
-
.{ .value = 2, .size = 20 },
|
|
250
|
-
.{ .value = 3, .size = 30 },
|
|
251
|
-
};
|
|
252
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
253
|
-
|
|
254
|
-
const metrics = rope.root.metrics();
|
|
255
|
-
try std.testing.expectEqual(@as(u32, 3), metrics.count);
|
|
256
|
-
try std.testing.expectEqual(@as(u32, 60), metrics.custom.total_size);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
test "Rope - rebalance maintains data" {
|
|
260
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
261
|
-
defer arena.deinit();
|
|
262
|
-
|
|
263
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
264
|
-
var items: [20]SimpleItem = undefined;
|
|
265
|
-
for (&items, 0..) |*item, i| {
|
|
266
|
-
item.* = .{ .value = @intCast(i) };
|
|
267
|
-
}
|
|
268
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
269
|
-
|
|
270
|
-
try rope.rebalance(arena.allocator());
|
|
271
|
-
|
|
272
|
-
// Data should be preserved
|
|
273
|
-
try std.testing.expectEqual(@as(u32, 20), rope.count());
|
|
274
|
-
try std.testing.expectEqual(@as(u32, 0), rope.get(0).?.value);
|
|
275
|
-
try std.testing.expectEqual(@as(u32, 10), rope.get(10).?.value);
|
|
276
|
-
try std.testing.expectEqual(@as(u32, 19), rope.get(19).?.value);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
//===== Stress Tests =====
|
|
280
|
-
|
|
281
|
-
test "Rope - large number of items" {
|
|
282
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
283
|
-
defer arena.deinit();
|
|
284
|
-
|
|
285
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
286
|
-
var items: [100]SimpleItem = undefined;
|
|
287
|
-
for (&items, 0..) |*item, i| {
|
|
288
|
-
item.* = .{ .value = @intCast(i) };
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
292
|
-
|
|
293
|
-
try std.testing.expectEqual(@as(u32, 100), rope.count());
|
|
294
|
-
try std.testing.expectEqual(@as(u32, 0), rope.get(0).?.value);
|
|
295
|
-
try std.testing.expectEqual(@as(u32, 50), rope.get(50).?.value);
|
|
296
|
-
try std.testing.expectEqual(@as(u32, 99), rope.get(99).?.value);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
test "Rope - many insert operations" {
|
|
300
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
301
|
-
defer arena.deinit();
|
|
302
|
-
|
|
303
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
304
|
-
var rope = try RopeType.init(arena.allocator());
|
|
305
|
-
|
|
306
|
-
for (0..50) |i| {
|
|
307
|
-
try rope.insert(@intCast(i), .{ .value = @intCast(i) });
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
try std.testing.expectEqual(@as(u32, 50), rope.count()); // Sentinel filtered
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
//===== Nested Rope Tests (Lines→Chunks Pattern) =====
|
|
314
|
-
|
|
315
|
-
// Chunk type similar to what would be used in text buffer
|
|
316
|
-
const Chunk = struct {
|
|
317
|
-
data: []const u8,
|
|
318
|
-
width: u32,
|
|
319
|
-
|
|
320
|
-
pub const Metrics = struct {
|
|
321
|
-
total_width: u32 = 0,
|
|
322
|
-
total_bytes: u32 = 0,
|
|
323
|
-
|
|
324
|
-
pub fn add(self: *Metrics, other: Metrics) void {
|
|
325
|
-
self.total_width += other.total_width;
|
|
326
|
-
self.total_bytes += other.total_bytes;
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
pub fn measure(self: *const Chunk) Metrics {
|
|
331
|
-
return .{
|
|
332
|
-
.total_width = self.width,
|
|
333
|
-
.total_bytes = @intCast(self.data.len),
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
pub fn empty() Chunk {
|
|
338
|
-
return .{ .data = "", .width = 0 };
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
pub fn is_empty(self: *const Chunk) bool {
|
|
342
|
-
return self.data.len == 0;
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
// Static empty chunk rope node for Line.empty()
|
|
347
|
-
const empty_chunk_leaf_node = rope_mod.Rope(Chunk).Node{
|
|
348
|
-
.leaf = .{
|
|
349
|
-
.data = Chunk.empty(),
|
|
350
|
-
},
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
// Line type containing a rope of chunks
|
|
354
|
-
const Line = struct {
|
|
355
|
-
chunks: rope_mod.Rope(Chunk),
|
|
356
|
-
line_id: u32,
|
|
357
|
-
|
|
358
|
-
pub const Metrics = struct {
|
|
359
|
-
total_width: u32 = 0,
|
|
360
|
-
total_lines: u32 = 1,
|
|
361
|
-
|
|
362
|
-
pub fn add(self: *Metrics, other: Metrics) void {
|
|
363
|
-
self.total_width += other.total_width;
|
|
364
|
-
self.total_lines += other.total_lines;
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
pub fn measure(self: *const Line) Metrics {
|
|
369
|
-
const chunk_metrics = self.chunks.root.metrics();
|
|
370
|
-
return .{
|
|
371
|
-
.total_width = chunk_metrics.custom.total_width,
|
|
372
|
-
.total_lines = 1,
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
pub fn empty() Line {
|
|
377
|
-
// Use static empty chunk rope - safe because it's immutable
|
|
378
|
-
const ChunkRope = rope_mod.Rope(Chunk);
|
|
379
|
-
return .{
|
|
380
|
-
.chunks = .{
|
|
381
|
-
.root = &empty_chunk_leaf_node,
|
|
382
|
-
.allocator = undefined, // Never used for empty
|
|
383
|
-
.empty_leaf = &empty_chunk_leaf_node,
|
|
384
|
-
.marker_cache = ChunkRope.MarkerCache.init(undefined),
|
|
385
|
-
},
|
|
386
|
-
.line_id = 0,
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
pub fn is_empty(self: *const Line) bool {
|
|
391
|
-
return self.line_id == 0 and self.chunks.count() == 1;
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
test "Rope - replace item at index" {
|
|
396
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
397
|
-
defer arena.deinit();
|
|
398
|
-
|
|
399
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
400
|
-
const items = [_]SimpleItem{
|
|
401
|
-
.{ .value = 1 },
|
|
402
|
-
.{ .value = 2 },
|
|
403
|
-
.{ .value = 3 },
|
|
404
|
-
};
|
|
405
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
406
|
-
|
|
407
|
-
try rope.replace(1, .{ .value = 20 });
|
|
408
|
-
|
|
409
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
410
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
411
|
-
try std.testing.expectEqual(@as(u32, 20), rope.get(1).?.value);
|
|
412
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(2).?.value);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
test "Rope - append item" {
|
|
416
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
417
|
-
defer arena.deinit();
|
|
418
|
-
|
|
419
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
420
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
421
|
-
|
|
422
|
-
try rope.append(.{ .value = 2 });
|
|
423
|
-
try rope.append(.{ .value = 3 });
|
|
424
|
-
|
|
425
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
426
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
427
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
428
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(2).?.value);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
test "Rope - prepend item" {
|
|
432
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
433
|
-
defer arena.deinit();
|
|
434
|
-
|
|
435
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
436
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 3 });
|
|
437
|
-
|
|
438
|
-
try rope.prepend(.{ .value = 2 });
|
|
439
|
-
try rope.prepend(.{ .value = 1 });
|
|
440
|
-
|
|
441
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
442
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
443
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
444
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(2).?.value);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
test "Rope - concatenate two ropes" {
|
|
448
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
449
|
-
defer arena.deinit();
|
|
450
|
-
|
|
451
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
452
|
-
|
|
453
|
-
const items1 = [_]SimpleItem{
|
|
454
|
-
.{ .value = 1 },
|
|
455
|
-
.{ .value = 2 },
|
|
456
|
-
};
|
|
457
|
-
var rope1 = try RopeType.from_slice(arena.allocator(), &items1);
|
|
458
|
-
|
|
459
|
-
const items2 = [_]SimpleItem{
|
|
460
|
-
.{ .value = 3 },
|
|
461
|
-
.{ .value = 4 },
|
|
462
|
-
};
|
|
463
|
-
const rope2 = try RopeType.from_slice(arena.allocator(), &items2);
|
|
464
|
-
|
|
465
|
-
try rope1.concat(&rope2);
|
|
466
|
-
|
|
467
|
-
try std.testing.expectEqual(@as(u32, 4), rope1.count());
|
|
468
|
-
try std.testing.expectEqual(@as(u32, 1), rope1.get(0).?.value);
|
|
469
|
-
try std.testing.expectEqual(@as(u32, 2), rope1.get(1).?.value);
|
|
470
|
-
try std.testing.expectEqual(@as(u32, 3), rope1.get(2).?.value);
|
|
471
|
-
try std.testing.expectEqual(@as(u32, 4), rope1.get(3).?.value);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
//===== Undo/Redo Tests =====
|
|
475
|
-
|
|
476
|
-
test "Rope - basic undo operation" {
|
|
477
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
478
|
-
defer arena.deinit();
|
|
479
|
-
|
|
480
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
481
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
482
|
-
|
|
483
|
-
try rope.store_undo("initial");
|
|
484
|
-
|
|
485
|
-
try rope.insert(1, .{ .value = 2 });
|
|
486
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
487
|
-
|
|
488
|
-
const meta = try rope.undo("before undo");
|
|
489
|
-
try std.testing.expectEqualStrings("initial", meta);
|
|
490
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
test "Rope - basic redo operation" {
|
|
494
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
495
|
-
defer arena.deinit();
|
|
496
|
-
|
|
497
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
498
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
499
|
-
|
|
500
|
-
try rope.store_undo("initial");
|
|
501
|
-
try rope.insert(1, .{ .value = 2 });
|
|
502
|
-
|
|
503
|
-
_ = try rope.undo("before undo");
|
|
504
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
505
|
-
|
|
506
|
-
const meta = try rope.redo();
|
|
507
|
-
try std.testing.expectEqualStrings("before undo", meta);
|
|
508
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
test "Rope - multiple undo/redo operations" {
|
|
512
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
513
|
-
defer arena.deinit();
|
|
514
|
-
|
|
515
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
516
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
517
|
-
|
|
518
|
-
try rope.store_undo("state1");
|
|
519
|
-
try rope.append(.{ .value = 2 });
|
|
520
|
-
|
|
521
|
-
try rope.store_undo("state2");
|
|
522
|
-
try rope.append(.{ .value = 3 });
|
|
523
|
-
|
|
524
|
-
try rope.store_undo("state3");
|
|
525
|
-
try rope.append(.{ .value = 4 });
|
|
526
|
-
|
|
527
|
-
try std.testing.expectEqual(@as(u32, 4), rope.count());
|
|
528
|
-
|
|
529
|
-
_ = try rope.undo("current");
|
|
530
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
531
|
-
|
|
532
|
-
_ = try rope.undo("current");
|
|
533
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
534
|
-
|
|
535
|
-
_ = try rope.redo();
|
|
536
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
test "Rope - undo/redo with delete operations" {
|
|
540
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
541
|
-
defer arena.deinit();
|
|
542
|
-
|
|
543
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
544
|
-
const items = [_]SimpleItem{
|
|
545
|
-
.{ .value = 1 },
|
|
546
|
-
.{ .value = 2 },
|
|
547
|
-
.{ .value = 3 },
|
|
548
|
-
};
|
|
549
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
550
|
-
|
|
551
|
-
try rope.store_undo("before delete");
|
|
552
|
-
try rope.delete(1);
|
|
553
|
-
|
|
554
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
555
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
556
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(1).?.value);
|
|
557
|
-
|
|
558
|
-
_ = try rope.undo("after delete");
|
|
559
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
560
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
test "Rope - undo/redo with replace operations" {
|
|
564
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
565
|
-
defer arena.deinit();
|
|
566
|
-
|
|
567
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
568
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 10 });
|
|
569
|
-
|
|
570
|
-
try rope.store_undo("original");
|
|
571
|
-
try rope.replace(0, .{ .value = 20 });
|
|
572
|
-
try std.testing.expectEqual(@as(u32, 20), rope.get(0).?.value);
|
|
573
|
-
|
|
574
|
-
_ = try rope.undo("after replace");
|
|
575
|
-
try std.testing.expectEqual(@as(u32, 10), rope.get(0).?.value);
|
|
576
|
-
|
|
577
|
-
_ = try rope.redo();
|
|
578
|
-
try std.testing.expectEqual(@as(u32, 20), rope.get(0).?.value);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
test "Rope - can_undo and can_redo" {
|
|
582
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
583
|
-
defer arena.deinit();
|
|
584
|
-
|
|
585
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
586
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
587
|
-
|
|
588
|
-
try std.testing.expect(!rope.can_undo());
|
|
589
|
-
try std.testing.expect(!rope.can_redo());
|
|
590
|
-
|
|
591
|
-
try rope.store_undo("state1");
|
|
592
|
-
try std.testing.expect(rope.can_undo());
|
|
593
|
-
try std.testing.expect(!rope.can_redo());
|
|
594
|
-
|
|
595
|
-
_ = try rope.undo("current");
|
|
596
|
-
try std.testing.expect(!rope.can_undo()); // No more undo (only one state)
|
|
597
|
-
try std.testing.expect(rope.can_redo());
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
test "Rope - clear history" {
|
|
601
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
602
|
-
defer arena.deinit();
|
|
603
|
-
|
|
604
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
605
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
606
|
-
|
|
607
|
-
try rope.store_undo("state1");
|
|
608
|
-
try rope.append(.{ .value = 2 });
|
|
609
|
-
try rope.store_undo("state2");
|
|
610
|
-
|
|
611
|
-
try std.testing.expect(rope.can_undo());
|
|
612
|
-
|
|
613
|
-
rope.clear_history();
|
|
614
|
-
try std.testing.expect(!rope.can_undo());
|
|
615
|
-
try std.testing.expect(!rope.can_redo());
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
test "Rope - undo fails when no history" {
|
|
619
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
620
|
-
defer arena.deinit();
|
|
621
|
-
|
|
622
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
623
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
624
|
-
|
|
625
|
-
// No history stored, undo should fail
|
|
626
|
-
const result = rope.undo("current");
|
|
627
|
-
try std.testing.expectError(error.Stop, result);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
test "Rope - redo fails when no redo history" {
|
|
631
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
632
|
-
defer arena.deinit();
|
|
633
|
-
|
|
634
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
635
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
636
|
-
|
|
637
|
-
// No redo history, redo should fail
|
|
638
|
-
const result = rope.redo();
|
|
639
|
-
try std.testing.expectError(error.Stop, result);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
test "Rope - complex undo/redo workflow" {
|
|
643
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
644
|
-
defer arena.deinit();
|
|
645
|
-
|
|
646
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
647
|
-
var rope = try RopeType.init(arena.allocator());
|
|
648
|
-
|
|
649
|
-
// Build up a sequence of operations
|
|
650
|
-
try rope.store_undo("empty");
|
|
651
|
-
try rope.insert(0, .{ .value = 1 });
|
|
652
|
-
|
|
653
|
-
try rope.store_undo("one item");
|
|
654
|
-
try rope.append(.{ .value = 2 });
|
|
655
|
-
|
|
656
|
-
try rope.store_undo("two items");
|
|
657
|
-
try rope.append(.{ .value = 3 });
|
|
658
|
-
|
|
659
|
-
try rope.store_undo("three items");
|
|
660
|
-
try rope.delete(1); // Remove middle
|
|
661
|
-
|
|
662
|
-
// State: [1, 3]
|
|
663
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count()); // Sentinel filtered
|
|
664
|
-
|
|
665
|
-
// Undo delete
|
|
666
|
-
_ = try rope.undo("current");
|
|
667
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
668
|
-
|
|
669
|
-
// Undo append
|
|
670
|
-
_ = try rope.undo("current");
|
|
671
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
672
|
-
|
|
673
|
-
// Redo append
|
|
674
|
-
_ = try rope.redo();
|
|
675
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
test "Rope - undo/redo with metadata tracking" {
|
|
679
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
680
|
-
defer arena.deinit();
|
|
681
|
-
|
|
682
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
683
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
684
|
-
|
|
685
|
-
try rope.store_undo("insert operation");
|
|
686
|
-
try rope.append(.{ .value = 2 });
|
|
687
|
-
|
|
688
|
-
try rope.store_undo("delete operation");
|
|
689
|
-
try rope.delete(0);
|
|
690
|
-
|
|
691
|
-
// Undo and check metadata
|
|
692
|
-
const meta1 = try rope.undo("current state");
|
|
693
|
-
try std.testing.expectEqualStrings("delete operation", meta1);
|
|
694
|
-
|
|
695
|
-
const meta2 = try rope.undo("current state");
|
|
696
|
-
try std.testing.expectEqualStrings("insert operation", meta2);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
test "Rope - undo invalidates redo after new operation" {
|
|
700
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
701
|
-
defer arena.deinit();
|
|
702
|
-
|
|
703
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
704
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
705
|
-
|
|
706
|
-
try rope.store_undo("state1");
|
|
707
|
-
try rope.append(.{ .value = 2 });
|
|
708
|
-
|
|
709
|
-
try rope.store_undo("state2");
|
|
710
|
-
try rope.append(.{ .value = 3 });
|
|
711
|
-
|
|
712
|
-
// Undo once
|
|
713
|
-
_ = try rope.undo("current");
|
|
714
|
-
try std.testing.expect(rope.can_redo());
|
|
715
|
-
|
|
716
|
-
// Make a new change - this stores the old redo as a branch and clears redo
|
|
717
|
-
try rope.store_undo("new branch");
|
|
718
|
-
try rope.append(.{ .value = 99 });
|
|
719
|
-
|
|
720
|
-
// Redo should NOT work anymore (it was saved as a branch)
|
|
721
|
-
try std.testing.expect(!rope.can_redo());
|
|
722
|
-
|
|
723
|
-
// But we can still undo
|
|
724
|
-
try std.testing.expect(rope.can_undo());
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
test "Rope - undo/redo with nested ropes" {
|
|
728
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
729
|
-
defer arena.deinit();
|
|
730
|
-
const allocator = arena.allocator();
|
|
731
|
-
|
|
732
|
-
const chunks1 = [_]Chunk{.{ .data = "Line 1", .width = 6 }};
|
|
733
|
-
const line1 = Line{
|
|
734
|
-
.chunks = try rope_mod.Rope(Chunk).from_slice(allocator, &chunks1),
|
|
735
|
-
.line_id = 1,
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
const RopeType = rope_mod.Rope(Line);
|
|
739
|
-
var rope = try RopeType.from_item(allocator, line1);
|
|
740
|
-
|
|
741
|
-
try rope.store_undo("before append");
|
|
742
|
-
|
|
743
|
-
const chunks2 = [_]Chunk{.{ .data = "Line 2", .width = 6 }};
|
|
744
|
-
const line2 = Line{
|
|
745
|
-
.chunks = try rope_mod.Rope(Chunk).from_slice(allocator, &chunks2),
|
|
746
|
-
.line_id = 2,
|
|
747
|
-
};
|
|
748
|
-
try rope.append(line2);
|
|
749
|
-
|
|
750
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
751
|
-
|
|
752
|
-
// Undo
|
|
753
|
-
_ = try rope.undo("after append");
|
|
754
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
755
|
-
|
|
756
|
-
// Redo
|
|
757
|
-
_ = try rope.redo();
|
|
758
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
test "Rope - stress test undo/redo with many operations" {
|
|
762
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
763
|
-
defer arena.deinit();
|
|
764
|
-
|
|
765
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
766
|
-
var rope = try RopeType.init(arena.allocator());
|
|
767
|
-
|
|
768
|
-
// Perform 20 operations
|
|
769
|
-
for (0..20) |i| {
|
|
770
|
-
try rope.store_undo("operation");
|
|
771
|
-
try rope.append(.{ .value = @intCast(i) });
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
try std.testing.expectEqual(@as(u32, 20), rope.count()); // Sentinel filtered
|
|
775
|
-
|
|
776
|
-
// Undo 10 operations
|
|
777
|
-
for (0..10) |_| {
|
|
778
|
-
_ = try rope.undo("current");
|
|
779
|
-
}
|
|
780
|
-
try std.testing.expectEqual(@as(u32, 10), rope.count());
|
|
781
|
-
|
|
782
|
-
// Redo 5 operations
|
|
783
|
-
for (0..5) |_| {
|
|
784
|
-
_ = try rope.redo();
|
|
785
|
-
}
|
|
786
|
-
try std.testing.expectEqual(@as(u32, 15), rope.count());
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
//===== Bulk/Range Operations Tests =====
|
|
790
|
-
|
|
791
|
-
test "Rope - split at beginning" {
|
|
792
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
793
|
-
defer arena.deinit();
|
|
794
|
-
|
|
795
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
796
|
-
const items = [_]SimpleItem{
|
|
797
|
-
.{ .value = 1 },
|
|
798
|
-
.{ .value = 2 },
|
|
799
|
-
.{ .value = 3 },
|
|
800
|
-
};
|
|
801
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
802
|
-
|
|
803
|
-
const right = try rope.split(0);
|
|
804
|
-
|
|
805
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count()); // Sentinel filtered
|
|
806
|
-
try std.testing.expectEqual(@as(u32, 3), right.count());
|
|
807
|
-
try std.testing.expectEqual(@as(u32, 1), right.get(0).?.value);
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
test "Rope - split at middle" {
|
|
811
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
812
|
-
defer arena.deinit();
|
|
813
|
-
|
|
814
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
815
|
-
const items = [_]SimpleItem{
|
|
816
|
-
.{ .value = 1 },
|
|
817
|
-
.{ .value = 2 },
|
|
818
|
-
.{ .value = 3 },
|
|
819
|
-
.{ .value = 4 },
|
|
820
|
-
.{ .value = 5 },
|
|
821
|
-
};
|
|
822
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
823
|
-
|
|
824
|
-
const right = try rope.split(2);
|
|
825
|
-
|
|
826
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
827
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
828
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
829
|
-
|
|
830
|
-
try std.testing.expectEqual(@as(u32, 3), right.count());
|
|
831
|
-
try std.testing.expectEqual(@as(u32, 3), right.get(0).?.value);
|
|
832
|
-
try std.testing.expectEqual(@as(u32, 4), right.get(1).?.value);
|
|
833
|
-
try std.testing.expectEqual(@as(u32, 5), right.get(2).?.value);
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
test "Rope - split at end" {
|
|
837
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
838
|
-
defer arena.deinit();
|
|
839
|
-
|
|
840
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
841
|
-
const items = [_]SimpleItem{
|
|
842
|
-
.{ .value = 1 },
|
|
843
|
-
.{ .value = 2 },
|
|
844
|
-
.{ .value = 3 },
|
|
845
|
-
};
|
|
846
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
847
|
-
|
|
848
|
-
const right = try rope.split(3);
|
|
849
|
-
|
|
850
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
851
|
-
try std.testing.expectEqual(@as(u32, 0), right.count()); // Sentinel filtered
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
test "Rope - slice full range" {
|
|
855
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
856
|
-
defer arena.deinit();
|
|
857
|
-
|
|
858
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
859
|
-
const items = [_]SimpleItem{
|
|
860
|
-
.{ .value = 1 },
|
|
861
|
-
.{ .value = 2 },
|
|
862
|
-
.{ .value = 3 },
|
|
863
|
-
};
|
|
864
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
865
|
-
|
|
866
|
-
const sliced = try rope.slice(0, 3, arena.allocator());
|
|
867
|
-
defer arena.allocator().free(sliced);
|
|
868
|
-
|
|
869
|
-
try std.testing.expectEqual(@as(usize, 3), sliced.len);
|
|
870
|
-
try std.testing.expectEqual(@as(u32, 1), sliced[0].value);
|
|
871
|
-
try std.testing.expectEqual(@as(u32, 2), sliced[1].value);
|
|
872
|
-
try std.testing.expectEqual(@as(u32, 3), sliced[2].value);
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
test "Rope - slice partial range" {
|
|
876
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
877
|
-
defer arena.deinit();
|
|
878
|
-
|
|
879
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
880
|
-
const items = [_]SimpleItem{
|
|
881
|
-
.{ .value = 10 },
|
|
882
|
-
.{ .value = 20 },
|
|
883
|
-
.{ .value = 30 },
|
|
884
|
-
.{ .value = 40 },
|
|
885
|
-
.{ .value = 50 },
|
|
886
|
-
};
|
|
887
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
888
|
-
|
|
889
|
-
const sliced = try rope.slice(1, 4, arena.allocator());
|
|
890
|
-
defer arena.allocator().free(sliced);
|
|
891
|
-
|
|
892
|
-
try std.testing.expectEqual(@as(usize, 3), sliced.len);
|
|
893
|
-
try std.testing.expectEqual(@as(u32, 20), sliced[0].value);
|
|
894
|
-
try std.testing.expectEqual(@as(u32, 30), sliced[1].value);
|
|
895
|
-
try std.testing.expectEqual(@as(u32, 40), sliced[2].value);
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
test "Rope - slice empty range" {
|
|
899
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
900
|
-
defer arena.deinit();
|
|
901
|
-
|
|
902
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
903
|
-
const items = [_]SimpleItem{
|
|
904
|
-
.{ .value = 1 },
|
|
905
|
-
.{ .value = 2 },
|
|
906
|
-
};
|
|
907
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
908
|
-
|
|
909
|
-
const sliced = try rope.slice(1, 1, arena.allocator());
|
|
910
|
-
defer arena.allocator().free(sliced);
|
|
911
|
-
|
|
912
|
-
try std.testing.expectEqual(@as(usize, 0), sliced.len);
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
test "Rope - delete_range at beginning" {
|
|
916
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
917
|
-
defer arena.deinit();
|
|
918
|
-
|
|
919
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
920
|
-
const items = [_]SimpleItem{
|
|
921
|
-
.{ .value = 1 },
|
|
922
|
-
.{ .value = 2 },
|
|
923
|
-
.{ .value = 3 },
|
|
924
|
-
.{ .value = 4 },
|
|
925
|
-
.{ .value = 5 },
|
|
926
|
-
};
|
|
927
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
928
|
-
|
|
929
|
-
try rope.delete_range(0, 2);
|
|
930
|
-
|
|
931
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
932
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(0).?.value);
|
|
933
|
-
try std.testing.expectEqual(@as(u32, 4), rope.get(1).?.value);
|
|
934
|
-
try std.testing.expectEqual(@as(u32, 5), rope.get(2).?.value);
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
test "Rope - delete_range in middle" {
|
|
938
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
939
|
-
defer arena.deinit();
|
|
940
|
-
|
|
941
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
942
|
-
const items = [_]SimpleItem{
|
|
943
|
-
.{ .value = 1 },
|
|
944
|
-
.{ .value = 2 },
|
|
945
|
-
.{ .value = 3 },
|
|
946
|
-
.{ .value = 4 },
|
|
947
|
-
.{ .value = 5 },
|
|
948
|
-
};
|
|
949
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
950
|
-
|
|
951
|
-
try rope.delete_range(1, 4);
|
|
952
|
-
|
|
953
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
954
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
955
|
-
try std.testing.expectEqual(@as(u32, 5), rope.get(1).?.value);
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
test "Rope - delete_range at end" {
|
|
959
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
960
|
-
defer arena.deinit();
|
|
961
|
-
|
|
962
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
963
|
-
const items = [_]SimpleItem{
|
|
964
|
-
.{ .value = 1 },
|
|
965
|
-
.{ .value = 2 },
|
|
966
|
-
.{ .value = 3 },
|
|
967
|
-
};
|
|
968
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
969
|
-
|
|
970
|
-
try rope.delete_range(1, 3);
|
|
971
|
-
|
|
972
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
973
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
test "Rope - delete_range empty (same indices)" {
|
|
977
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
978
|
-
defer arena.deinit();
|
|
979
|
-
|
|
980
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
981
|
-
const items = [_]SimpleItem{
|
|
982
|
-
.{ .value = 1 },
|
|
983
|
-
.{ .value = 2 },
|
|
984
|
-
};
|
|
985
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
986
|
-
|
|
987
|
-
try rope.delete_range(1, 1);
|
|
988
|
-
|
|
989
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
test "Rope - insert_slice at beginning" {
|
|
993
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
994
|
-
defer arena.deinit();
|
|
995
|
-
|
|
996
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
997
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 3 });
|
|
998
|
-
|
|
999
|
-
const to_insert = [_]SimpleItem{
|
|
1000
|
-
.{ .value = 1 },
|
|
1001
|
-
.{ .value = 2 },
|
|
1002
|
-
};
|
|
1003
|
-
try rope.insert_slice(0, &to_insert);
|
|
1004
|
-
|
|
1005
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
1006
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
1007
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
1008
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(2).?.value);
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
test "Rope - insert_slice in middle" {
|
|
1012
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1013
|
-
defer arena.deinit();
|
|
1014
|
-
|
|
1015
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1016
|
-
const items = [_]SimpleItem{
|
|
1017
|
-
.{ .value = 1 },
|
|
1018
|
-
.{ .value = 4 },
|
|
1019
|
-
};
|
|
1020
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1021
|
-
|
|
1022
|
-
const to_insert = [_]SimpleItem{
|
|
1023
|
-
.{ .value = 2 },
|
|
1024
|
-
.{ .value = 3 },
|
|
1025
|
-
};
|
|
1026
|
-
try rope.insert_slice(1, &to_insert);
|
|
1027
|
-
|
|
1028
|
-
try std.testing.expectEqual(@as(u32, 4), rope.count());
|
|
1029
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
1030
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
1031
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(2).?.value);
|
|
1032
|
-
try std.testing.expectEqual(@as(u32, 4), rope.get(3).?.value);
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
test "Rope - insert_slice at end" {
|
|
1036
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1037
|
-
defer arena.deinit();
|
|
1038
|
-
|
|
1039
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1040
|
-
const items = [_]SimpleItem{
|
|
1041
|
-
.{ .value = 1 },
|
|
1042
|
-
.{ .value = 2 },
|
|
1043
|
-
};
|
|
1044
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1045
|
-
|
|
1046
|
-
const to_insert = [_]SimpleItem{
|
|
1047
|
-
.{ .value = 3 },
|
|
1048
|
-
.{ .value = 4 },
|
|
1049
|
-
};
|
|
1050
|
-
try rope.insert_slice(2, &to_insert);
|
|
1051
|
-
|
|
1052
|
-
try std.testing.expectEqual(@as(u32, 4), rope.count());
|
|
1053
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(2).?.value);
|
|
1054
|
-
try std.testing.expectEqual(@as(u32, 4), rope.get(3).?.value);
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
test "Rope - insert_slice empty array" {
|
|
1058
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1059
|
-
defer arena.deinit();
|
|
1060
|
-
|
|
1061
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1062
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
1063
|
-
|
|
1064
|
-
const to_insert: []const SimpleItem = &[_]SimpleItem{};
|
|
1065
|
-
try rope.insert_slice(0, to_insert);
|
|
1066
|
-
|
|
1067
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
test "Rope - to_array with simple items" {
|
|
1071
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1072
|
-
defer arena.deinit();
|
|
1073
|
-
|
|
1074
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1075
|
-
const items = [_]SimpleItem{
|
|
1076
|
-
.{ .value = 10 },
|
|
1077
|
-
.{ .value = 20 },
|
|
1078
|
-
.{ .value = 30 },
|
|
1079
|
-
};
|
|
1080
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1081
|
-
|
|
1082
|
-
const array = try rope.to_array(arena.allocator());
|
|
1083
|
-
defer arena.allocator().free(array);
|
|
1084
|
-
|
|
1085
|
-
try std.testing.expectEqual(@as(usize, 3), array.len);
|
|
1086
|
-
try std.testing.expectEqual(@as(u32, 10), array[0].value);
|
|
1087
|
-
try std.testing.expectEqual(@as(u32, 20), array[1].value);
|
|
1088
|
-
try std.testing.expectEqual(@as(u32, 30), array[2].value);
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
test "Rope - to_array empty rope" {
|
|
1092
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1093
|
-
defer arena.deinit();
|
|
1094
|
-
|
|
1095
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1096
|
-
var rope = try RopeType.init(arena.allocator());
|
|
1097
|
-
|
|
1098
|
-
const array = try rope.to_array(arena.allocator());
|
|
1099
|
-
defer arena.allocator().free(array);
|
|
1100
|
-
|
|
1101
|
-
try std.testing.expectEqual(@as(usize, 0), array.len); // Sentinel filtered
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
test "Rope - combined bulk operations" {
|
|
1105
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1106
|
-
defer arena.deinit();
|
|
1107
|
-
|
|
1108
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1109
|
-
const items = [_]SimpleItem{
|
|
1110
|
-
.{ .value = 1 },
|
|
1111
|
-
.{ .value = 2 },
|
|
1112
|
-
.{ .value = 3 },
|
|
1113
|
-
.{ .value = 4 },
|
|
1114
|
-
.{ .value = 5 },
|
|
1115
|
-
};
|
|
1116
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1117
|
-
|
|
1118
|
-
try rope.delete_range(2, 4);
|
|
1119
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
1120
|
-
|
|
1121
|
-
const to_insert = [_]SimpleItem{
|
|
1122
|
-
.{ .value = 30 },
|
|
1123
|
-
.{ .value = 40 },
|
|
1124
|
-
};
|
|
1125
|
-
try rope.insert_slice(1, &to_insert);
|
|
1126
|
-
try std.testing.expectEqual(@as(u32, 5), rope.count());
|
|
1127
|
-
|
|
1128
|
-
const array = try rope.to_array(arena.allocator());
|
|
1129
|
-
defer arena.allocator().free(array);
|
|
1130
|
-
|
|
1131
|
-
try std.testing.expectEqual(@as(u32, 1), array[0].value);
|
|
1132
|
-
try std.testing.expectEqual(@as(u32, 30), array[1].value);
|
|
1133
|
-
try std.testing.expectEqual(@as(u32, 40), array[2].value);
|
|
1134
|
-
try std.testing.expectEqual(@as(u32, 2), array[3].value);
|
|
1135
|
-
try std.testing.expectEqual(@as(u32, 5), array[4].value);
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
test "Rope - undo/redo with bulk operations" {
|
|
1139
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1140
|
-
defer arena.deinit();
|
|
1141
|
-
|
|
1142
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1143
|
-
const items = [_]SimpleItem{
|
|
1144
|
-
.{ .value = 1 },
|
|
1145
|
-
.{ .value = 2 },
|
|
1146
|
-
.{ .value = 3 },
|
|
1147
|
-
};
|
|
1148
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1149
|
-
|
|
1150
|
-
// Store state
|
|
1151
|
-
try rope.store_undo("before bulk");
|
|
1152
|
-
|
|
1153
|
-
// Bulk insert
|
|
1154
|
-
const to_insert = [_]SimpleItem{
|
|
1155
|
-
.{ .value = 10 },
|
|
1156
|
-
.{ .value = 20 },
|
|
1157
|
-
};
|
|
1158
|
-
try rope.insert_slice(1, &to_insert);
|
|
1159
|
-
try std.testing.expectEqual(@as(u32, 5), rope.count());
|
|
1160
|
-
|
|
1161
|
-
// Undo
|
|
1162
|
-
_ = try rope.undo("after bulk");
|
|
1163
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
1164
|
-
|
|
1165
|
-
// Redo
|
|
1166
|
-
_ = try rope.redo();
|
|
1167
|
-
try std.testing.expectEqual(@as(u32, 5), rope.count());
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
//===== Edge Case Tests =====
|
|
1171
|
-
|
|
1172
|
-
test "Rope - slice with start > end returns empty" {
|
|
1173
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1174
|
-
defer arena.deinit();
|
|
1175
|
-
|
|
1176
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1177
|
-
const items = [_]SimpleItem{
|
|
1178
|
-
.{ .value = 1 },
|
|
1179
|
-
.{ .value = 2 },
|
|
1180
|
-
.{ .value = 3 },
|
|
1181
|
-
};
|
|
1182
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1183
|
-
|
|
1184
|
-
const sliced = try rope.slice(2, 1, arena.allocator());
|
|
1185
|
-
defer arena.allocator().free(sliced);
|
|
1186
|
-
|
|
1187
|
-
try std.testing.expectEqual(@as(usize, 0), sliced.len);
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
test "Rope - slice beyond bounds" {
|
|
1191
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1192
|
-
defer arena.deinit();
|
|
1193
|
-
|
|
1194
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1195
|
-
const items = [_]SimpleItem{
|
|
1196
|
-
.{ .value = 1 },
|
|
1197
|
-
.{ .value = 2 },
|
|
1198
|
-
};
|
|
1199
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1200
|
-
|
|
1201
|
-
// Should only get items that exist
|
|
1202
|
-
const sliced = try rope.slice(0, 100, arena.allocator());
|
|
1203
|
-
defer arena.allocator().free(sliced);
|
|
1204
|
-
|
|
1205
|
-
try std.testing.expectEqual(@as(usize, 2), sliced.len);
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
test "Rope - delete_range with start > end does nothing" {
|
|
1209
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1210
|
-
defer arena.deinit();
|
|
1211
|
-
|
|
1212
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1213
|
-
const items = [_]SimpleItem{
|
|
1214
|
-
.{ .value = 1 },
|
|
1215
|
-
.{ .value = 2 },
|
|
1216
|
-
};
|
|
1217
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1218
|
-
|
|
1219
|
-
try rope.delete_range(2, 1);
|
|
1220
|
-
|
|
1221
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
test "Rope - insert_slice beyond count appends" {
|
|
1225
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1226
|
-
defer arena.deinit();
|
|
1227
|
-
|
|
1228
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1229
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
1230
|
-
|
|
1231
|
-
const to_insert = [_]SimpleItem{
|
|
1232
|
-
.{ .value = 2 },
|
|
1233
|
-
.{ .value = 3 },
|
|
1234
|
-
};
|
|
1235
|
-
try rope.insert_slice(100, &to_insert);
|
|
1236
|
-
|
|
1237
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
1238
|
-
try std.testing.expectEqual(@as(u32, 2), rope.get(1).?.value);
|
|
1239
|
-
try std.testing.expectEqual(@as(u32, 3), rope.get(2).?.value);
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
test "Rope - replace at out of bounds does nothing" {
|
|
1243
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1244
|
-
defer arena.deinit();
|
|
1245
|
-
|
|
1246
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1247
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
1248
|
-
|
|
1249
|
-
try rope.replace(100, .{ .value = 999 });
|
|
1250
|
-
|
|
1251
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
1252
|
-
try std.testing.expectEqual(@as(u32, 1), rope.get(0).?.value);
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
test "Rope - delete at out of bounds" {
|
|
1256
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1257
|
-
defer arena.deinit();
|
|
1258
|
-
|
|
1259
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1260
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
1261
|
-
|
|
1262
|
-
// This should handle gracefully (delete beyond bounds)
|
|
1263
|
-
try rope.delete(100);
|
|
1264
|
-
|
|
1265
|
-
// Count unchanged
|
|
1266
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
test "Rope - split at zero creates empty left" {
|
|
1270
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1271
|
-
defer arena.deinit();
|
|
1272
|
-
|
|
1273
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1274
|
-
const items = [_]SimpleItem{
|
|
1275
|
-
.{ .value = 1 },
|
|
1276
|
-
.{ .value = 2 },
|
|
1277
|
-
};
|
|
1278
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1279
|
-
|
|
1280
|
-
const right = try rope.split(0);
|
|
1281
|
-
|
|
1282
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count()); // Sentinel filtered
|
|
1283
|
-
try std.testing.expectEqual(@as(u32, 2), right.count());
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
test "Rope - split beyond count" {
|
|
1287
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1288
|
-
defer arena.deinit();
|
|
1289
|
-
|
|
1290
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1291
|
-
const items = [_]SimpleItem{
|
|
1292
|
-
.{ .value = 1 },
|
|
1293
|
-
.{ .value = 2 },
|
|
1294
|
-
};
|
|
1295
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1296
|
-
|
|
1297
|
-
const right = try rope.split(100);
|
|
1298
|
-
|
|
1299
|
-
try std.testing.expectEqual(@as(u32, 2), rope.count());
|
|
1300
|
-
try std.testing.expectEqual(@as(u32, 0), right.count()); // Sentinel filtered
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
test "Rope - multiple undo without operations" {
|
|
1304
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1305
|
-
defer arena.deinit();
|
|
1306
|
-
|
|
1307
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1308
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
1309
|
-
|
|
1310
|
-
try rope.store_undo("state1");
|
|
1311
|
-
try rope.store_undo("state2");
|
|
1312
|
-
|
|
1313
|
-
// Two undos back to back
|
|
1314
|
-
_ = try rope.undo("current");
|
|
1315
|
-
_ = try rope.undo("current");
|
|
1316
|
-
|
|
1317
|
-
// Should fail on third
|
|
1318
|
-
const result = rope.undo("current");
|
|
1319
|
-
try std.testing.expectError(error.Stop, result);
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
test "Rope - stress test with 1000 items" {
|
|
1323
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1324
|
-
defer arena.deinit();
|
|
1325
|
-
|
|
1326
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1327
|
-
var items: [1000]SimpleItem = undefined;
|
|
1328
|
-
for (&items, 0..) |*item, i| {
|
|
1329
|
-
item.* = .{ .value = @intCast(i) };
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1333
|
-
|
|
1334
|
-
try std.testing.expectEqual(@as(u32, 1000), rope.count());
|
|
1335
|
-
try std.testing.expectEqual(@as(u32, 0), rope.get(0).?.value);
|
|
1336
|
-
try std.testing.expectEqual(@as(u32, 500), rope.get(500).?.value);
|
|
1337
|
-
try std.testing.expectEqual(@as(u32, 999), rope.get(999).?.value);
|
|
1338
|
-
|
|
1339
|
-
const depth = rope.root.depth();
|
|
1340
|
-
try std.testing.expect(depth < 20); // log2(1000) ≈ 10, allow some slack
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
test "Rope - delete_range entire rope" {
|
|
1344
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1345
|
-
defer arena.deinit();
|
|
1346
|
-
|
|
1347
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1348
|
-
const items = [_]SimpleItem{
|
|
1349
|
-
.{ .value = 1 },
|
|
1350
|
-
.{ .value = 2 },
|
|
1351
|
-
.{ .value = 3 },
|
|
1352
|
-
};
|
|
1353
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1354
|
-
|
|
1355
|
-
try rope.delete_range(0, 3);
|
|
1356
|
-
|
|
1357
|
-
// Should be empty (sentinel filtered)
|
|
1358
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count());
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
test "Rope - to_array single item" {
|
|
1362
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1363
|
-
defer arena.deinit();
|
|
1364
|
-
|
|
1365
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1366
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 42 });
|
|
1367
|
-
|
|
1368
|
-
const array = try rope.to_array(arena.allocator());
|
|
1369
|
-
defer arena.allocator().free(array);
|
|
1370
|
-
|
|
1371
|
-
try std.testing.expectEqual(@as(usize, 1), array.len);
|
|
1372
|
-
try std.testing.expectEqual(@as(u32, 42), array[0].value);
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
test "Rope - concat with empty rope" {
|
|
1376
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1377
|
-
defer arena.deinit();
|
|
1378
|
-
|
|
1379
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1380
|
-
var rope1 = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
1381
|
-
const rope2 = try RopeType.init(arena.allocator());
|
|
1382
|
-
|
|
1383
|
-
try rope1.concat(&rope2);
|
|
1384
|
-
|
|
1385
|
-
try std.testing.expectEqual(@as(u32, 1), rope1.count()); // original only (empty filtered)
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
test "Rope - redo after modifying tree fails" {
|
|
1389
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1390
|
-
defer arena.deinit();
|
|
1391
|
-
|
|
1392
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1393
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
1394
|
-
|
|
1395
|
-
try rope.store_undo("state1");
|
|
1396
|
-
try rope.append(.{ .value = 2 });
|
|
1397
|
-
|
|
1398
|
-
_ = try rope.undo("current");
|
|
1399
|
-
|
|
1400
|
-
// Manually modify the rope (breaking the redo contract)
|
|
1401
|
-
try rope.append(.{ .value = 3 });
|
|
1402
|
-
|
|
1403
|
-
// Redo should fail because tree was modified
|
|
1404
|
-
const result = rope.redo();
|
|
1405
|
-
try std.testing.expectError(error.Stop, result);
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
test "Rope - rebalance extremely unbalanced tree" {
|
|
1409
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1410
|
-
defer arena.deinit();
|
|
1411
|
-
|
|
1412
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1413
|
-
var rope = try RopeType.init(arena.allocator());
|
|
1414
|
-
|
|
1415
|
-
for (0..50) |i| {
|
|
1416
|
-
try rope.append(.{ .value = @intCast(i) });
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
const depth_before = rope.root.depth();
|
|
1420
|
-
|
|
1421
|
-
// Rebalance
|
|
1422
|
-
try rope.rebalance(arena.allocator());
|
|
1423
|
-
|
|
1424
|
-
const depth_after = rope.root.depth();
|
|
1425
|
-
|
|
1426
|
-
// Should be more balanced now
|
|
1427
|
-
try std.testing.expect(depth_after <= depth_before);
|
|
1428
|
-
try std.testing.expect(depth_after < 15); // log2(50) ≈ 6
|
|
1429
|
-
|
|
1430
|
-
// Data should be preserved
|
|
1431
|
-
try std.testing.expectEqual(@as(u32, 50), rope.count());
|
|
1432
|
-
try std.testing.expectEqual(@as(u32, 0), rope.get(0).?.value); // Fixed index
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
//===== Weight-aware Tests =====
|
|
1436
|
-
|
|
1437
|
-
// Type with custom weight for testing weight-based operations
|
|
1438
|
-
const WeightedItem = struct {
|
|
1439
|
-
value: u32,
|
|
1440
|
-
weight: u32,
|
|
1441
|
-
|
|
1442
|
-
pub const Metrics = struct {
|
|
1443
|
-
total_weight: u32 = 0,
|
|
1444
|
-
|
|
1445
|
-
pub fn add(self: *Metrics, other: Metrics) void {
|
|
1446
|
-
self.total_weight += other.total_weight;
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
pub fn weight(self: *const Metrics) u32 {
|
|
1450
|
-
return self.total_weight;
|
|
1451
|
-
}
|
|
1452
|
-
};
|
|
1453
|
-
|
|
1454
|
-
pub fn measure(self: *const WeightedItem) Metrics {
|
|
1455
|
-
return .{ .total_weight = self.weight };
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
pub fn empty() WeightedItem {
|
|
1459
|
-
return .{ .value = 0, .weight = 0 };
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
|
-
pub fn is_empty(self: *const WeightedItem) bool {
|
|
1463
|
-
return self.value == 0 and self.weight == 0;
|
|
1464
|
-
}
|
|
1465
|
-
};
|
|
1466
|
-
|
|
1467
|
-
// Leaf split function for testing (callback format)
|
|
1468
|
-
const WeightedRope = rope_mod.Rope(WeightedItem);
|
|
1469
|
-
|
|
1470
|
-
fn splitWeightedItemCallback(
|
|
1471
|
-
ctx: ?*anyopaque,
|
|
1472
|
-
allocator: std.mem.Allocator,
|
|
1473
|
-
leaf: *const WeightedItem,
|
|
1474
|
-
weight_in_leaf: u32,
|
|
1475
|
-
) error{ OutOfBounds, OutOfMemory }!WeightedRope.Node.LeafSplitResult {
|
|
1476
|
-
_ = ctx;
|
|
1477
|
-
_ = allocator;
|
|
1478
|
-
if (weight_in_leaf == 0) {
|
|
1479
|
-
return .{
|
|
1480
|
-
.left = WeightedItem.empty(),
|
|
1481
|
-
.right = leaf.*,
|
|
1482
|
-
};
|
|
1483
|
-
} else if (weight_in_leaf >= leaf.weight) {
|
|
1484
|
-
return .{
|
|
1485
|
-
.left = leaf.*,
|
|
1486
|
-
.right = WeightedItem.empty(),
|
|
1487
|
-
};
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
// Split proportionally
|
|
1491
|
-
return .{
|
|
1492
|
-
.left = .{ .value = leaf.value, .weight = weight_in_leaf },
|
|
1493
|
-
.right = .{ .value = leaf.value + 1000, .weight = leaf.weight - weight_in_leaf },
|
|
1494
|
-
};
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
// Helper to create the callback struct
|
|
1498
|
-
fn makeWeightedSplitter() WeightedRope.Node.LeafSplitFn {
|
|
1499
|
-
return .{
|
|
1500
|
-
.ctx = null,
|
|
1501
|
-
.splitFn = splitWeightedItemCallback,
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
test "Rope - totalWeight returns correct weight" {
|
|
1506
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1507
|
-
defer arena.deinit();
|
|
1508
|
-
const items = [_]WeightedItem{
|
|
1509
|
-
.{ .value = 1, .weight = 10 },
|
|
1510
|
-
.{ .value = 2, .weight = 20 },
|
|
1511
|
-
.{ .value = 3, .weight = 30 },
|
|
1512
|
-
};
|
|
1513
|
-
|
|
1514
|
-
var rope = try WeightedRope.from_slice(arena.allocator(), &items);
|
|
1515
|
-
try std.testing.expectEqual(@as(u32, 60), rope.totalWeight());
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
test "Rope - split_at_weight at boundary" {
|
|
1519
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1520
|
-
defer arena.deinit();
|
|
1521
|
-
const items = [_]WeightedItem{
|
|
1522
|
-
.{ .value = 1, .weight = 10 },
|
|
1523
|
-
.{ .value = 2, .weight = 20 },
|
|
1524
|
-
.{ .value = 3, .weight = 30 },
|
|
1525
|
-
};
|
|
1526
|
-
|
|
1527
|
-
const rope = try WeightedRope.from_slice(arena.allocator(), &items);
|
|
1528
|
-
|
|
1529
|
-
// Split at weight 30 (boundary between second and third item)
|
|
1530
|
-
const splitter = makeWeightedSplitter();
|
|
1531
|
-
const result = try WeightedRope.Node.split_at_weight(rope.root, 30, arena.allocator(), rope.empty_leaf, &splitter);
|
|
1532
|
-
|
|
1533
|
-
// Left should have weight 30 (first two items)
|
|
1534
|
-
try std.testing.expectEqual(@as(u32, 30), result.left.metrics().weight());
|
|
1535
|
-
|
|
1536
|
-
// Right should have weight 30 (third item)
|
|
1537
|
-
try std.testing.expectEqual(@as(u32, 30), result.right.metrics().weight());
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
|
-
test "Rope - split_at_weight inside leaf" {
|
|
1541
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1542
|
-
defer arena.deinit();
|
|
1543
|
-
const rope = try WeightedRope.from_item(arena.allocator(), .{ .value = 1, .weight = 100 });
|
|
1544
|
-
|
|
1545
|
-
// Split at weight 40 (inside the single leaf)
|
|
1546
|
-
const splitter = makeWeightedSplitter();
|
|
1547
|
-
const result = try WeightedRope.Node.split_at_weight(rope.root, 40, arena.allocator(), rope.empty_leaf, &splitter);
|
|
1548
|
-
|
|
1549
|
-
// Left should have weight 40
|
|
1550
|
-
try std.testing.expectEqual(@as(u32, 40), result.left.metrics().weight());
|
|
1551
|
-
|
|
1552
|
-
// Right should have weight 60
|
|
1553
|
-
try std.testing.expectEqual(@as(u32, 60), result.right.metrics().weight());
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
test "Rope - splitByWeight" {
|
|
1557
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1558
|
-
defer arena.deinit();
|
|
1559
|
-
const items = [_]WeightedItem{
|
|
1560
|
-
.{ .value = 1, .weight = 10 },
|
|
1561
|
-
.{ .value = 2, .weight = 20 },
|
|
1562
|
-
.{ .value = 3, .weight = 30 },
|
|
1563
|
-
};
|
|
1564
|
-
|
|
1565
|
-
var rope = try WeightedRope.from_slice(arena.allocator(), &items);
|
|
1566
|
-
try std.testing.expectEqual(@as(u32, 60), rope.totalWeight());
|
|
1567
|
-
|
|
1568
|
-
// Split at weight 30
|
|
1569
|
-
const splitter = makeWeightedSplitter();
|
|
1570
|
-
const right_half = try rope.splitByWeight(30, &splitter);
|
|
1571
|
-
|
|
1572
|
-
// Left half should have weight 30
|
|
1573
|
-
try std.testing.expectEqual(@as(u32, 30), rope.totalWeight());
|
|
1574
|
-
|
|
1575
|
-
// Right half should have weight 30
|
|
1576
|
-
try std.testing.expectEqual(@as(u32, 30), right_half.totalWeight());
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
test "Rope - deleteRangeByWeight" {
|
|
1580
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1581
|
-
defer arena.deinit();
|
|
1582
|
-
const items = [_]WeightedItem{
|
|
1583
|
-
.{ .value = 1, .weight = 10 },
|
|
1584
|
-
.{ .value = 2, .weight = 20 },
|
|
1585
|
-
.{ .value = 3, .weight = 30 },
|
|
1586
|
-
.{ .value = 4, .weight = 40 },
|
|
1587
|
-
};
|
|
1588
|
-
|
|
1589
|
-
var rope = try WeightedRope.from_slice(arena.allocator(), &items);
|
|
1590
|
-
try std.testing.expectEqual(@as(u32, 100), rope.totalWeight());
|
|
1591
|
-
|
|
1592
|
-
// Delete weight range [10, 30) - removes the second item (weight 20)
|
|
1593
|
-
const splitter = makeWeightedSplitter();
|
|
1594
|
-
try rope.deleteRangeByWeight(10, 30, &splitter);
|
|
1595
|
-
|
|
1596
|
-
// Should have removed weight 20
|
|
1597
|
-
try std.testing.expectEqual(@as(u32, 80), rope.totalWeight());
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
test "Rope - insertSliceByWeight" {
|
|
1601
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1602
|
-
defer arena.deinit();
|
|
1603
|
-
const items = [_]WeightedItem{
|
|
1604
|
-
.{ .value = 1, .weight = 10 },
|
|
1605
|
-
.{ .value = 3, .weight = 30 },
|
|
1606
|
-
};
|
|
1607
|
-
|
|
1608
|
-
var rope = try WeightedRope.from_slice(arena.allocator(), &items);
|
|
1609
|
-
try std.testing.expectEqual(@as(u32, 40), rope.totalWeight());
|
|
1610
|
-
|
|
1611
|
-
// Insert at weight 10 (after first item)
|
|
1612
|
-
const insert_items = [_]WeightedItem{
|
|
1613
|
-
.{ .value = 2, .weight = 20 },
|
|
1614
|
-
};
|
|
1615
|
-
const splitter = makeWeightedSplitter();
|
|
1616
|
-
try rope.insertSliceByWeight(10, &insert_items, &splitter);
|
|
1617
|
-
|
|
1618
|
-
// Should have added weight 20
|
|
1619
|
-
try std.testing.expectEqual(@as(u32, 60), rope.totalWeight());
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
test "Rope - findByWeight" {
|
|
1623
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1624
|
-
defer arena.deinit();
|
|
1625
|
-
const items = [_]WeightedItem{
|
|
1626
|
-
.{ .value = 1, .weight = 10 },
|
|
1627
|
-
.{ .value = 2, .weight = 20 },
|
|
1628
|
-
.{ .value = 3, .weight = 30 },
|
|
1629
|
-
};
|
|
1630
|
-
|
|
1631
|
-
var rope = try WeightedRope.from_slice(arena.allocator(), &items);
|
|
1632
|
-
|
|
1633
|
-
// Find leaf containing weight 0 (first item)
|
|
1634
|
-
const result0 = rope.findByWeight(0);
|
|
1635
|
-
try std.testing.expect(result0 != null);
|
|
1636
|
-
try std.testing.expectEqual(@as(u32, 1), result0.?.leaf.value);
|
|
1637
|
-
try std.testing.expectEqual(@as(u32, 0), result0.?.start_weight);
|
|
1638
|
-
|
|
1639
|
-
// Find leaf containing weight 15 (second item)
|
|
1640
|
-
const result15 = rope.findByWeight(15);
|
|
1641
|
-
try std.testing.expect(result15 != null);
|
|
1642
|
-
try std.testing.expectEqual(@as(u32, 2), result15.?.leaf.value);
|
|
1643
|
-
try std.testing.expectEqual(@as(u32, 10), result15.?.start_weight);
|
|
1644
|
-
|
|
1645
|
-
// Find leaf containing weight 35 (third item)
|
|
1646
|
-
const result35 = rope.findByWeight(35);
|
|
1647
|
-
try std.testing.expect(result35 != null);
|
|
1648
|
-
try std.testing.expectEqual(@as(u32, 3), result35.?.leaf.value);
|
|
1649
|
-
try std.testing.expectEqual(@as(u32, 30), result35.?.start_weight);
|
|
1650
|
-
|
|
1651
|
-
// Out of bounds
|
|
1652
|
-
const result100 = rope.findByWeight(100);
|
|
1653
|
-
try std.testing.expect(result100 == null);
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
//===== Integrated Marker Tracking Tests (Union Types) =====
|
|
1657
|
-
|
|
1658
|
-
// Simple union type for testing automatic marker tracking
|
|
1659
|
-
const TokenType = union(enum) {
|
|
1660
|
-
word: u32,
|
|
1661
|
-
space: u32,
|
|
1662
|
-
newline: void, // Marker type
|
|
1663
|
-
|
|
1664
|
-
// Define which tags are markers (only track these!)
|
|
1665
|
-
pub const MarkerTypes = &[_]std.meta.Tag(TokenType){.newline};
|
|
1666
|
-
|
|
1667
|
-
pub const Metrics = struct {
|
|
1668
|
-
width: u32 = 0,
|
|
1669
|
-
|
|
1670
|
-
pub fn add(self: *Metrics, other: Metrics) void {
|
|
1671
|
-
self.width += other.width;
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
pub fn weight(self: *const Metrics) u32 {
|
|
1675
|
-
return self.width;
|
|
1676
|
-
}
|
|
1677
|
-
};
|
|
1678
|
-
|
|
1679
|
-
pub fn measure(self: *const TokenType) Metrics {
|
|
1680
|
-
return switch (self.*) {
|
|
1681
|
-
.word => |w| .{ .width = w },
|
|
1682
|
-
.space => |s| .{ .width = s },
|
|
1683
|
-
.newline => .{ .width = 0 },
|
|
1684
|
-
};
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
pub fn empty() TokenType {
|
|
1688
|
-
return .{ .space = 0 };
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
pub fn is_empty(self: *const TokenType) bool {
|
|
1692
|
-
return switch (self.*) {
|
|
1693
|
-
.space => |s| s == 0,
|
|
1694
|
-
else => false,
|
|
1695
|
-
};
|
|
1696
|
-
}
|
|
1697
|
-
};
|
|
1698
|
-
|
|
1699
|
-
test "Rope - automatic marker tracking with union type" {
|
|
1700
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1701
|
-
defer arena.deinit();
|
|
1702
|
-
|
|
1703
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
1704
|
-
|
|
1705
|
-
// Create rope with marker tracking enabled
|
|
1706
|
-
const tokens = [_]TokenType{
|
|
1707
|
-
.{ .word = 5 }, // "Hello"
|
|
1708
|
-
.{ .space = 1 }, // " "
|
|
1709
|
-
.{ .word = 5 }, // "World"
|
|
1710
|
-
.{ .newline = {} }, // Line break marker
|
|
1711
|
-
.{ .word = 6 }, // "Second"
|
|
1712
|
-
.{ .space = 1 }, // " "
|
|
1713
|
-
.{ .word = 4 }, // "Line"
|
|
1714
|
-
.{ .newline = {} }, // Line break marker
|
|
1715
|
-
.{ .word = 5 }, // "Third"
|
|
1716
|
-
};
|
|
1717
|
-
|
|
1718
|
-
var rope = try RopeType.from_slice(arena.allocator(), &tokens);
|
|
1719
|
-
|
|
1720
|
-
// O(1) lookup: find newline markers (only .newline is tracked, not .word or .space)
|
|
1721
|
-
try std.testing.expectEqual(@as(u32, 2), rope.markerCount(.newline));
|
|
1722
|
-
|
|
1723
|
-
// Get first newline (end of line 0)
|
|
1724
|
-
const nl0 = rope.getMarker(.newline, 0);
|
|
1725
|
-
try std.testing.expect(nl0 != null);
|
|
1726
|
-
try std.testing.expectEqual(@as(u32, 3), nl0.?.leaf_index); // After word, space, word
|
|
1727
|
-
try std.testing.expectEqual(@as(u32, 11), nl0.?.global_weight); // 5 + 1 + 5
|
|
1728
|
-
|
|
1729
|
-
// Get second newline (end of line 1)
|
|
1730
|
-
const nl1 = rope.getMarker(.newline, 1);
|
|
1731
|
-
try std.testing.expect(nl1 != null);
|
|
1732
|
-
try std.testing.expectEqual(@as(u32, 7), nl1.?.leaf_index);
|
|
1733
|
-
try std.testing.expectEqual(@as(u32, 22), nl1.?.global_weight); // 11 + 6 + 1 + 4
|
|
1734
|
-
|
|
1735
|
-
// Word and space are NOT markers - should return 0
|
|
1736
|
-
try std.testing.expectEqual(@as(u32, 0), rope.markerCount(.word));
|
|
1737
|
-
try std.testing.expectEqual(@as(u32, 0), rope.markerCount(.space));
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
test "Rope - marker tracking with empty rope" {
|
|
1741
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1742
|
-
defer arena.deinit();
|
|
1743
|
-
|
|
1744
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
1745
|
-
var rope = try RopeType.init(arena.allocator());
|
|
1746
|
-
|
|
1747
|
-
try std.testing.expectEqual(@as(u32, 0), rope.markerCount(.newline));
|
|
1748
|
-
try std.testing.expectEqual(@as(u32, 0), rope.markerCount(.word)); // Not a marker type
|
|
1749
|
-
try std.testing.expect(rope.getMarker(.newline, 0) == null);
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
test "Rope - marker tracking requires rebuild" {
|
|
1753
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1754
|
-
defer arena.deinit();
|
|
1755
|
-
|
|
1756
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
1757
|
-
const tokens = [_]TokenType{
|
|
1758
|
-
.{ .word = 5 },
|
|
1759
|
-
.{ .newline = {} },
|
|
1760
|
-
};
|
|
1761
|
-
|
|
1762
|
-
var rope = try RopeType.from_slice(arena.allocator(), &tokens);
|
|
1763
|
-
|
|
1764
|
-
// Markers are automatically tracked in the tree
|
|
1765
|
-
try std.testing.expectEqual(@as(u32, 1), rope.markerCount(.newline));
|
|
1766
|
-
try std.testing.expect(rope.getMarker(.newline, 0) != null);
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
test "Rope - marker tracking with many markers" {
|
|
1770
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1771
|
-
defer arena.deinit();
|
|
1772
|
-
|
|
1773
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
1774
|
-
|
|
1775
|
-
// Create 100 lines
|
|
1776
|
-
var tokens_array: [199]TokenType = undefined; // 100 words + 99 newlines
|
|
1777
|
-
for (0..100) |i| {
|
|
1778
|
-
if (i > 0) {
|
|
1779
|
-
tokens_array[i * 2 - 1] = .{ .newline = {} };
|
|
1780
|
-
}
|
|
1781
|
-
tokens_array[i * 2] = .{ .word = 5 };
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
var rope = try RopeType.from_slice(arena.allocator(), &tokens_array);
|
|
1785
|
-
|
|
1786
|
-
// Should have 99 newlines (only newlines are tracked as markers)
|
|
1787
|
-
try std.testing.expectEqual(@as(u32, 99), rope.markerCount(.newline));
|
|
1788
|
-
|
|
1789
|
-
// Test O(1) random access to specific lines
|
|
1790
|
-
const nl50 = rope.getMarker(.newline, 50).?;
|
|
1791
|
-
try std.testing.expectEqual(@as(u32, 101), nl50.leaf_index); // word, nl, word, nl, ... (50th newline is at index 101)
|
|
1792
|
-
try std.testing.expectEqual(@as(u32, 255), nl50.global_weight); // 51 words * 5 width
|
|
1793
|
-
|
|
1794
|
-
const nl98 = rope.getMarker(.newline, 98).?;
|
|
1795
|
-
try std.testing.expectEqual(@as(u32, 197), nl98.leaf_index);
|
|
1796
|
-
}
|
|
1797
|
-
//===== Debug toText Tests =====
|
|
1798
|
-
|
|
1799
|
-
test "Rope - toText shows basic structure" {
|
|
1800
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1801
|
-
defer arena.deinit();
|
|
1802
|
-
|
|
1803
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1804
|
-
const items = [_]SimpleItem{
|
|
1805
|
-
.{ .value = 1 },
|
|
1806
|
-
.{ .value = 2 },
|
|
1807
|
-
.{ .value = 3 },
|
|
1808
|
-
};
|
|
1809
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1810
|
-
|
|
1811
|
-
const debug_text = try rope.toText(arena.allocator());
|
|
1812
|
-
|
|
1813
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "[root") != null);
|
|
1814
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "branch") != null or std.mem.indexOf(u8, debug_text, "leaf") != null);
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
|
-
test "Rope - toText shows empty rope" {
|
|
1818
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1819
|
-
defer arena.deinit();
|
|
1820
|
-
|
|
1821
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1822
|
-
var rope = try RopeType.init(arena.allocator());
|
|
1823
|
-
|
|
1824
|
-
const debug_text = try rope.toText(arena.allocator());
|
|
1825
|
-
|
|
1826
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "[root") != null);
|
|
1827
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "[empty]") != null);
|
|
1828
|
-
}
|
|
1829
|
-
|
|
1830
|
-
test "Rope - toText with union type shows tags" {
|
|
1831
|
-
const TestSegment = union(enum) {
|
|
1832
|
-
text: struct { width: u32 },
|
|
1833
|
-
brk: void,
|
|
1834
|
-
linestart: void,
|
|
1835
|
-
|
|
1836
|
-
pub const MarkerTypes = &[_]std.meta.Tag(@This()){ .brk, .linestart };
|
|
1837
|
-
|
|
1838
|
-
pub const Metrics = struct {
|
|
1839
|
-
width: u32 = 0,
|
|
1840
|
-
|
|
1841
|
-
pub fn add(self: *Metrics, other: Metrics) void {
|
|
1842
|
-
self.width += other.width;
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
|
-
pub fn weight(self: *const Metrics) u32 {
|
|
1846
|
-
return self.width;
|
|
1847
|
-
}
|
|
1848
|
-
};
|
|
1849
|
-
|
|
1850
|
-
pub fn measure(self: *const @This()) Metrics {
|
|
1851
|
-
return switch (self.*) {
|
|
1852
|
-
.text => |t| Metrics{ .width = t.width },
|
|
1853
|
-
.brk => Metrics{ .width = 1 },
|
|
1854
|
-
.linestart => Metrics{ .width = 0 },
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
pub fn empty() @This() {
|
|
1859
|
-
return .{ .text = .{ .width = 0 } };
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
pub fn is_empty(self: *const @This()) bool {
|
|
1863
|
-
return switch (self.*) {
|
|
1864
|
-
.text => |t| t.width == 0,
|
|
1865
|
-
else => false,
|
|
1866
|
-
};
|
|
1867
|
-
}
|
|
1868
|
-
};
|
|
1869
|
-
|
|
1870
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1871
|
-
defer arena.deinit();
|
|
1872
|
-
|
|
1873
|
-
const TestRope = rope_mod.Rope(TestSegment);
|
|
1874
|
-
var rope = try TestRope.from_slice(arena.allocator(), &[_]TestSegment{
|
|
1875
|
-
.linestart,
|
|
1876
|
-
.{ .text = .{ .width = 5 } },
|
|
1877
|
-
.brk,
|
|
1878
|
-
.linestart,
|
|
1879
|
-
.{ .text = .{ .width = 10 } },
|
|
1880
|
-
});
|
|
1881
|
-
|
|
1882
|
-
const debug_text = try rope.toText(arena.allocator());
|
|
1883
|
-
|
|
1884
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "text") != null);
|
|
1885
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "brk") != null);
|
|
1886
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "linestart") != null);
|
|
1887
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "w5") != null);
|
|
1888
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "w10") != null);
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
test "Rope - toText with nested structure" {
|
|
1892
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1893
|
-
defer arena.deinit();
|
|
1894
|
-
|
|
1895
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1896
|
-
|
|
1897
|
-
// Create a larger rope that will have branches
|
|
1898
|
-
var items: [10]SimpleItem = undefined;
|
|
1899
|
-
for (&items, 0..) |*item, i| {
|
|
1900
|
-
item.* = .{ .value = @intCast(i) };
|
|
1901
|
-
}
|
|
1902
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1903
|
-
|
|
1904
|
-
const debug_text = try rope.toText(arena.allocator());
|
|
1905
|
-
|
|
1906
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "[root") != null);
|
|
1907
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "[branch") != null);
|
|
1908
|
-
}
|
|
1909
|
-
|
|
1910
|
-
test "Rope - toText after insertions shows updated structure" {
|
|
1911
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1912
|
-
defer arena.deinit();
|
|
1913
|
-
|
|
1914
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1915
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
1916
|
-
|
|
1917
|
-
const before = try rope.toText(arena.allocator());
|
|
1918
|
-
try std.testing.expect(std.mem.indexOf(u8, before, "[root") != null);
|
|
1919
|
-
|
|
1920
|
-
try rope.append(.{ .value = 2 });
|
|
1921
|
-
try rope.append(.{ .value = 3 });
|
|
1922
|
-
|
|
1923
|
-
const after = try rope.toText(arena.allocator());
|
|
1924
|
-
try std.testing.expect(std.mem.indexOf(u8, after, "[root") != null);
|
|
1925
|
-
try std.testing.expect(after.len >= before.len);
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
|
-
test "Rope - toText with custom metrics shows width info" {
|
|
1929
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1930
|
-
defer arena.deinit();
|
|
1931
|
-
|
|
1932
|
-
const RopeType = rope_mod.Rope(ItemWithMetrics);
|
|
1933
|
-
const items = [_]ItemWithMetrics{
|
|
1934
|
-
.{ .value = 1, .size = 100 },
|
|
1935
|
-
.{ .value = 2, .size = 200 },
|
|
1936
|
-
};
|
|
1937
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
1938
|
-
|
|
1939
|
-
const debug_text = try rope.toText(arena.allocator());
|
|
1940
|
-
|
|
1941
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "[root") != null);
|
|
1942
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "w") != null);
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
test "Rope - toText shows single leaf" {
|
|
1946
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1947
|
-
defer arena.deinit();
|
|
1948
|
-
|
|
1949
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
1950
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 42 });
|
|
1951
|
-
|
|
1952
|
-
const debug_text = try rope.toText(arena.allocator());
|
|
1953
|
-
|
|
1954
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "[root") != null);
|
|
1955
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "[leaf") != null);
|
|
1956
|
-
try std.testing.expect(std.mem.indexOf(u8, debug_text, "]") != null);
|
|
1957
|
-
}
|
|
1958
|
-
|
|
1959
|
-
test "Rope - marker cache MUST update after delete operations" {
|
|
1960
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1961
|
-
defer arena.deinit();
|
|
1962
|
-
|
|
1963
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
1964
|
-
|
|
1965
|
-
// Create: word(5) newline word(5) newline word(5)
|
|
1966
|
-
// 3 lines total, 2 newlines
|
|
1967
|
-
const tokens = [_]TokenType{
|
|
1968
|
-
.{ .word = 5 },
|
|
1969
|
-
.{ .newline = {} },
|
|
1970
|
-
.{ .word = 5 },
|
|
1971
|
-
.{ .newline = {} },
|
|
1972
|
-
.{ .word = 5 },
|
|
1973
|
-
};
|
|
1974
|
-
|
|
1975
|
-
var rope = try RopeType.from_slice(arena.allocator(), &tokens);
|
|
1976
|
-
|
|
1977
|
-
try std.testing.expectEqual(@as(u32, 2), rope.markerCount(.newline));
|
|
1978
|
-
|
|
1979
|
-
try rope.delete(4);
|
|
1980
|
-
|
|
1981
|
-
try std.testing.expectEqual(@as(u32, 2), rope.markerCount(.newline));
|
|
1982
|
-
|
|
1983
|
-
// The critical test: marker positions MUST be correct after delete!
|
|
1984
|
-
const nl1_after = rope.getMarker(.newline, 1);
|
|
1985
|
-
try std.testing.expect(nl1_after != null);
|
|
1986
|
-
|
|
1987
|
-
// After deleting the last word at index 4, the second newline should be at index 3
|
|
1988
|
-
// (was at index 3 before, stays at 3 after deleting index 4)
|
|
1989
|
-
try std.testing.expectEqual(@as(u32, 3), nl1_after.?.leaf_index);
|
|
1990
|
-
}
|
|
1991
|
-
|
|
1992
|
-
test "Rope - marker cache MUST update after undo" {
|
|
1993
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1994
|
-
defer arena.deinit();
|
|
1995
|
-
|
|
1996
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
1997
|
-
|
|
1998
|
-
// Create: word(10) newline word(5)
|
|
1999
|
-
const tokens = [_]TokenType{
|
|
2000
|
-
.{ .word = 10 },
|
|
2001
|
-
.{ .newline = {} },
|
|
2002
|
-
.{ .word = 5 },
|
|
2003
|
-
};
|
|
2004
|
-
|
|
2005
|
-
var rope = try RopeType.from_slice(arena.allocator(), &tokens);
|
|
2006
|
-
|
|
2007
|
-
// Initial state: 1 newline at weight 10
|
|
2008
|
-
const nl_before = rope.getMarker(.newline, 0);
|
|
2009
|
-
try std.testing.expect(nl_before != null);
|
|
2010
|
-
try std.testing.expectEqual(@as(u32, 10), nl_before.?.global_weight);
|
|
2011
|
-
|
|
2012
|
-
// Store undo point
|
|
2013
|
-
try rope.store_undo("before delete");
|
|
2014
|
-
|
|
2015
|
-
// Delete part of first word: delete range [0, 1) removes first word
|
|
2016
|
-
try rope.delete_range(0, 1);
|
|
2017
|
-
|
|
2018
|
-
// After delete: newline should be at weight 0 (no word before it)
|
|
2019
|
-
const nl_after_delete = rope.getMarker(.newline, 0);
|
|
2020
|
-
try std.testing.expect(nl_after_delete != null);
|
|
2021
|
-
try std.testing.expectEqual(@as(u32, 0), nl_after_delete.?.global_weight);
|
|
2022
|
-
|
|
2023
|
-
// Undo the delete
|
|
2024
|
-
_ = try rope.undo("after delete");
|
|
2025
|
-
|
|
2026
|
-
// CRITICAL: After undo, marker cache MUST be recalculated!
|
|
2027
|
-
// Newline should be back at weight 10
|
|
2028
|
-
const nl_after_undo = rope.getMarker(.newline, 0);
|
|
2029
|
-
try std.testing.expect(nl_after_undo != null);
|
|
2030
|
-
try std.testing.expectEqual(@as(u32, 10), nl_after_undo.?.global_weight);
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
test "Rope - marker cache MUST update after redo" {
|
|
2034
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2035
|
-
defer arena.deinit();
|
|
2036
|
-
|
|
2037
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
2038
|
-
|
|
2039
|
-
const tokens = [_]TokenType{
|
|
2040
|
-
.{ .word = 10 },
|
|
2041
|
-
.{ .newline = {} },
|
|
2042
|
-
.{ .word = 5 },
|
|
2043
|
-
};
|
|
2044
|
-
|
|
2045
|
-
var rope = try RopeType.from_slice(arena.allocator(), &tokens);
|
|
2046
|
-
|
|
2047
|
-
try rope.store_undo("initial");
|
|
2048
|
-
try rope.delete_range(0, 1);
|
|
2049
|
-
|
|
2050
|
-
const nl_after_delete = rope.getMarker(.newline, 0);
|
|
2051
|
-
try std.testing.expectEqual(@as(u32, 0), nl_after_delete.?.global_weight);
|
|
2052
|
-
|
|
2053
|
-
// Undo
|
|
2054
|
-
_ = try rope.undo("after delete");
|
|
2055
|
-
const nl_after_undo = rope.getMarker(.newline, 0);
|
|
2056
|
-
try std.testing.expectEqual(@as(u32, 10), nl_after_undo.?.global_weight);
|
|
2057
|
-
|
|
2058
|
-
// Redo
|
|
2059
|
-
_ = try rope.redo();
|
|
2060
|
-
|
|
2061
|
-
// CRITICAL: After redo, marker cache MUST be recalculated!
|
|
2062
|
-
const nl_after_redo = rope.getMarker(.newline, 0);
|
|
2063
|
-
try std.testing.expect(nl_after_redo != null);
|
|
2064
|
-
try std.testing.expectEqual(@as(u32, 0), nl_after_redo.?.global_weight);
|
|
2065
|
-
}
|
|
2066
|
-
|
|
2067
|
-
test "Rope - marker cache survives multiple undo/redo cycles" {
|
|
2068
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2069
|
-
defer arena.deinit();
|
|
2070
|
-
|
|
2071
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
2072
|
-
|
|
2073
|
-
var rope = try RopeType.from_slice(arena.allocator(), &[_]TokenType{
|
|
2074
|
-
.{ .word = 5 },
|
|
2075
|
-
.{ .newline = {} },
|
|
2076
|
-
.{ .word = 5 },
|
|
2077
|
-
});
|
|
2078
|
-
|
|
2079
|
-
try rope.store_undo("state1");
|
|
2080
|
-
try rope.append(.{ .newline = {} });
|
|
2081
|
-
try rope.append(.{ .word = 5 });
|
|
2082
|
-
|
|
2083
|
-
// Should have 2 newlines now
|
|
2084
|
-
try std.testing.expectEqual(@as(u32, 2), rope.markerCount(.newline));
|
|
2085
|
-
const nl1_orig = rope.getMarker(.newline, 1);
|
|
2086
|
-
try std.testing.expectEqual(@as(u32, 10), nl1_orig.?.global_weight);
|
|
2087
|
-
|
|
2088
|
-
try rope.store_undo("state2");
|
|
2089
|
-
try rope.delete(0); // Delete first word
|
|
2090
|
-
|
|
2091
|
-
// Markers should update: first newline now at weight 0
|
|
2092
|
-
const nl0_after_delete = rope.getMarker(.newline, 0);
|
|
2093
|
-
try std.testing.expectEqual(@as(u32, 0), nl0_after_delete.?.global_weight);
|
|
2094
|
-
|
|
2095
|
-
// Undo twice
|
|
2096
|
-
_ = try rope.undo("current");
|
|
2097
|
-
_ = try rope.undo("current");
|
|
2098
|
-
|
|
2099
|
-
// Back to original: 1 newline at weight 5
|
|
2100
|
-
try std.testing.expectEqual(@as(u32, 1), rope.markerCount(.newline));
|
|
2101
|
-
const nl_final = rope.getMarker(.newline, 0);
|
|
2102
|
-
try std.testing.expectEqual(@as(u32, 5), nl_final.?.global_weight);
|
|
2103
|
-
|
|
2104
|
-
// Redo twice
|
|
2105
|
-
_ = try rope.redo();
|
|
2106
|
-
_ = try rope.redo();
|
|
2107
|
-
|
|
2108
|
-
// Should match the post-delete state
|
|
2109
|
-
const nl0_redo = rope.getMarker(.newline, 0);
|
|
2110
|
-
try std.testing.expectEqual(@as(u32, 0), nl0_redo.?.global_weight);
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
//===== Configurable Undo Depth Tests =====
|
|
2114
|
-
|
|
2115
|
-
test "Rope - weight-based balancing with custom weight function" {
|
|
2116
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2117
|
-
defer arena.deinit();
|
|
2118
|
-
|
|
2119
|
-
// Create items with different sizes
|
|
2120
|
-
const items = [_]WeightedItem{
|
|
2121
|
-
.{ .value = 1, .weight = 100 }, // Large item
|
|
2122
|
-
.{ .value = 2, .weight = 10 }, // Small item
|
|
2123
|
-
.{ .value = 3, .weight = 200 }, // Very large item
|
|
2124
|
-
.{ .value = 4, .weight = 50 }, // Medium item
|
|
2125
|
-
};
|
|
2126
|
-
|
|
2127
|
-
var rope = try WeightedRope.from_slice(arena.allocator(), &items);
|
|
2128
|
-
|
|
2129
|
-
// Check that metrics are tracked
|
|
2130
|
-
const metrics = rope.root.metrics();
|
|
2131
|
-
try std.testing.expectEqual(@as(u32, 4), metrics.count);
|
|
2132
|
-
try std.testing.expectEqual(@as(u32, 360), metrics.custom.total_weight);
|
|
2133
|
-
try std.testing.expectEqual(@as(u32, 360), metrics.weight()); // Should use weight()
|
|
2134
|
-
}
|
|
2135
|
-
|
|
2136
|
-
test "Rope - unlimited undo depth by default" {
|
|
2137
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2138
|
-
defer arena.deinit();
|
|
2139
|
-
|
|
2140
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
2141
|
-
var rope = try RopeType.init(arena.allocator());
|
|
2142
|
-
|
|
2143
|
-
// Store many undo states
|
|
2144
|
-
for (0..100) |i| {
|
|
2145
|
-
try rope.store_undo("state");
|
|
2146
|
-
try rope.append(.{ .value = @intCast(i) });
|
|
2147
|
-
}
|
|
2148
|
-
|
|
2149
|
-
// Should have all 100 states
|
|
2150
|
-
try std.testing.expectEqual(@as(usize, 100), rope.undo_depth);
|
|
2151
|
-
try std.testing.expect(rope.can_undo());
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
test "Rope - max_undo_depth limits history" {
|
|
2155
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2156
|
-
defer arena.deinit();
|
|
2157
|
-
|
|
2158
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
2159
|
-
var rope = try RopeType.initWithConfig(arena.allocator(), .{ .max_undo_depth = 10 });
|
|
2160
|
-
|
|
2161
|
-
// Store 20 undo states
|
|
2162
|
-
for (0..20) |i| {
|
|
2163
|
-
try rope.store_undo("state");
|
|
2164
|
-
try rope.append(.{ .value = @intCast(i) });
|
|
2165
|
-
}
|
|
2166
|
-
|
|
2167
|
-
// Should only keep 10 states
|
|
2168
|
-
try std.testing.expectEqual(@as(usize, 10), rope.undo_depth);
|
|
2169
|
-
try std.testing.expect(rope.can_undo());
|
|
2170
|
-
|
|
2171
|
-
// Can undo at most 10 times (may be less due to how history works)
|
|
2172
|
-
var undo_count: usize = 0;
|
|
2173
|
-
while (rope.can_undo()) : (undo_count += 1) {
|
|
2174
|
-
_ = rope.undo("current") catch break;
|
|
2175
|
-
}
|
|
2176
|
-
// Should have undone at least some operations, but not more than 10
|
|
2177
|
-
try std.testing.expect(undo_count > 0);
|
|
2178
|
-
try std.testing.expect(undo_count <= 10);
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
|
-
test "Rope - trimUndoHistory works correctly" {
|
|
2182
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2183
|
-
defer arena.deinit();
|
|
2184
|
-
|
|
2185
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
2186
|
-
var rope = try RopeType.initWithConfig(arena.allocator(), .{ .max_undo_depth = 5 });
|
|
2187
|
-
|
|
2188
|
-
for (0..10) |i| {
|
|
2189
|
-
try rope.store_undo("state");
|
|
2190
|
-
try rope.append(.{ .value = @intCast(i) });
|
|
2191
|
-
|
|
2192
|
-
try std.testing.expect(rope.undo_depth <= 5);
|
|
2193
|
-
}
|
|
2194
|
-
|
|
2195
|
-
try std.testing.expectEqual(@as(usize, 5), rope.undo_depth);
|
|
2196
|
-
}
|
|
2197
|
-
|
|
2198
|
-
test "Rope - weight-based join_balanced respects weight ratio" {
|
|
2199
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2200
|
-
defer arena.deinit();
|
|
2201
|
-
|
|
2202
|
-
const left_items = [_]WeightedItem{
|
|
2203
|
-
.{ .value = 1, .weight = 1000 },
|
|
2204
|
-
.{ .value = 2, .weight = 1000 },
|
|
2205
|
-
.{ .value = 3, .weight = 1000 },
|
|
2206
|
-
};
|
|
2207
|
-
var rope_left = try WeightedRope.from_slice(arena.allocator(), &left_items);
|
|
2208
|
-
|
|
2209
|
-
const right_items = [_]WeightedItem{
|
|
2210
|
-
.{ .value = 4, .weight = 100 },
|
|
2211
|
-
};
|
|
2212
|
-
const rope_right = try WeightedRope.from_slice(arena.allocator(), &right_items);
|
|
2213
|
-
|
|
2214
|
-
try rope_left.concat(&rope_right);
|
|
2215
|
-
|
|
2216
|
-
try std.testing.expectEqual(@as(u32, 4), rope_left.count());
|
|
2217
|
-
|
|
2218
|
-
try std.testing.expect(rope_left.root.is_balanced());
|
|
2219
|
-
}
|
|
2220
|
-
|
|
2221
|
-
test "Rope - integration weight-based balancing with history limits" {
|
|
2222
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2223
|
-
defer arena.deinit();
|
|
2224
|
-
|
|
2225
|
-
var rope = try WeightedRope.initWithConfig(arena.allocator(), .{ .max_undo_depth = 5 });
|
|
2226
|
-
|
|
2227
|
-
var expected_count: u32 = 0;
|
|
2228
|
-
for (0..10) |i| {
|
|
2229
|
-
try rope.store_undo("insert");
|
|
2230
|
-
try rope.append(.{
|
|
2231
|
-
.value = @intCast(i),
|
|
2232
|
-
.weight = @intCast((i + 1) * 10),
|
|
2233
|
-
});
|
|
2234
|
-
expected_count += 1;
|
|
2235
|
-
}
|
|
2236
|
-
|
|
2237
|
-
try std.testing.expectEqual(expected_count, rope.count());
|
|
2238
|
-
|
|
2239
|
-
try rope.insert(5, .{ .value = 999, .weight = 50 });
|
|
2240
|
-
expected_count += 1;
|
|
2241
|
-
|
|
2242
|
-
try std.testing.expectEqual(expected_count, rope.count());
|
|
2243
|
-
|
|
2244
|
-
try std.testing.expect(rope.undo_depth <= 5);
|
|
2245
|
-
|
|
2246
|
-
try std.testing.expect(rope.root.is_balanced());
|
|
2247
|
-
}
|
|
2248
|
-
|
|
2249
|
-
test "Rope - clear removes all items" {
|
|
2250
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2251
|
-
defer arena.deinit();
|
|
2252
|
-
|
|
2253
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
2254
|
-
const items = [_]SimpleItem{
|
|
2255
|
-
.{ .value = 1 },
|
|
2256
|
-
.{ .value = 2 },
|
|
2257
|
-
.{ .value = 3 },
|
|
2258
|
-
};
|
|
2259
|
-
var rope = try RopeType.from_slice(arena.allocator(), &items);
|
|
2260
|
-
|
|
2261
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
2262
|
-
|
|
2263
|
-
rope.clear();
|
|
2264
|
-
|
|
2265
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count());
|
|
2266
|
-
}
|
|
2267
|
-
|
|
2268
|
-
test "Rope - clear on empty rope" {
|
|
2269
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2270
|
-
defer arena.deinit();
|
|
2271
|
-
|
|
2272
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
2273
|
-
var rope = try RopeType.init(arena.allocator());
|
|
2274
|
-
|
|
2275
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count());
|
|
2276
|
-
|
|
2277
|
-
rope.clear();
|
|
2278
|
-
|
|
2279
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count());
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
test "Rope - clear then insert works" {
|
|
2283
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2284
|
-
defer arena.deinit();
|
|
2285
|
-
|
|
2286
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
2287
|
-
var rope = try RopeType.from_item(arena.allocator(), .{ .value = 1 });
|
|
2288
|
-
|
|
2289
|
-
rope.clear();
|
|
2290
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count());
|
|
2291
|
-
|
|
2292
|
-
try rope.append(.{ .value = 42 });
|
|
2293
|
-
try std.testing.expectEqual(@as(u32, 1), rope.count());
|
|
2294
|
-
try std.testing.expectEqual(@as(u32, 42), rope.get(0).?.value);
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
test "Rope - clear with markers resets marker cache" {
|
|
2298
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2299
|
-
defer arena.deinit();
|
|
2300
|
-
|
|
2301
|
-
const RopeType = rope_mod.Rope(TokenType);
|
|
2302
|
-
const tokens = [_]TokenType{
|
|
2303
|
-
.{ .word = 5 },
|
|
2304
|
-
.{ .newline = {} },
|
|
2305
|
-
.{ .word = 5 },
|
|
2306
|
-
.{ .newline = {} },
|
|
2307
|
-
};
|
|
2308
|
-
|
|
2309
|
-
var rope = try RopeType.from_slice(arena.allocator(), &tokens);
|
|
2310
|
-
try std.testing.expectEqual(@as(u32, 2), rope.markerCount(.newline));
|
|
2311
|
-
|
|
2312
|
-
rope.clear();
|
|
2313
|
-
|
|
2314
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count());
|
|
2315
|
-
try std.testing.expectEqual(@as(u32, 0), rope.markerCount(.newline));
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
|
-
test "Rope - integration all features working together" {
|
|
2319
|
-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2320
|
-
defer arena.deinit();
|
|
2321
|
-
|
|
2322
|
-
const RopeType = rope_mod.Rope(SimpleItem);
|
|
2323
|
-
var rope = try RopeType.initWithConfig(arena.allocator(), .{ .max_undo_depth = 3 });
|
|
2324
|
-
|
|
2325
|
-
try std.testing.expectEqual(@as(u32, 0), rope.count());
|
|
2326
|
-
|
|
2327
|
-
try rope.store_undo("empty");
|
|
2328
|
-
try rope.append(.{ .value = 1 });
|
|
2329
|
-
|
|
2330
|
-
try rope.store_undo("one");
|
|
2331
|
-
try rope.append(.{ .value = 2 });
|
|
2332
|
-
|
|
2333
|
-
try rope.store_undo("two");
|
|
2334
|
-
try rope.append(.{ .value = 3 });
|
|
2335
|
-
|
|
2336
|
-
try rope.store_undo("three");
|
|
2337
|
-
try rope.append(.{ .value = 4 });
|
|
2338
|
-
|
|
2339
|
-
try std.testing.expectEqual(@as(u32, 4), rope.count());
|
|
2340
|
-
|
|
2341
|
-
try std.testing.expectEqual(@as(usize, 3), rope.undo_depth);
|
|
2342
|
-
|
|
2343
|
-
const val = rope.get(2);
|
|
2344
|
-
try std.testing.expectEqual(@as(u32, 3), val.?.value);
|
|
2345
|
-
|
|
2346
|
-
_ = try rope.undo("current");
|
|
2347
|
-
try std.testing.expectEqual(@as(u32, 3), rope.count());
|
|
2348
|
-
|
|
2349
|
-
const Context = struct {
|
|
2350
|
-
count: u32 = 0,
|
|
2351
|
-
fn walker(ctx: *anyopaque, data: *const SimpleItem, index: u32) RopeType.Node.WalkerResult {
|
|
2352
|
-
_ = data;
|
|
2353
|
-
_ = index;
|
|
2354
|
-
const self = @as(*@This(), @ptrCast(@alignCast(ctx)));
|
|
2355
|
-
self.count += 1;
|
|
2356
|
-
return .{};
|
|
2357
|
-
}
|
|
2358
|
-
};
|
|
2359
|
-
var ctx = Context{};
|
|
2360
|
-
try rope.walk(&ctx, Context.walker);
|
|
2361
|
-
try std.testing.expectEqual(@as(u32, 3), ctx.count);
|
|
2362
|
-
}
|