|
4 | 4 |
|
5 | 5 | from typing import Any, List, Optional |
6 | 6 |
|
7 | | -from lark import Tree |
| 7 | +from lark import Token, Tree |
8 | 8 |
|
9 | 9 | from strictdoc.backend.sdoc_source_code.comment_parser.marker_lexer import ( |
10 | 10 | MarkerLexer, |
@@ -489,6 +489,46 @@ def test_34_node_text_starting_below() -> None: |
489 | 489 | ) |
490 | 490 |
|
491 | 491 |
|
| 492 | +def test_35a_node_value_newline_lf() -> None: |
| 493 | + """Verify that LF goes into a separate NEWLINE token.""" |
| 494 | + input_string = "FIELD: value1\nvalue2\n" |
| 495 | + tree = MarkerLexer.parse(input_string, custom_tags={"FIELD"}) |
| 496 | + |
| 497 | + node_fields = list(tree.find_data("node_field")) |
| 498 | + |
| 499 | + assert_node_field( |
| 500 | + node_fields[0], |
| 501 | + "FIELD", |
| 502 | + [ |
| 503 | + Token("NODE_STRING_VALUE", "value1"), |
| 504 | + Token("NEWLINE", "\n"), |
| 505 | + Token("NODE_STRING_VALUE", "value2"), |
| 506 | + Token("NEWLINE", "\n"), |
| 507 | + ], |
| 508 | + ) |
| 509 | + |
| 510 | + |
| 511 | +def test_35b_node_value_newline_crlf() -> None: |
| 512 | + """Verify that CR LF goes into a separate NEWLINE token.""" |
| 513 | + input_string = "FIELD: value1\r\nvalue2\r\n" |
| 514 | + tree = MarkerLexer.parse(input_string, custom_tags={"FIELD"}) |
| 515 | + |
| 516 | + node_fields = list(tree.find_data("node_field")) |
| 517 | + |
| 518 | + assert_node_field( |
| 519 | + node_fields[0], |
| 520 | + "FIELD", |
| 521 | + [ |
| 522 | + Token("NODE_STRING_VALUE", "value1"), |
| 523 | + Token("NEWLINE", "\r\n"), |
| 524 | + Token("NODE_STRING_VALUE", "value2"), |
| 525 | + # The implicit \r\n => \n conversion at EOF is not nice, but doesn't hurt (yet). |
| 526 | + # We need to improve EOF handling in lark grammar to get rid of it. |
| 527 | + Token("NEWLINE", "\n"), |
| 528 | + ], |
| 529 | + ) |
| 530 | + |
| 531 | + |
492 | 532 | def test_60_exclude_reserved_keywords() -> None: |
493 | 533 | input_string = """ |
494 | 534 | FIXME: This can likely replace _weak below with no problem. |
|
0 commit comments