-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pp
executable file
·140 lines (135 loc) · 2.19 KB
/
test_pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl
use strict;
use warnings;
use Pplight;
my @test_cases =
(
{ in => '', expect => '' },
{ in => <<'EOF'
const char *C = "/* this is not a C comment */"; /* but this is */
const char *Cplusplus = "In perl, // means \"defined-or\""; // ...
EOF
,
expect => <<'EOF'
const char *C = "/* this is not a C comment */";
const char *Cplusplus = "In perl, // means \"defined-or\"";
EOF
},
{ in => <<'EOF'
int x; /* comment /* do not nest */
int y; // so y is declared */
int z; /* Also, we cannot comment out end-of-comment // */
int w; /* so w is also declared */
EOF
,
expect => <<'EOF'
int x;
int y;
int z;
int w;
EOF
},
{ in => <<'EOF'
void bar(void) {
printf("Foo went into a %s.\n", __func__);
/* ... */
printf("\"Just put it on my \\
t\", said Foo.");
}
EOF
,
expect => <<'EOF'
void bar(void) {
printf("Foo went into a %s.\n", __func__);
printf("\"Just put it on my \t\", said Foo.");
}
EOF
},
{ in => "int missing_newline;",
expect => "int missing_newline;\n" },
{ in => <<'EOF'
#if 0
this
#ifdef foo
foo_stuff
#endif
#elif x
that
#endif
EOF
,
expect => <<'EOF'
#if x
that
#endif
EOF
},
{ in => <<'EOF'
#if /* not this */0
#elif /* nor this */0
#else // always this
#endif
EOF
,
expect => <<'EOF'
#if 1
#endif
EOF
},
{ in => <<'EOF'
int x;
#if 0
#endif
int y;
EOF
,
expect => "int x;\n\nint y;\n"
},
{ in => "#if 0\n#endif\n", expect => "\n" },
{ in => <<'EOF'
#if FOO
#elif 0
#elif 0
#elif BAR
#elif 0
#endif
EOF
,
expect => <<'EOF'
#if FOO
#elif BAR
#endif
EOF
},
{ in => <<'EOF'
#/* 1
*/if defined(ABC)
# /* 2 */ define X Y
#/*
3
*/else
# /*4*/define X Z
/*5*/ #endif // 6
EOF
,
expect => << 'EOF'
# if defined(ABC)
# define X Y
# else
# define X Z
#endif
EOF
},
);
for (my $i = 0; $i < @test_cases; ++$i) {
my $t = $test_cases[$i];
my $out = Pplight->string($t->{in}, $t->{opt});
if ("$out" ne $t->{expect}) {
printf "Test case %d failed:\n", $i;
printf "==== Expected ====\n";
print $t->{expect};
printf "==== Got ====\n";
print $out;
printf "==== ====\n";
}
}