Mercurial > hg > toybox
annotate tests/expr.test @ 1613:96aa7ec74936 draft
Fix yet another sed bug.
The s/// command would copy the \ of substitutions before deciding what to
do with them (generally overwriting the \ with the new data). When the
substitution was A) at the very end of the new string, B) resolved to nothing,
it could leave a trailing \ that didn't belong there and didn't get overwritten
because the "copy trailing data" part that copies the original string's null
terminator already happened before the \ overwrote it.
The ghostwheel() function restarts regexes after embedded NUL bytes, but
if the string it's passed is _longer_ than the length it's told then it
gets confused (and it means we're off the end of our allocation so segfaults
are likely).
Fix: test for \ first and move the "copy byte" logic into an else case.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 15 Dec 2014 03:34:55 -0600 |
parents | d5931155cafe |
children |
rev | line source |
---|---|
920
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 #!/bin/bash |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 [ -f testing.sh ] && . testing.sh |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 testing "expr integer" "expr 5" "5\n" "" "" |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 testing "expr integer negative" "expr -5" "-5\n" "" "" |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 testing "expr string" "expr astring" "astring\n" "" "" |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 testing "expr 1 + 3" "expr 1 + 3" "4\n" "" "" |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 testing "expr 5 + 6 * 3" "expr 5 + 6 \* 3" "23\n" "" "" |
74b5cf0309fc
Start of expr, by Daniel Verkamp.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 testing "expr ( 5 + 6 ) * 3" "expr \( 5 + 6 \) \* 3" "33\n" "" "" |
1589
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
11 testing "expr * / same priority" "expr 4 \* 3 / 2" "6\n" "" "" |
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
12 testing "expr / * same priority" "expr 3 / 2 \* 4" "4\n" "" "" |
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
13 testing "expr & before |" "expr 0 \| 1 \& 0" "0\n" "" "" |
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
14 testing "expr | after &" "expr 1 \| 0 \& 0" "1\n" "" "" |
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
15 testing "expr | & same priority" "expr 0 \& 0 \| 1" "1\n" "" "" |
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
16 testing "expr % * same priority" "expr 3 % 2 \* 4" "4\n" "" "" |
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
17 testing "expr * % same priority" "expr 3 \* 2 % 4" "2\n" "" "" |
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
18 testing "expr = > same priority" "expr 0 = 2 \> 3" "0\n" "" "" |
a97f69a1e406
Tests for operator priority groupings.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
19 testing "expr > = same priority" "expr 3 \> 2 = 1" "1\n" "" "" |
1590
d5931155cafe
Refactor expr and add another test entry that works with TEST_HOST=1 but not with the one in pending.
Rob Landley <rob@landley.net>
parents:
1589
diff
changeset
|
20 testing "expr string becomes integer" "expr ab21xx : '[^0-9]*\([0-9]*\)' + 3" \ |
d5931155cafe
Refactor expr and add another test entry that works with TEST_HOST=1 but not with the one in pending.
Rob Landley <rob@landley.net>
parents:
1589
diff
changeset
|
21 "24\n" "" "" |