sbase

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

0040-dc.sh (2233B)


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