1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
|
:
# test-par
# last touched in Par 1.53.0
# last meaningful change in Par 1.53.0
# Copyright 2020 Adam M. Costello
# This is POSIX shell code.
if [ $# -ne 1 ]; then
echo 'need exactly one argument, the pathname for par' >&2
exit 2
fi
par=$1
unset PARBODY PARINIT PARPROTECT PARQUOTE
pass_count=0
fail_count=0
# The caller must set variables called 'input' and 'expected', may set
# a variable called 'locale' (which if nonempty will be exposed to
# par as environment variable LC_ALL), and may pass arguments for par
# on the command line. The input and expected text need not end with
# newlines, because test_par will add a newline to the input, and the
# shell backquotes that capture the output will strip the last newline.
test_par() {
output=`
if [ -n "$locale" ]; then
LC_ALL=$locale "$par" "$@"
else
"$par" "$@"
fi << EOF
$input
EOF
`
cmdline="${locale:+LC_ALL=$locale }$par $@"
if [ "$expected" = "$output" ]; then
pass_count=`expr $pass_count + 1`
echo "passed: $cmdline"
else
fail_count=`expr $fail_count + 1`
echo "
FAILED: $cmdline
input {
$input
}
expected {
$expected
}
output {
$output
}
"
fi
}
# From the Examples section of par.doc:
input=`cat << 'EOF'
We the people of the United States,
in order to form a more perfect union,
establish justice,
insure domestic tranquility,
provide for the common defense,
promote the general welfare,
and secure the blessing of liberty
to ourselves and our posterity,
do ordain and establish the Constitution
of the United States of America.
EOF
`
args=39
expected=`cat << 'EOF'
We the people of the United
States, in order to form a
more perfect union, establish
justice, insure domestic
tranquility, provide for the
common defense, promote the
general welfare, and secure
the blessing of liberty to
ourselves and our posterity,
do ordain and establish the
Constitution of the United
States of America.
EOF
`
test_par $args
input=`cat << 'EOF'
/* We the people of the United States, */
/* in order to form a more perfect union, */
/* establish justice, */
/* insure domestic tranquility, */
/* provide for the common defense, */
/* promote the general welfare, */
/* and secure the blessing of liberty */
/* to ourselves and our posterity, */
/* do ordain and establish the Constitution */
/* of the United States of America. */
EOF
`
args=59
expected=`cat << 'EOF'
/* We the people of the United States, in */
/* order to form a more perfect union, establish */
/* justice, insure domestic tranquility, provide */
/* for the common defense, promote the general */
/* welfare, and secure the blessing of liberty */
/* to ourselves and our posterity, do ordain */
/* and establish the Constitution of the United */
/* States of America. */
EOF
`
test_par $args
args=59f
expected=`cat << 'EOF'
/* We the people of the United States, */
/* in order to form a more perfect union, */
/* establish justice, insure domestic */
/* tranquility, provide for the common */
/* defense, promote the general welfare, */
/* and secure the blessing of liberty to */
/* ourselves and our posterity, do ordain */
/* and establish the Constitution of the */
/* United States of America. */
EOF
`
test_par $args
args=59l
expected=`cat << 'EOF'
/* We the people of the United States, in */
/* order to form a more perfect union, establish */
/* justice, insure domestic tranquility, */
/* provide for the common defense, promote */
/* the general welfare, and secure the */
/* blessing of liberty to ourselves and our */
/* posterity, do ordain and establish the */
/* Constitution of the United States of America. */
EOF
`
test_par $args
args=59lf
expected=`cat << 'EOF'
/* We the people of the United States, */
/* in order to form a more perfect union, */
/* establish justice, insure domestic */
/* tranquility, provide for the common */
/* defense, promote the general welfare, */
/* and secure the blessing of liberty */
/* to ourselves and our posterity, do */
/* ordain and establish the Constitution */
/* of the United States of America. */
EOF
`
test_par $args
args=59lft0
expected=`cat << 'EOF'
/* We the people of the United States, */
/* in order to form a more perfect union, */
/* establish justice, insure domestic */
/* tranquility, provide for the common */
/* defense, promote the general welfare, */
/* and secure the blessing of liberty */
/* to ourselves and our posterity, do */
/* ordain and establish the Constitution */
/* of the United States of America. */
EOF
`
test_par $args
args=59j
expected=`cat << 'EOF'
/* We the people of the United States, in */
/* order to form a more perfect union, establish */
/* justice, insure domestic tranquility, provide */
/* for the common defense, promote the general */
/* welfare, and secure the blessing of liberty */
/* to ourselves and our posterity, do ordain and */
/* establish the Constitution of the United */
/* States of America. */
EOF
`
test_par $args
args=59jl
expected=`cat << 'EOF'
/* We the people of the United States, */
/* in order to form a more perfect */
/* union, establish justice, insure domestic */
/* tranquility, provide for the common defense, */
/* promote the general welfare, and secure */
/* the blessing of liberty to ourselves and */
/* our posterity, do ordain and establish the */
/* Constitution of the United States of America. */
EOF
`
test_par $args
input=`cat << 'EOF'
Preamble We the people of the United States,
to the US in order to form
Constitution a more perfect union,
establish justice,
insure domestic tranquility,
provide for the common defense,
promote the general welfare,
and secure the blessing of liberty
to ourselves and our posterity,
do ordain and establish
the Constitution
of the United States of America.
EOF
`
args=52h3
expected=`cat << 'EOF'
Preamble We the people of the United
to the US States, in order to form a
Constitution more perfect union, establish
justice, insure domestic
tranquility, provide for the
common defense, promote the
general welfare, and secure
the blessing of liberty to
ourselves and our posterity,
do ordain and establish the
Constitution of the United
States of America.
EOF
`
test_par $args
input=`cat << 'EOF'
1 We the people of the United States,
2 in order to form a more perfect union,
3 establish justice,
4 insure domestic tranquility,
5 provide for the common defense,
6 promote the general welfare,
7 and secure the blessing of liberty
8 to ourselves and our posterity,
9 do ordain and establish the Constitution
10 of the United States of America.
EOF
`
args=59p12l
expected=`cat << 'EOF'
1 We the people of the United States, in order to
2 form a more perfect union, establish justice,
3 insure domestic tranquility, provide for the
4 common defense, promote the general welfare,
5 and secure the blessing of liberty to ourselves
6 and our posterity, do ordain and establish the
7 Constitution of the United States of America.
EOF
`
test_par $args
input=`cat << 'EOF'
> > We the people
> > of the United States,
> > in order to form a more perfect union,
> > establish justice,
> > ensure domestic tranquility,
> > provide for the common defense,
>
> Promote the general welfare,
> and secure the blessing of liberty
> to ourselves and our posterity,
> do ordain and establish
> the Constitution of the United States of America.
EOF
`
args=52
expected=`cat << 'EOF'
> > We the people of the United States, in
> > order to form a more perfect union,
> > establish justice, ensure domestic
> > tranquility, provide for the common
> > defense,
>
> Promote the general welfare, and secure
> the blessing of liberty to ourselves and
> our posterity, do ordain and establish
> the Constitution of the United States of
> America.
EOF
`
test_par $args
input=`cat << 'EOF'
> We the people
> of the United States,
> in order to form a more perfect union,
> establish justice,
> ensure domestic tranquility,
> provide for the common defense,
> Promote the general welfare,
> and secure the blessing of liberty
> to ourselves and our posterity,
> do ordain and establish
> the Constitution of the United States of America.
EOF
`
args=52d
expected=`cat << 'EOF'
> We the people of the United States,
> in order to form a more perfect union,
> establish justice, ensure domestic
> tranquility, provide for the common
> defense,
> Promote the general welfare, and secure
> the blessing of liberty to ourselves and
> our posterity, do ordain and establish
> the Constitution of the United States of
> America.
EOF
`
test_par $args
input=`cat << 'EOF'
# 1. We the people of the United States.
# 2. In order to form a more perfect union.
# 3. Establish justice, ensure domestic
# tranquility.
# 4. Provide for the common defense
# 5. Promote the general welfare.
# 6. And secure the blessing of liberty
# to ourselves and our posterity.
# 7. Do ordain and establish the Constitution.
# 8. Of the United States of America.
EOF
`
args=37p13dh
expected=`cat << 'EOF'
# 1. We the people of the
# United States.
# 2. In order to form a more
# perfect union.
# 3. Establish justice,
# ensure domestic
# tranquility.
# 4. Provide for the common
# defense
# 5. Promote the general
# welfare.
# 6. And secure the blessing
# of liberty to ourselves
# and our posterity.
# 7. Do ordain and establish
# the Constitution.
# 8. Of the United States of
# America.
EOF
`
test_par $args
input=`cat << 'EOF'
/*****************************************/
/* We the people of the United States, */
/* in order to form a more perfect union, */
/* establish justice, insure domestic */
/* tranquility, */
/* */
/* */
/* [ provide for the common defense, ] */
/* [ promote the general welfare, ] */
/* [ and secure the blessing of liberty ] */
/* [ to ourselves and our posterity, ] */
/* [ ] */
/* */
/* do ordain and establish the Constitution */
/* of the United States of America. */
/******************************************/
EOF
`
args=42r
expected=`cat << 'EOF'
/********************************/
/* We the people of the */
/* United States, in order to */
/* form a more perfect union, */
/* establish justice, insure */
/* domestic tranquility, */
/* */
/* */
/* [ provide for the common ] */
/* [ defense, promote the ] */
/* [ general welfare, and ] */
/* [ secure the blessing of ] */
/* [ liberty to ourselves ] */
/* [ and our posterity, ] */
/* [ ] */
/* */
/* do ordain and establish the */
/* Constitution of the United */
/* States of America. */
/********************************/
EOF
`
test_par $args
args=42re
expected=`cat << 'EOF'
/********************************/
/* We the people of the */
/* United States, in order to */
/* form a more perfect union, */
/* establish justice, insure */
/* domestic tranquility, */
/* */
/* [ provide for the common ] */
/* [ defense, promote the ] */
/* [ general welfare, and ] */
/* [ secure the blessing of ] */
/* [ liberty to ourselves ] */
/* [ and our posterity, ] */
/* */
/* do ordain and establish the */
/* Constitution of the United */
/* States of America. */
/********************************/
EOF
`
test_par $args
input=`cat << 'EOF'
Joe Public writes:
> Jane Doe writes:
> >
> >
> > I can't find the source for uncompress.
> Oh no, not again!!!
>
>
> Isn't there a FAQ for this?
>
>
That wasn't very helpful, Joe. Jane,
just make a link from uncompress to compress.
EOF
`
args=40q
expected=`cat << 'EOF'
Joe Public writes:
> Jane Doe writes:
>
>
> > I can't find the source for
> > uncompress.
>
> Oh no, not again!!!
>
>
> Isn't there a FAQ for this?
>
That wasn't very helpful, Joe.
Jane, just make a link from
uncompress to compress.
EOF
`
test_par $args
args=40qe
expected=`cat << 'EOF'
Joe Public writes:
> Jane Doe writes:
>
> > I can't find the source for
> > uncompress.
>
> Oh no, not again!!!
>
> Isn't there a FAQ for this?
That wasn't very helpful, Joe.
Jane, just make a link from
uncompress to compress.
EOF
`
test_par $args
args=40qi
expected=`cat << 'EOF'
Joe Public writes:
> Jane Doe writes:
> >
> >
> > I can't find the source for
> > uncompress.
> Oh no, not again!!!
>
>
> Isn't there a FAQ for this?
>
>
That wasn't very helpful, Joe.
Jane, just make a link from
uncompress to compress.
EOF
`
test_par $args
args=40qie
expected=`cat << 'EOF'
Joe Public writes:
> Jane Doe writes:
> > I can't find the source for
> > uncompress.
> Oh no, not again!!!
>
> Isn't there a FAQ for this?
That wasn't very helpful, Joe.
Jane, just make a link from
uncompress to compress.
EOF
`
test_par $args
input=`cat << 'EOF'
I sure hope there's still room
in Dr. Jones' section of archaeology.
I've heard he's the bestest. [sic]
EOF
`
args=50g
expected=`cat << 'EOF'
I sure hope there's still room in
Dr. Jones' section of archaeology. I've
heard he's the bestest. [sic]
EOF
`
test_par $args
args=50gc
expected=`cat << 'EOF'
I sure hope there's still room in
Dr. Jones' section of archaeology. I've
heard he's the bestest. [sic]
EOF
`
test_par $args
input=`cat << 'EOF'
John writes:
: Mary writes:
: + Anastasia writes:
: + > Hi all!
: + Hi Ana!
: Hi Ana & Mary!
Please unsubscribe me from alt.hello.
EOF
`
args='Q+:+ q'
expected=`cat << 'EOF'
John writes:
: Mary writes:
:
: + Anastasia writes:
: +
: + > Hi all!
: +
: + Hi Ana!
:
: Hi Ana & Mary!
Please unsubscribe me from alt.hello.
EOF
`
test_par $args
input=`cat << 'EOF'
amc> The b option was added primarily to deal with
amc> this new style of quotation
amc> which became popular after Par 1.41 was released.
amc>
amc> Par still pays attention to body characters.
amc> Par should not mistake "Par" for part of the prefix.
amc> Par should not mistake "." for a suffix.
EOF
`
args='B=._A_a 50bg'
expected=`cat << 'EOF'
amc> The b option was added primarily to
amc> deal with this new style of quotation
amc> which became popular after Par 1.41
amc> was released.
amc>
amc> Par still pays attention to body
amc> characters. Par should not mistake
amc> "Par" for part of the prefix. Par
amc> should not mistake "." for a suffix.
EOF
`
test_par $args
# Tests for new features in 1.53.0:
tmpdir=`mktemp -d`
export LOCPATH=$tmpdir/locale
mkdir -p $LOCPATH/en_US
mkdir $LOCPATH/he_IL
localedef -f ISO-8859-1 -i en_US $LOCPATH/en_US
localedef -f ISO-8859-8 -i he_IL $LOCPATH/he_IL
# ISO-8859-1 capital letters A and AE, small letters A and AE
input=`printf 'A\306a\346'`
#
args=
locale=C
expected=$input
test_par $args
locale=en_US
expected=$input
test_par $args
#
args=W=_A
locale=C
expected=`printf ' \306a\346'`
test_par $args
locale=en_US
expected=`printf ' a\346'`
test_par $args
#
args=W=_a
locale=C
expected=`printf 'A\306 \346'`
test_par $args
locale=en_US
expected=`printf 'A\306'`
test_par $args
# ISO-8859-1 no-break spaces and vertical tabs
input=`printf 'X\240\240\240Y\v\v\vZ'`
#
args=
locale=C
expected=`printf 'X\240\240\240Y Z'`
test_par $args
locale=en_US
test_par $args
#
args=W=_S
locale=C
expected=`printf 'X\240\240\240Y Z'`
test_par $args
#
args=W=
locale=en_US
expected=$input
test_par $args
#
# The behavior of isspace() on non-ASCII characters (like no-break
# space) in locales other than C is not standardized, and has been
# observed to vary, so we won't test that. If you want to refer to
# no-break space, the surest way is with _x.
args=W+_xA0
locale=en_US
expected='X Y Z'
test_par $args
# ISO-8859-8 letter alef
input=`printf '.\n\340'`
#
args=P=_A_a
locale=he_IL
expected=`printf '. \340'`
test_par $args
#
args=P=_@
expected=`printf '.\n\340'`
test_par $args
unset LOCPATH locale
input=`cat << 'EOF'
> one
>> two
>>> three
>>>> four
>>>>> five
EOF
`
args='Q=> qr'
expected=`cat << 'EOF'
> one
>
>> two
>>
>>> three
>>>
>>>> four
>>>>
>>>>> five
EOF
`
test_par $args
input=`cat << 'EOF'
One.
Two:
Three.
EOF
`
args=g
expected=`cat << 'EOF'
One. Two: Three.
EOF
`
test_par $args
#
args='g Z-:'
expected=`cat << 'EOF'
One. Two: Three.
EOF
`
test_par $args
rm -rf $tmpdir
echo
echo "$pass_count passed"
echo "$fail_count failed"
[ 0 = $fail_count ]
|