sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

0040-dc.sh (2273B)


      1 #!/bin/sh
      2 
      3 tmp1=$$.tmp1
      4 tmp2=$$.tmp2
      5 
      6 trap 'rm -f $tmp1 $tmp2' EXIT
      7 trap 'exit $?' HUP INT TERM
      8 
      9 # Test x, >, !>, <, !<, =, != commands
     10 # Note: dc pops values and compares: first_popped OP second_popped
     11 # So "3 5 >a" pops 5 then 3, checks 5 > 3 (true)
     12 # And "5 3 >a" pops 3 then 5, checks 3 > 5 (false)
     13 ($EXEC ../dc <<'EOF' 2>$tmp2
     14 [test 1:]pc [42p]x c
     15 [test 2:]pc 5 x p c
     16 [test 3:]pc []x c
     17 [test 4:]pc [[10p]x]x c
     18 [test 5:]pc [[YES]p]sa 3 5 >a c
     19 [test 6:]pc [[NO]p]sa 5 3 >a c
     20 [test 7:]pc [[NO]p]sa 5 5 >a c
     21 [test 8:]pc [[YES]p]sa 5 3 <a c
     22 [test 9:]pc [[NO]p]sa 3 5 <a c
     23 [test 10:]pc [[NO]p]sa 5 5 <a c
     24 [test 11:]pc [[YES]p]sa 5 5 =a c
     25 [test 12:]pc [[NO]p]sa 5 3 =a c
     26 [test 13:]pc [[NO]p]sa 3 5 !>a c
     27 [test 14:]pc [[YES]p]sa 5 3 !>a c
     28 [test 15:]pc [[YES]p]sa 5 5 !>a c
     29 [test 16:]pc [[NO]p]sa 5 3 !<a c
     30 [test 17:]pc [[YES]p]sa 3 5 !<a c
     31 [test 18:]pc [[YES]p]sa 5 5 !<a c
     32 [test 19:]pc [[YES]p]sa 5 3 !=a c
     33 [test 20:]pc [[NO]p]sa 5 5 !=a c
     34 [test 21:]pc [[NO]p]sa _3 _5 >a c
     35 [test 22:]pc [[YES]p]sa _5 _3 >a c
     36 [test 23:]pc [[NO]p]sa 3 _5 >a c
     37 [test 24:]pc [[YES]p]sa _3 5 >a c
     38 [test 25:]pc [[YES]p]sa 0 0 =a c
     39 [test 26:]pc [[YES]p]sa _0 0 =a c
     40 [test 27:]pc [[YES]p]sa 1.4 1.5 >a c
     41 [test 28:]pc [[YES]p]sa 1.5 1.5 =a c
     42 [test 29:]pc [[YES]p]sa 1.5 1.4 <a c
     43 [test 30:]pc [[YES]p]sa 99999999999999999998 99999999999999999999 >a c
     44 [test 31:]pc [d p 1 - d 0 <a]sa 5 la x c
     45 [test 32:]pc [[YES]p]sa [2 2 =a]sb 2 2 =b c
     46 [test 33:]pc 99 sa la x p c
     47 [test 34:]pc [3p]sa [2p]sb 2 3 >a 3 2 <b c
     48 [test 35:]pc [[NO]p]sa 1 2 <a z p c
     49 [test 36:]pc [[[[[77p]]]]]x x x x x c
     50 [test 37:]pc [[YES]p]sa 2k 1.50 1.5 =a c
     51 [test 38:]pc [1p]x [2p]x [3p]x c
     52 [test 39:]pc x
     53 [test 40:]pc [[NO]p]sa 5 >a
     54 [test 41:]pc [[NO]p]sa >a
     55 EOF
     56 cat $tmp2) > $tmp1
     57 
     58 diff -u - $tmp1 <<'EOF'
     59 test 1:
     60 42
     61 test 2:
     62 5
     63 test 3:
     64 test 4:
     65 10
     66 test 5:
     67 YES
     68 test 6:
     69 test 7:
     70 test 8:
     71 YES
     72 test 9:
     73 test 10:
     74 test 11:
     75 YES
     76 test 12:
     77 test 13:
     78 test 14:
     79 YES
     80 test 15:
     81 YES
     82 test 16:
     83 test 17:
     84 YES
     85 test 18:
     86 YES
     87 test 19:
     88 YES
     89 test 20:
     90 test 21:
     91 test 22:
     92 YES
     93 test 23:
     94 test 24:
     95 YES
     96 test 25:
     97 YES
     98 test 26:
     99 YES
    100 test 27:
    101 YES
    102 test 28:
    103 YES
    104 test 29:
    105 YES
    106 test 30:
    107 YES
    108 test 31:
    109 5
    110 4
    111 3
    112 2
    113 1
    114 test 32:
    115 YES
    116 test 33:
    117 99
    118 test 34:
    119 3
    120 2
    121 test 35:
    122 0
    123 test 36:
    124 77
    125 test 37:
    126 YES
    127 test 38:
    128 1
    129 2
    130 3
    131 test 39:
    132 test 40:
    133 test 41:
    134 ../dc: stack empty
    135 ../dc: stack empty
    136 ../dc: stack empty
    137 EOF