Skip to content

test: ゴールデンテストを追加し、PTY 環境での動作バグを修正#3

Open
zztkm wants to merge 1 commit intomainfrom
feature/golden-test
Open

test: ゴールデンテストを追加し、PTY 環境での動作バグを修正#3
zztkm wants to merge 1 commit intomainfrom
feature/golden-test

Conversation

@zztkm
Copy link
Owner

@zztkm zztkm commented Feb 23, 2026

Summary

  • zim のコア編集操作(挿入・削除・ペースト・改行)を検証するゴールデンテスト 7 件を追加
  • テスト実装中に発見した PTY 環境固有のバグ 4 件を修正

追加したテストケース

テスト名 操作 検証内容
test_insert_ascii i → ASCII 入力 → ESC → :wq Insert モードでの文字挿入
test_delete_line dd:wq 行削除
test_open_line_below o → 文字入力 → ESC → :wq 下に新規行を開いて挿入
test_insert_japanese i → 日本語入力 → ESC → :wq マルチバイト文字の挿入
test_yank_paste_line yyp:wq 行ヤンク&ペースト
test_delete_char_x x:wq 1 文字削除
test_backspace_join_lines ji → Backspace → ESC → :wq 行頭 Backspace による行結合

バグ修正

cursor.rs: editor_rows - 1 の u16 オーバーフロー(3 箇所)

  • PTY サイズが (0, 0) のとき editor_rows = 0 となり 0u16 - 1 でパニックが発生
  • move_to_bottom()scroll()saturating_sub(1) に変更

terminal.rs: PTY サイズ (0, 0) 時のフォールバック

  • rexpect が作成する PTY のサイズは (0, 0)terminal_width = 0 → Insert モードでカーソルが動かず文字が逆順挿入される
  • (0, 0) の場合は (80, 24) をデフォルトとして使用

handler/insert.rs: Key::Alt(':') ハンドラ追加

  • PTY 経由で \x1b の直後に : が届くと termion が Key::Alt(':') と解析する
  • Insert モードで Key::Alt(':') を ESC + : と同等に処理(Normal → Command モード)

app.rs: Insert → Command モード遷移時に command_buffer をクリア

  • Normal → Command 遷移と同様の処理を Insert → Command でも実施

Test plan

  • cargo test --test golden が 9 テスト全てグリーンになることを確認
  • cargo test --lib が 54 テスト全てグリーンになることを確認
  • ゴールデンファイルの内容が期待通りであることを目視確認

🤖 Generated with Claude Code

## 追加したテストケース

- test_insert_ascii: i → 文字入力 → Esc → :wq
- test_delete_line: dd → :wq
- test_open_line_below: o → 文字入力 → Esc → :wq
- test_insert_japanese: i → 日本語入力 → Esc → :wq
- test_yank_paste_line: yy → p → :wq
- test_delete_char_x: x → :wq
- test_backspace_join_lines: j → i → Backspace → Esc → :wq

## バグ修正(テスト実装中に発見)

**cursor.rs**: `editor_rows - 1` の u16 オーバーフロー修正
- PTY サイズが (0,0) のとき editor_rows=0 となり、`0u16 - 1` でパニックが発生
- move_to_bottom()・scroll() の 3 箇所を `saturating_sub(1)` に変更

**terminal.rs**: PTY サイズ (0,0) 時のフォールバック追加
- rexpect が作成する PTY のサイズが (0,0) で terminal_width=0 になり、
  Insert モードでカーソルが移動できず文字が逆順に挿入される問題を修正
- (0,0) の場合は (80,24) をデフォルトサイズとして使用

**handler/insert.rs**: Key::Alt(':') ハンドラを追加
- PTY 経由で \x1b の直後に ':' が届くと termion が Key::Alt(':') として
  解析するため、Insert モードでも ESC+: と同様に扱うよう対応
- Normal モードに戻り、Command モードに入る

**app.rs**: Insert → Command モード遷移時に command_buffer をクリア
- Normal → Command と同様の処理を Insert → Command でも実施

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant