@@ -49,6 +49,8 @@ program test_syntax_highlight |
| 49 | 49 | call test_complex_pipeline() |
| 50 | 50 | call test_keyword_resets_cmd_pos() |
| 51 | 51 | call test_case_esac() |
| 52 | + call test_c_style_for_loop() |
| 53 | + call test_keyword_outside_cmd_pos() |
| 52 | 54 | |
| 53 | 55 | write(*, '(a)') '' |
| 54 | 56 | write(*, '(a)') '==========================================' |
@@ -431,10 +433,40 @@ contains |
| 431 | 433 | call tokenize_v2(input, 9, tokens, n) |
| 432 | 434 | call assert_eq('case_esac: count', 2, n) |
| 433 | 435 | call assert_eq('case_esac/case', HTOK_KEYWORD, tokens(1)%token_type) |
| 434 | | - ! esac is not in command position after case (case doesn't reset cmd pos) |
| 435 | | - ! but 'case' is a keyword. After case, in_cmd_pos goes to false. |
| 436 | | - ! esac is a word in non-cmd position — DEFAULT |
| 437 | | - call assert_eq('case_esac/esac', HTOK_DEFAULT, tokens(2)%token_type) |
| 436 | + ! esac is always recognized as a keyword regardless of command position |
| 437 | + call assert_eq('case_esac/esac', HTOK_KEYWORD, tokens(2)%token_type) |
| 438 | + end subroutine |
| 439 | + |
| 440 | + ! C-style for loop: for ((i=0; i<3; i++)) do echo $i; done |
| 441 | + subroutine test_c_style_for_loop() |
| 442 | + character(len=256) :: input |
| 443 | + type(hl_token_t) :: tokens(MT) |
| 444 | + integer :: n |
| 445 | + |
| 446 | + input = 'for ((i=0; i<3; i++)) do echo $i; done' |
| 447 | + call tokenize_v2(input, 38, tokens, n) |
| 448 | + ! for = KEYWORD, ((...)) = NUMBER (arithmetic), do = KEYWORD, |
| 449 | + ! echo = BUILTIN, $i = VARIABLE, ; = OPERATOR, done = KEYWORD |
| 450 | + call assert_eq('cfor: for', HTOK_KEYWORD, tokens(1)%token_type) |
| 451 | + call assert_eq('cfor: (())', HTOK_NUMBER, tokens(2)%token_type) |
| 452 | + call assert_eq('cfor: do', HTOK_KEYWORD, tokens(3)%token_type) |
| 453 | + call assert_eq('cfor: echo', HTOK_BUILTIN, tokens(4)%token_type) |
| 454 | + call assert_eq('cfor: $i', HTOK_VARIABLE, tokens(5)%token_type) |
| 455 | + call assert_eq('cfor: ;', HTOK_OPERATOR, tokens(6)%token_type) |
| 456 | + call assert_eq('cfor: done', HTOK_KEYWORD, tokens(7)%token_type) |
| 457 | + end subroutine |
| 458 | + |
| 459 | + ! Keywords recognized even outside command position |
| 460 | + subroutine test_keyword_outside_cmd_pos() |
| 461 | + character(len=256) :: input |
| 462 | + type(hl_token_t) :: tokens(MT) |
| 463 | + integer :: n |
| 464 | + |
| 465 | + ! 'echo done' — done after a builtin should still be keyword |
| 466 | + input = 'echo done' |
| 467 | + call tokenize_v2(input, 9, tokens, n) |
| 468 | + call assert_eq('kw_nonpos: echo', HTOK_BUILTIN, tokens(1)%token_type) |
| 469 | + call assert_eq('kw_nonpos: done', HTOK_KEYWORD, tokens(2)%token_type) |
| 438 | 470 | end subroutine |
| 439 | 471 | |
| 440 | 472 | end program test_syntax_highlight |