fortrangoingonforty/fortsh / eadc361

Browse files

Add quoting and file test coverage to reach 1661 tests

- posix_compliance_quoting.sh: sections 465-480 (escape sequences, word splitting,
special parameters, nested quoting, glob prevention, tests, case patterns,
function args, dollar/backslash in quotes, quote removal, mixed styles)
- posix_compliance_filetest.sh: sections 388-400 (numeric comparisons, negative
numbers, string tests, file permissions, test vs [, logical tests, file types,
file size, symlinks, special files, terminals, precedence, edge cases)

Total: 1661 tests (93% pass rate)
Authored by espadonne
SHA
eadc36196c7b2f0ef9010a18766ae95c2d0229ba
Parents
43d102f
Tree
3224ffc

2 changed files

StatusFile+-
M tests/posix_compliance_filetest.sh 324 0
M tests/posix_compliance_quoting.sh 331 0
tests/posix_compliance_filetest.shmodified
@@ -761,6 +761,330 @@ else
761761
     fail "[ \"\$unset\" = \"\" ] unset equals empty" "yes" "$result"
762762
 fi
763763
 
764
+# =====================================
765
+section "388. NUMERIC COMPARISON OPERATORS"
766
+# =====================================
767
+
768
+result=$("$FORTSH_BIN" -c '[ 5 -eq 5 ] && echo yes || echo no' 2>&1)
769
+if [ "$result" = "yes" ]; then
770
+    pass "[ 5 -eq 5 ] equals"
771
+else
772
+    fail "[ 5 -eq 5 ] equals" "yes" "$result"
773
+fi
774
+
775
+result=$("$FORTSH_BIN" -c '[ 5 -ne 3 ] && echo yes || echo no' 2>&1)
776
+if [ "$result" = "yes" ]; then
777
+    pass "[ 5 -ne 3 ] not equals"
778
+else
779
+    fail "[ 5 -ne 3 ] not equals" "yes" "$result"
780
+fi
781
+
782
+result=$("$FORTSH_BIN" -c '[ 10 -gt 5 ] && echo yes || echo no' 2>&1)
783
+if [ "$result" = "yes" ]; then
784
+    pass "[ 10 -gt 5 ] greater than"
785
+else
786
+    fail "[ 10 -gt 5 ] greater than" "yes" "$result"
787
+fi
788
+
789
+result=$("$FORTSH_BIN" -c '[ 10 -ge 10 ] && echo yes || echo no' 2>&1)
790
+if [ "$result" = "yes" ]; then
791
+    pass "[ 10 -ge 10 ] greater or equal"
792
+else
793
+    fail "[ 10 -ge 10 ] greater or equal" "yes" "$result"
794
+fi
795
+
796
+result=$("$FORTSH_BIN" -c '[ 3 -lt 5 ] && echo yes || echo no' 2>&1)
797
+if [ "$result" = "yes" ]; then
798
+    pass "[ 3 -lt 5 ] less than"
799
+else
800
+    fail "[ 3 -lt 5 ] less than" "yes" "$result"
801
+fi
802
+
803
+result=$("$FORTSH_BIN" -c '[ 3 -le 3 ] && echo yes || echo no' 2>&1)
804
+if [ "$result" = "yes" ]; then
805
+    pass "[ 3 -le 3 ] less or equal"
806
+else
807
+    fail "[ 3 -le 3 ] less or equal" "yes" "$result"
808
+fi
809
+
810
+# =====================================
811
+section "389. NEGATIVE NUMBER TESTS"
812
+# =====================================
813
+
814
+result=$("$FORTSH_BIN" -c '[ -5 -lt 0 ] && echo yes || echo no' 2>&1)
815
+if [ "$result" = "yes" ]; then
816
+    pass "[ -5 -lt 0 ] negative less than zero"
817
+else
818
+    fail "[ -5 -lt 0 ] negative less than zero" "yes" "$result"
819
+fi
820
+
821
+result=$("$FORTSH_BIN" -c '[ -10 -lt -5 ] && echo yes || echo no' 2>&1)
822
+if [ "$result" = "yes" ]; then
823
+    pass "[ -10 -lt -5 ] negative comparison"
824
+else
825
+    fail "[ -10 -lt -5 ] negative comparison" "yes" "$result"
826
+fi
827
+
828
+result=$("$FORTSH_BIN" -c '[ -5 -eq -5 ] && echo yes || echo no' 2>&1)
829
+if [ "$result" = "yes" ]; then
830
+    pass "[ -5 -eq -5 ] negative equality"
831
+else
832
+    fail "[ -5 -eq -5 ] negative equality" "yes" "$result"
833
+fi
834
+
835
+# =====================================
836
+section "390. STRING TESTS"
837
+# =====================================
838
+
839
+result=$("$FORTSH_BIN" -c '[ "hello" = "hello" ] && echo yes || echo no' 2>&1)
840
+if [ "$result" = "yes" ]; then
841
+    pass "[ \"hello\" = \"hello\" ] string equality"
842
+else
843
+    fail "[ \"hello\" = \"hello\" ] string equality" "yes" "$result"
844
+fi
845
+
846
+result=$("$FORTSH_BIN" -c '[ "hello" != "world" ] && echo yes || echo no' 2>&1)
847
+if [ "$result" = "yes" ]; then
848
+    pass "[ \"hello\" != \"world\" ] string inequality"
849
+else
850
+    fail "[ \"hello\" != \"world\" ] string inequality" "yes" "$result"
851
+fi
852
+
853
+result=$("$FORTSH_BIN" -c '[ "abc" \< "def" ] && echo yes || echo no' 2>&1)
854
+if [ "$result" = "yes" ]; then
855
+    pass "[ \"abc\" < \"def\" ] string less than"
856
+else
857
+    fail "[ \"abc\" < \"def\" ] string less than" "yes" "$result"
858
+fi
859
+
860
+result=$("$FORTSH_BIN" -c '[ "xyz" \> "abc" ] && echo yes || echo no' 2>&1)
861
+if [ "$result" = "yes" ]; then
862
+    pass "[ \"xyz\" > \"abc\" ] string greater than"
863
+else
864
+    fail "[ \"xyz\" > \"abc\" ] string greater than" "yes" "$result"
865
+fi
866
+
867
+# =====================================
868
+section "391. FILE PERMISSION TESTS"
869
+# =====================================
870
+
871
+touch "$TEST_DIR/readable.txt"
872
+chmod 644 "$TEST_DIR/readable.txt"
873
+result=$("$FORTSH_BIN" -c '[ -r "'"$TEST_DIR"'/readable.txt" ] && echo yes || echo no' 2>&1)
874
+if [ "$result" = "yes" ]; then
875
+    pass "[ -r file ] readable file"
876
+else
877
+    fail "[ -r file ] readable file" "yes" "$result"
878
+fi
879
+
880
+result=$("$FORTSH_BIN" -c '[ -w "'"$TEST_DIR"'/readable.txt" ] && echo yes || echo no' 2>&1)
881
+if [ "$result" = "yes" ]; then
882
+    pass "[ -w file ] writable file"
883
+else
884
+    fail "[ -w file ] writable file" "yes" "$result"
885
+fi
886
+
887
+# =====================================
888
+section "392. TEST BUILTIN vs [ COMMAND"
889
+# =====================================
890
+
891
+result=$("$FORTSH_BIN" -c 'test -f /etc/passwd && echo yes || echo no' 2>&1)
892
+if [ "$result" = "yes" ]; then
893
+    pass "test -f /etc/passwd"
894
+else
895
+    fail "test -f /etc/passwd" "yes" "$result"
896
+fi
897
+
898
+result=$("$FORTSH_BIN" -c 'test 5 -eq 5 && echo yes || echo no' 2>&1)
899
+if [ "$result" = "yes" ]; then
900
+    pass "test 5 -eq 5"
901
+else
902
+    fail "test 5 -eq 5" "yes" "$result"
903
+fi
904
+
905
+result=$("$FORTSH_BIN" -c 'test "hello" = "hello" && echo yes || echo no' 2>&1)
906
+if [ "$result" = "yes" ]; then
907
+    pass "test string equality"
908
+else
909
+    fail "test string equality" "yes" "$result"
910
+fi
911
+
912
+# =====================================
913
+section "393. COMBINED LOGICAL TESTS"
914
+# =====================================
915
+
916
+result=$("$FORTSH_BIN" -c '[ 5 -gt 3 ] && [ 10 -gt 5 ] && echo yes || echo no' 2>&1)
917
+if [ "$result" = "yes" ]; then
918
+    pass "[ ] && [ ] both true"
919
+else
920
+    fail "[ ] && [ ] both true" "yes" "$result"
921
+fi
922
+
923
+result=$("$FORTSH_BIN" -c '[ 5 -lt 3 ] || [ 10 -gt 5 ] && echo yes || echo no' 2>&1)
924
+if [ "$result" = "yes" ]; then
925
+    pass "[ ] || [ ] one true"
926
+else
927
+    fail "[ ] || [ ] one true" "yes" "$result"
928
+fi
929
+
930
+result=$("$FORTSH_BIN" -c '! [ 5 -lt 3 ] && echo yes || echo no' 2>&1)
931
+if [ "$result" = "yes" ]; then
932
+    pass "! [ ] negation"
933
+else
934
+    fail "! [ ] negation" "yes" "$result"
935
+fi
936
+
937
+# =====================================
938
+section "394. FILE TYPE TESTS"
939
+# =====================================
940
+
941
+result=$("$FORTSH_BIN" -c '[ -f /etc/passwd ] && echo yes || echo no' 2>&1)
942
+if [ "$result" = "yes" ]; then
943
+    pass "[ -f /etc/passwd ] regular file"
944
+else
945
+    fail "[ -f /etc/passwd ] regular file" "yes" "$result"
946
+fi
947
+
948
+result=$("$FORTSH_BIN" -c '[ -d /tmp ] && echo yes || echo no' 2>&1)
949
+if [ "$result" = "yes" ]; then
950
+    pass "[ -d /tmp ] directory"
951
+else
952
+    fail "[ -d /tmp ] directory" "yes" "$result"
953
+fi
954
+
955
+result=$("$FORTSH_BIN" -c '[ -e /etc/passwd ] && echo yes || echo no' 2>&1)
956
+if [ "$result" = "yes" ]; then
957
+    pass "[ -e /etc/passwd ] exists"
958
+else
959
+    fail "[ -e /etc/passwd ] exists" "yes" "$result"
960
+fi
961
+
962
+result=$("$FORTSH_BIN" -c '[ -e /nonexistent/path ] && echo yes || echo no' 2>&1)
963
+if [ "$result" = "no" ]; then
964
+    pass "[ -e /nonexistent ] does not exist"
965
+else
966
+    fail "[ -e /nonexistent ] does not exist" "no" "$result"
967
+fi
968
+
969
+# =====================================
970
+section "395. FILE SIZE TESTS"
971
+# =====================================
972
+
973
+echo "content" > "$TEST_DIR/nonempty.txt"
974
+result=$("$FORTSH_BIN" -c '[ -s "'"$TEST_DIR"'/nonempty.txt" ] && echo yes || echo no' 2>&1)
975
+if [ "$result" = "yes" ]; then
976
+    pass "[ -s file ] non-empty file"
977
+else
978
+    fail "[ -s file ] non-empty file" "yes" "$result"
979
+fi
980
+
981
+: > "$TEST_DIR/empty.txt"
982
+result=$("$FORTSH_BIN" -c '[ -s "'"$TEST_DIR"'/empty.txt" ] && echo yes || echo no' 2>&1)
983
+if [ "$result" = "no" ]; then
984
+    pass "[ -s file ] empty file is false"
985
+else
986
+    fail "[ -s file ] empty file is false" "no" "$result"
987
+fi
988
+
989
+# =====================================
990
+section "396. SYMLINK TESTS"
991
+# =====================================
992
+
993
+ln -sf /etc/passwd "$TEST_DIR/link_to_passwd" 2>/dev/null || true
994
+result=$("$FORTSH_BIN" -c '[ -L "'"$TEST_DIR"'/link_to_passwd" ] && echo yes || echo no' 2>&1)
995
+if [ "$result" = "yes" ]; then
996
+    pass "[ -L symlink ] is symlink"
997
+else
998
+    fail "[ -L symlink ] is symlink" "yes" "$result"
999
+fi
1000
+
1001
+result=$("$FORTSH_BIN" -c '[ -h "'"$TEST_DIR"'/link_to_passwd" ] && echo yes || echo no' 2>&1)
1002
+if [ "$result" = "yes" ]; then
1003
+    pass "[ -h symlink ] is symlink (alternate)"
1004
+else
1005
+    fail "[ -h symlink ] is symlink (alternate)" "yes" "$result"
1006
+fi
1007
+
1008
+# =====================================
1009
+section "397. SPECIAL FILE TESTS"
1010
+# =====================================
1011
+
1012
+result=$("$FORTSH_BIN" -c '[ -c /dev/null ] && echo yes || echo no' 2>&1)
1013
+if [ "$result" = "yes" ]; then
1014
+    pass "[ -c /dev/null ] character device"
1015
+else
1016
+    fail "[ -c /dev/null ] character device" "yes" "$result"
1017
+fi
1018
+
1019
+result=$("$FORTSH_BIN" -c '[ -p /dev/null ] && echo yes || echo no' 2>&1)
1020
+if [ "$result" = "no" ]; then
1021
+    pass "[ -p /dev/null ] not a pipe"
1022
+else
1023
+    fail "[ -p /dev/null ] not a pipe" "no" "$result"
1024
+fi
1025
+
1026
+# =====================================
1027
+section "398. TERMINAL TESTS"
1028
+# =====================================
1029
+
1030
+result=$("$FORTSH_BIN" -c '[ -t 1 ] && echo tty || echo not_tty' 2>&1)
1031
+# When running in a script, stdout is typically not a tty
1032
+if echo "$result" | grep -qE "(tty|not_tty)"; then
1033
+    pass "[ -t 1 ] terminal test runs"
1034
+else
1035
+    fail "[ -t 1 ] terminal test runs"
1036
+fi
1037
+
1038
+# =====================================
1039
+section "399. COMPOUND EXPRESSION PRECEDENCE"
1040
+# =====================================
1041
+
1042
+result=$("$FORTSH_BIN" -c '[ 1 -eq 1 ] && [ 2 -eq 2 ] && [ 3 -eq 3 ] && echo yes || echo no' 2>&1)
1043
+if [ "$result" = "yes" ]; then
1044
+    pass "Multiple && chain"
1045
+else
1046
+    fail "Multiple && chain" "yes" "$result"
1047
+fi
1048
+
1049
+result=$("$FORTSH_BIN" -c '[ 1 -eq 2 ] || [ 2 -eq 2 ] && echo yes || echo no' 2>&1)
1050
+if [ "$result" = "yes" ]; then
1051
+    pass "|| then && precedence"
1052
+else
1053
+    fail "|| then && precedence" "yes" "$result"
1054
+fi
1055
+
1056
+# =====================================
1057
+section "400. EDGE CASE EXPRESSIONS"
1058
+# =====================================
1059
+
1060
+result=$("$FORTSH_BIN" -c '[ "" ] && echo yes || echo no' 2>&1)
1061
+if [ "$result" = "no" ]; then
1062
+    pass "[ \"\" ] empty string is false"
1063
+else
1064
+    fail "[ \"\" ] empty string is false" "no" "$result"
1065
+fi
1066
+
1067
+result=$("$FORTSH_BIN" -c '[ "x" ] && echo yes || echo no' 2>&1)
1068
+if [ "$result" = "yes" ]; then
1069
+    pass "[ \"x\" ] non-empty string is true"
1070
+else
1071
+    fail "[ \"x\" ] non-empty string is true" "yes" "$result"
1072
+fi
1073
+
1074
+result=$("$FORTSH_BIN" -c '[ 0 ] && echo yes || echo no' 2>&1)
1075
+if [ "$result" = "yes" ]; then
1076
+    pass "[ 0 ] zero string is true (not numeric)"
1077
+else
1078
+    fail "[ 0 ] zero string is true (not numeric)" "yes" "$result"
1079
+fi
1080
+
1081
+result=$("$FORTSH_BIN" -c '[ ! "" ] && echo yes || echo no' 2>&1)
1082
+if [ "$result" = "yes" ]; then
1083
+    pass "[ ! \"\" ] negated empty is true"
1084
+else
1085
+    fail "[ ! \"\" ] negated empty is true" "yes" "$result"
1086
+fi
1087
+
7641088
 # =====================================
7651089
 # Summary
7661090
 # =====================================
tests/posix_compliance_quoting.shmodified
@@ -601,6 +601,337 @@ else
601601
     fail "Quoted assignment used in arithmetic" "8" "$result"
602602
 fi
603603
 
604
+# =====================================
605
+section "465. ESCAPE SEQUENCES"
606
+# =====================================
607
+
608
+result=$("$FORTSH_BIN" -c 'echo "hello\tworld"' 2>&1)
609
+if echo "$result" | grep -q "hello"; then
610
+    pass "Backslash-t in double quotes"
611
+else
612
+    fail "Backslash-t in double quotes"
613
+fi
614
+
615
+result=$("$FORTSH_BIN" -c "echo 'hello\nworld'" 2>&1)
616
+if echo "$result" | grep -q 'hello\\nworld'; then
617
+    pass "Backslash-n literal in single quotes"
618
+else
619
+    fail "Backslash-n literal in single quotes"
620
+fi
621
+
622
+# =====================================
623
+section "466. QUOTING AND WORD SPLITTING"
624
+# =====================================
625
+
626
+result=$("$FORTSH_BIN" -c 'x="a b c"; set -- $x; echo $#' 2>&1)
627
+if [ "$result" = "3" ]; then
628
+    pass "Unquoted var splits on spaces"
629
+else
630
+    fail "Unquoted var splits on spaces" "3" "$result"
631
+fi
632
+
633
+result=$("$FORTSH_BIN" -c 'x="a b c"; set -- "$x"; echo $#' 2>&1)
634
+if [ "$result" = "1" ]; then
635
+    pass "Quoted var prevents splitting"
636
+else
637
+    fail "Quoted var prevents splitting" "1" "$result"
638
+fi
639
+
640
+result=$("$FORTSH_BIN" -c 'x=""; set -- $x; echo $#' 2>&1)
641
+if [ "$result" = "0" ]; then
642
+    pass "Empty unquoted var produces no args"
643
+else
644
+    fail "Empty unquoted var produces no args" "0" "$result"
645
+fi
646
+
647
+result=$("$FORTSH_BIN" -c 'x=""; set -- "$x"; echo $#' 2>&1)
648
+if [ "$result" = "1" ]; then
649
+    pass "Empty quoted var produces one empty arg"
650
+else
651
+    fail "Empty quoted var produces one empty arg" "1" "$result"
652
+fi
653
+
654
+# =====================================
655
+section "467. QUOTING SPECIAL PARAMETERS"
656
+# =====================================
657
+
658
+result=$("$FORTSH_BIN" -c 'set -- a b c; echo "$@" | wc -w' 2>&1)
659
+if [ "$result" = "3" ]; then
660
+    pass 'Quoted $@ preserves args'
661
+else
662
+    fail 'Quoted $@ preserves args' "3" "$result"
663
+fi
664
+
665
+result=$("$FORTSH_BIN" -c 'set -- a b c; echo "$*"' 2>&1)
666
+if [ "$result" = "a b c" ]; then
667
+    pass 'Quoted $* joins args'
668
+else
669
+    fail 'Quoted $* joins args' "a b c" "$result"
670
+fi
671
+
672
+result=$("$FORTSH_BIN" -c 'set -- a "b c" d; for x in "$@"; do echo "[$x]"; done' 2>&1)
673
+expected=$(printf "[a]\n[b c]\n[d]")
674
+if [ "$result" = "$expected" ]; then
675
+    pass 'Quoted $@ preserves quoting in original args'
676
+else
677
+    fail 'Quoted $@ preserves quoting in original args'
678
+fi
679
+
680
+# =====================================
681
+section "468. NESTED QUOTING"
682
+# =====================================
683
+
684
+result=$("$FORTSH_BIN" -c "echo 'single \"with\" double'" 2>&1)
685
+if [ "$result" = 'single "with" double' ]; then
686
+    pass "Double quotes inside single quotes"
687
+else
688
+    fail "Double quotes inside single quotes"
689
+fi
690
+
691
+result=$("$FORTSH_BIN" -c 'echo "double '\''with'\'' single"' 2>&1)
692
+if [ "$result" = "double 'with' single" ]; then
693
+    pass "Single quotes inside double quotes (escaped)"
694
+else
695
+    fail "Single quotes inside double quotes (escaped)"
696
+fi
697
+
698
+# =====================================
699
+section "469. QUOTING IN ASSIGNMENTS"
700
+# =====================================
701
+
702
+result=$("$FORTSH_BIN" -c 'x="hello world"; echo $x' 2>&1)
703
+if [ "$result" = "hello world" ]; then
704
+    pass "Quoted assignment with spaces"
705
+else
706
+    fail "Quoted assignment with spaces" "hello world" "$result"
707
+fi
708
+
709
+result=$("$FORTSH_BIN" -c "x='hello world'; echo \$x" 2>&1)
710
+if [ "$result" = "hello world" ]; then
711
+    pass "Single-quoted assignment with spaces"
712
+else
713
+    fail "Single-quoted assignment with spaces" "hello world" "$result"
714
+fi
715
+
716
+result=$("$FORTSH_BIN" -c 'x=hello\ world; echo $x' 2>&1)
717
+if [ "$result" = "hello world" ]; then
718
+    pass "Escaped space in assignment"
719
+else
720
+    fail "Escaped space in assignment" "hello world" "$result"
721
+fi
722
+
723
+# =====================================
724
+section "470. QUOTING IN COMMAND SUBSTITUTION"
725
+# =====================================
726
+
727
+result=$("$FORTSH_BIN" -c 'x=$(echo "hello world"); echo "$x"' 2>&1)
728
+if [ "$result" = "hello world" ]; then
729
+    pass "Quoted string in command substitution"
730
+else
731
+    fail "Quoted string in command substitution" "hello world" "$result"
732
+fi
733
+
734
+result=$("$FORTSH_BIN" -c 'x=`echo "hello world"`; echo "$x"' 2>&1)
735
+if [ "$result" = "hello world" ]; then
736
+    pass "Quoted string in backtick substitution"
737
+else
738
+    fail "Quoted string in backtick substitution" "hello world" "$result"
739
+fi
740
+
741
+# =====================================
742
+section "471. QUOTING AND GLOB PREVENTION"
743
+# =====================================
744
+
745
+result=$("$FORTSH_BIN" -c 'echo "*"' 2>&1)
746
+if [ "$result" = "*" ]; then
747
+    pass "Quoted asterisk is literal"
748
+else
749
+    fail "Quoted asterisk is literal" "*" "$result"
750
+fi
751
+
752
+result=$("$FORTSH_BIN" -c 'echo "?"' 2>&1)
753
+if [ "$result" = "?" ]; then
754
+    pass "Quoted question mark is literal"
755
+else
756
+    fail "Quoted question mark is literal" "?" "$result"
757
+fi
758
+
759
+result=$("$FORTSH_BIN" -c 'echo "[abc]"' 2>&1)
760
+if [ "$result" = "[abc]" ]; then
761
+    pass "Quoted brackets are literal"
762
+else
763
+    fail "Quoted brackets are literal" "[abc]" "$result"
764
+fi
765
+
766
+# =====================================
767
+section "472. QUOTING IN TESTS"
768
+# =====================================
769
+
770
+result=$("$FORTSH_BIN" -c 'x=""; [ -z "$x" ] && echo empty' 2>&1)
771
+if [ "$result" = "empty" ]; then
772
+    pass "Quoted empty var in test -z"
773
+else
774
+    fail "Quoted empty var in test -z" "empty" "$result"
775
+fi
776
+
777
+result=$("$FORTSH_BIN" -c 'x="hello"; [ -n "$x" ] && echo nonempty' 2>&1)
778
+if [ "$result" = "nonempty" ]; then
779
+    pass "Quoted var in test -n"
780
+else
781
+    fail "Quoted var in test -n" "nonempty" "$result"
782
+fi
783
+
784
+result=$("$FORTSH_BIN" -c 'x="a b"; [ "$x" = "a b" ] && echo match' 2>&1)
785
+if [ "$result" = "match" ]; then
786
+    pass "Quoted var with spaces in test ="
787
+else
788
+    fail "Quoted var with spaces in test =" "match" "$result"
789
+fi
790
+
791
+# =====================================
792
+section "473. QUOTING IN CASE PATTERNS"
793
+# =====================================
794
+
795
+result=$("$FORTSH_BIN" -c 'x="*"; case "$x" in "*") echo literal;; esac' 2>&1)
796
+if [ "$result" = "literal" ]; then
797
+    pass "Quoted asterisk matches literally in case"
798
+else
799
+    fail "Quoted asterisk matches literally in case" "literal" "$result"
800
+fi
801
+
802
+result=$("$FORTSH_BIN" -c 'x="a b"; case "$x" in "a b") echo match;; esac' 2>&1)
803
+if [ "$result" = "match" ]; then
804
+    pass "Quoted pattern with space in case"
805
+else
806
+    fail "Quoted pattern with space in case" "match" "$result"
807
+fi
808
+
809
+# =====================================
810
+section "474. QUOTING IN FUNCTION ARGS"
811
+# =====================================
812
+
813
+result=$("$FORTSH_BIN" -c 'f() { echo "[$1]"; }; f "hello world"' 2>&1)
814
+if [ "$result" = "[hello world]" ]; then
815
+    pass "Quoted arg to function"
816
+else
817
+    fail "Quoted arg to function" "[hello world]" "$result"
818
+fi
819
+
820
+result=$("$FORTSH_BIN" -c 'f() { echo $#; }; f "a b" "c d"' 2>&1)
821
+if [ "$result" = "2" ]; then
822
+    pass "Quoted args count in function"
823
+else
824
+    fail "Quoted args count in function" "2" "$result"
825
+fi
826
+
827
+# =====================================
828
+section "475. DOLLAR IN QUOTES"
829
+# =====================================
830
+
831
+result=$("$FORTSH_BIN" -c 'echo "\$HOME"' 2>&1)
832
+if [ "$result" = '$HOME' ]; then
833
+    pass "Escaped dollar in double quotes"
834
+else
835
+    fail "Escaped dollar in double quotes" "\$HOME" "$result"
836
+fi
837
+
838
+result=$("$FORTSH_BIN" -c "echo '\$HOME'" 2>&1)
839
+if [ "$result" = '$HOME' ]; then
840
+    pass "Dollar in single quotes"
841
+else
842
+    fail "Dollar in single quotes" "\$HOME" "$result"
843
+fi
844
+
845
+# =====================================
846
+section "476. BACKSLASH IN QUOTES"
847
+# =====================================
848
+
849
+result=$("$FORTSH_BIN" -c 'echo "\\"' 2>&1)
850
+if [ "$result" = '\' ]; then
851
+    pass "Escaped backslash in double quotes"
852
+else
853
+    fail "Escaped backslash in double quotes" "\\" "$result"
854
+fi
855
+
856
+result=$("$FORTSH_BIN" -c "echo '\\'" 2>&1)
857
+if [ "$result" = '\' ]; then
858
+    pass "Backslash in single quotes"
859
+else
860
+    fail "Backslash in single quotes" "\\" "$result"
861
+fi
862
+
863
+# =====================================
864
+section "477. QUOTE REMOVAL"
865
+# =====================================
866
+
867
+result=$("$FORTSH_BIN" -c 'echo ""hello""' 2>&1)
868
+if [ "$result" = "hello" ]; then
869
+    pass "Empty quotes around word"
870
+else
871
+    fail "Empty quotes around word" "hello" "$result"
872
+fi
873
+
874
+result=$("$FORTSH_BIN" -c 'echo "a""b""c"' 2>&1)
875
+if [ "$result" = "abc" ]; then
876
+    pass "Adjacent quoted strings concatenate"
877
+else
878
+    fail "Adjacent quoted strings concatenate" "abc" "$result"
879
+fi
880
+
881
+# =====================================
882
+section "478. MIXED QUOTE STYLES"
883
+# =====================================
884
+
885
+result=$("$FORTSH_BIN" -c "x=val; echo 'a'\"\$x\"'b'" 2>&1)
886
+if [ "$result" = "avalb" ]; then
887
+    pass "Mixed single and double quotes"
888
+else
889
+    fail "Mixed single and double quotes" "avalb" "$result"
890
+fi
891
+
892
+result=$("$FORTSH_BIN" -c "echo 'single'\"double\"'single'" 2>&1)
893
+if [ "$result" = "singledoublesingle" ]; then
894
+    pass "Alternating quote styles"
895
+else
896
+    fail "Alternating quote styles" "singledoublesingle" "$result"
897
+fi
898
+
899
+# =====================================
900
+section "479. QUOTING IN REDIRECTIONS"
901
+# =====================================
902
+
903
+result=$("$FORTSH_BIN" -c 'echo test > "/tmp/quote space test.txt"; cat "/tmp/quote space test.txt"; rm "/tmp/quote space test.txt"' 2>&1)
904
+if [ "$result" = "test" ]; then
905
+    pass "Quoted filename with space in redirect"
906
+else
907
+    fail "Quoted filename with space in redirect" "test" "$result"
908
+fi
909
+
910
+# =====================================
911
+section "480. EMPTY QUOTES"
912
+# =====================================
913
+
914
+result=$("$FORTSH_BIN" -c 'echo ""' 2>&1)
915
+if [ -z "$result" ]; then
916
+    pass "Empty double quotes produce empty output"
917
+else
918
+    fail "Empty double quotes produce empty output" "empty" "$result"
919
+fi
920
+
921
+result=$("$FORTSH_BIN" -c "echo ''" 2>&1)
922
+if [ -z "$result" ]; then
923
+    pass "Empty single quotes produce empty output"
924
+else
925
+    fail "Empty single quotes produce empty output" "empty" "$result"
926
+fi
927
+
928
+result=$("$FORTSH_BIN" -c 'x=""; echo "[$x]"' 2>&1)
929
+if [ "$result" = "[]" ]; then
930
+    pass "Empty var in quotes"
931
+else
932
+    fail "Empty var in quotes" "[]" "$result"
933
+fi
934
+
604935
 # =====================================
605936
 # Summary
606937
 # =====================================