d01 ex04 erreur saute des find possibles

This commit is contained in:
Hugo LAMY
2022-02-07 19:27:30 +01:00
parent dc144127a9
commit ea0f9b085a
12 changed files with 40 additions and 9 deletions
+9 -4
View File
@@ -22,12 +22,17 @@ void Sed::replace() {
{
if (str[0] == this->_find[0])
{
tmp = str[0];
file.get(str, len, EOF);
if (this->_find.compare(1, len - 1, str) == 0)
if (len == 1)
new_file << this->_replacement;
else
new_file << tmp << str;
{
tmp = str[0];
file.get(str, len, EOF);
if (this->_find.compare(1, len - 1, str) == 0)
new_file << this->_replacement;
else
new_file << tmp << str;
}
}
else
new_file << str;
View File
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
+5
View File
@@ -0,0 +1,5 @@
ce fichier
contient
plusieurs lignes
les unes au dessus des autres
youhouuu ioieux
+1
View File
@@ -0,0 +1 @@
....................................................;
+2
View File
@@ -0,0 +1,2 @@
...................................................;
. . . . . . . . . . . . . . . . . . . . . . . . . .;
+18 -3
View File
@@ -1,4 +1,5 @@
#!/bin/bash
cd $(dirname $0)
source ./colors.sh
mkdir -p test_log
@@ -13,9 +14,9 @@ mkdir -p test_log
OUTPUT=$( cat $TESTNAME.replace )
if [ "$OUTPUT" == "$RESULT" ]
then
echo -e $B_GREEN"test1 success"$ENDCO
echo -e $B_GREEN"$TESTNAME success"$ENDCO
else
echo -e $B_RED"test1 faillure"$ENDCO
echo -e $B_RED"$TESTNAME faillure"$ENDCO
fi
mv $TESTNAME $TESTNAME.replace ./test_log
@@ -65,7 +66,7 @@ EOF
)
run_tests
# TEST 3 ########################################
# TEST 4 ########################################
TESTNAME="test4"
FIND=".."
REPLACEMENT="++"
@@ -81,3 +82,17 @@ EOF
)
run_tests
# TEST 5 ########################################
TESTNAME="test5"
FIND="mdr"
REPLACEMENT="|||"
CONTENT=$(cat << EOF
test de mmdr foubar
EOF
)
RESULT=$(cat << EOF
test de m||| foubar
EOF
)
run_tests
+1 -1
View File
@@ -1 +1 @@
hello
hello
+1 -1
View File
@@ -1 +1 @@
+
++++++++++++++++++++++++++++++++++++++++++++++++++++;
+1
View File
@@ -0,0 +1 @@
test de mmdr foubar
+1
View File
@@ -0,0 +1 @@
test de mmdr foubar