#!./perl
=cut
BEGIN {
chdir 't' if -d 't';
}
### use Test::More;
# BRE extensions
0
111
1000
10001
[TheEnd]
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
[TheEnd]
#no autoprint
# This script should be run on itself
/^#__DATA__$/,${
/^#A$/p
s/^# *[0-9]* *//
/^#\*$/p
/^#\.$/p
/^#\(..\)\(..\)\2\1*$/p
/^#[abc]\{1,\}[def]\{1,\}$/p
}
#__DATA__
#A
#*
#.
#abxyxy
#abxyxyab
#abxyxyabab
#ad
#abcdef
[TheEnd]
);
### bin2dec ###
'bin2dec' => {
# binary -> decimal
s/^[ ]*\([01]\{1,\}\)[ ]*/\1/
t go
i\
d
# expand binary to Xs
: go
s/^0*//
s/^1/X/
: expand
s/^\(X\{1,\}\)0/\1\1/
s/^\(X\{1,\}\)1/\1\1X/
t expand
# count Xs in decimal
: count
s/^X/1/
s/0X/1/
s/1X/2/
s/2X/3/
s/3X/4/
s/4X/5/
s/5X/6/
s/6X/7/
s/7X/8/
s/8X/9/
t count
s/^$/0/
[TheEnd]
0
7
8
17
[TheEnd]
},
### = ###
'=' => {
1=
$=
[TheEnd]
1
line 1
line 2
line 3
line 4
line 5
line 6
line 7
8
line 8
[TheEnd]
},
### D ###
'D' => {
#no autoprint
/1/{
N
N
N
D
}
p
/2/D
=
p
[TheEnd]
line 2
line 3
line 4
line 3
line 4
4
line 3
line 4
line 5
5
line 5
line 6
6
line 6
line 7
7
line 7
line 8
8
line 8
[TheEnd]
},
### H ###
'H' => {
#no autoprint
1,$H
$g
$=
$p
[TheEnd]
8
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
[TheEnd]
},
### N ###
'N' => {
3a\
4a\
5a\
3,5N
=
d
[TheEnd]
1
2
4
6
7
8
[TheEnd]
},
### P ###
'P' => {
1N
2N
3N
4=
4P
4,$d
[TheEnd]
4
line 1
[TheEnd]
},
### a ###
'a' => {
1a\
3a\
3a\
[TheEnd]
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
[TheEnd]
},
### b ###
'b' => {
#no autoprint
2 b eos
4 b eos
p
: eos
[TheEnd]
line 1
line 3
line 5
line 6
line 7
line 8
[TheEnd]
},
### block ###
'block' => {
1
line 1
2
line 2
3
line 3
[TheEnd]
},
### c ###
'c' => {
2=
2,4c\
2=
3,5c\
3=
[TheEnd]
line 1
2
line 5
line 6
line 7
line 8
[TheEnd]
},
### c1 ###
'c1' => {
1c\
2,3c\
/5/,/6/c\
8,10c\
[TheEnd]
line 4
line 7
[TheEnd]
},
### c2 ###
'c2' => {
3!c\
[TheEnd]
line 3
[TheEnd]
},
### c3 ###
'c3' => {
1,4!c\
/5/,/8/!c\
[TheEnd]
[TheEnd]
},
### d ###
'd' => {
# d delete pattern space, start next cycle
2,4 d
5 d
[TheEnd]
line 1
line 6
line 7
line 8
[TheEnd]
},
### gh ###
'gh' => {
1h
2g
3h
4g
5q
[TheEnd]
line 1
line 1
line 3
line 3
line 5
[TheEnd]
},
### i ###
'i' => {
1i\
3i\
3i\
[TheEnd]
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
[TheEnd]
},
### n ###
'n' => {
3a\
4a\
5a\
3,5n
=
d
[TheEnd]
1
2
line 3
4
line 5
6
7
8
[TheEnd]
},
### o ###
'o' => {
// i\
[TheEnd]
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
[TheEnd]
},
### q ###
'q' => {
2a\
3a\
3q
[TheEnd]
line 1
line 2
line 3
[TheEnd]
},
### r ###
'r' => {
2r%r.txt%
4r %r.txt%
[TheEnd]
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
[TheEnd]
},
### s ###
's' => {
# enclose any `(a)'.. `(c)' in `-'
s/([a-z])/-\1-/g
s/\([abc]\)/-\1-/g
[TheEnd]
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
[TheEnd]
},
### s1 ###
's1' => {
s/\w/@1/
s/\y/@2/
s/\n/@3/
# this is literal { }
s/a{3}/@4/
# proper repetition
s/a\{3\}/a rep 3/
[TheEnd]
@1ine 1
@1ine 2
@1ine 3
@1ine 4
@1ine 5
@1ine 6
@1ine 7
@1ine 8
[TheEnd]
},
### t ###
't' => {
Xine 1
Xine 2
Xine 3
Xine 4
Xine 5
Xine 6
Xine 7
Xine 8
[TheEnd]
},
### w ###
'w' => {
w %w.txt%
[TheEnd]
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
[TheEnd]
},
### x ###
'x' => {
1h
1d
2x
2,$G
[TheEnd]
line 1
line 2
line 3
line 2
line 4
line 2
line 5
line 2
line 6
line 2
line 7
line 2
line 8
line 2
[TheEnd]
},
### y ###
'y' => {
y/|/\
/
[TheEnd]
LINE 1
LINE 2
LINE 3
LINE 4
LINE 5
LINE 6
LINE 7
LINE 8
[TheEnd]
},
### cnt ###
'cnt' => {
#no autoprint
# delete line, append NL to hold space
s/.*//
H
$!b
# last line only: get hold
g
s/./X/g
t count
: count
s/^X/1/
s/0X/1/
s/1X/2/
s/2X/3/
s/3X/4/
s/4X/5/
s/5X/6/
s/6X/7/
s/7X/8/
s/8X/9/
t count
p
[TheEnd]
8
[TheEnd]
},
### adr1 ###
'adr1' => {
#no autoprint
# This script should be run on itself
/^#__DATA__$/,${
/^#A$/p
s/^# *[0-9]* *//
/^#\*$/p
/^#\.$/p
/^#\(..\)\(..\)\2\1*$/p
/^#[abc]\{1,\}[def]\{1,\}$/p
}
#__DATA__
#A
#*
#.
#abxyxy
#abxyxyab
#abxyxyabab
#ad
#abcdef
[TheEnd]
#A
[TheEnd]
},
);
# temporary file names
# various command lines for
# default in the .com extenson if it's not already there
}
# psed: we create a local copy as linking may not work on some systems.
# process all testcases
#
# 1st test: run psed
# prepare the script
# additional files for r, w: patch script, inserting temporary names
}
# prepare input
#
}
# on VMS, runperl eats blank lines to work around
# spurious newlines in pipes
# run and compare
#
# 2nd test: run s2p
# translate the sed script to a Perl program
# execute generated Perl program, compare
next;
}
END {
}
}