RedCloth 4.1.9-universal-java → 4.2.0-universal-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of RedCloth might be problematic. Click here for more details.
- data/CHANGELOG +55 -0
- data/Manifest +34 -38
- data/README +17 -5
- data/Rakefile +79 -30
- data/RedCloth.gemspec +8 -9
- data/ext/redcloth_scan/redcloth.h +38 -13
- data/lib/redcloth.rb +9 -3
- data/lib/redcloth/formatters/html.rb +2 -2
- data/lib/redcloth/formatters/latex.rb +99 -54
- data/lib/redcloth/formatters/latex_entities.yml +2 -2
- data/lib/redcloth/version.rb +9 -4
- data/lib/redcloth_scan.jar +0 -0
- data/lib/tasks/pureruby.rake +12 -0
- data/spec/custom_tags_spec.rb +50 -0
- data/spec/differs/inline.rb +48 -0
- data/{test/test_erb.rb → spec/erb_spec.rb} +6 -9
- data/spec/extension_spec.rb +26 -0
- data/{test → spec/fixtures}/basic.yml +90 -4
- data/{test → spec/fixtures}/code.yml +29 -0
- data/{test → spec/fixtures}/definitions.yml +0 -0
- data/{test → spec/fixtures}/extra_whitespace.yml +0 -0
- data/{test → spec/fixtures}/filter_html.yml +0 -0
- data/{test → spec/fixtures}/filter_pba.yml +0 -0
- data/{test → spec/fixtures}/html.yml +15 -0
- data/{test → spec/fixtures}/images.yml +16 -6
- data/{test → spec/fixtures}/instiki.yml +0 -0
- data/{test → spec/fixtures}/links.yml +7 -1
- data/{test → spec/fixtures}/lists.yml +162 -1
- data/{test → spec/fixtures}/poignant.yml +0 -0
- data/{test → spec/fixtures}/sanitize_html.yml +0 -0
- data/{test → spec/fixtures}/table.yml +121 -23
- data/{test → spec/fixtures}/textism.yml +44 -15
- data/{test → spec/fixtures}/threshold.yml +6 -14
- data/spec/formatters/class_filtered_html_spec.rb +7 -0
- data/spec/formatters/filtered_html_spec.rb +7 -0
- data/spec/formatters/html_no_breaks_spec.rb +9 -0
- data/spec/formatters/html_spec.rb +13 -0
- data/spec/formatters/id_filtered_html_spec.rb +7 -0
- data/spec/formatters/latex_spec.rb +13 -0
- data/spec/formatters/lite_mode_html_spec.rb +7 -0
- data/spec/formatters/no_span_caps_html_spec.rb +7 -0
- data/spec/formatters/sanitized_html_spec.rb +7 -0
- data/spec/formatters/style_filtered_html_spec.rb +7 -0
- data/spec/parser_spec.rb +95 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +42 -0
- metadata +46 -51
- data/ext/mingw-rbconfig.rb +0 -176
- data/ext/redcloth_scan/redcloth_attributes.c.rl +0 -55
- data/ext/redcloth_scan/redcloth_attributes.java.rl +0 -95
- data/ext/redcloth_scan/redcloth_attributes.rl +0 -33
- data/ext/redcloth_scan/redcloth_common.c.rl +0 -18
- data/ext/redcloth_scan/redcloth_common.java.rl +0 -18
- data/ext/redcloth_scan/redcloth_common.rl +0 -115
- data/ext/redcloth_scan/redcloth_inline.c.rl +0 -193
- data/ext/redcloth_scan/redcloth_inline.java.rl +0 -140
- data/ext/redcloth_scan/redcloth_inline.rl +0 -156
- data/ext/redcloth_scan/redcloth_scan.c.rl +0 -228
- data/ext/redcloth_scan/redcloth_scan.java.rl +0 -577
- data/ext/redcloth_scan/redcloth_scan.rl +0 -320
- data/extras/ragel_profiler.rb +0 -73
- data/test/helper.rb +0 -108
- data/test/test_custom_tags.rb +0 -58
- data/test/test_extensions.rb +0 -31
- data/test/test_formatters.rb +0 -24
- data/test/test_parser.rb +0 -73
- data/test/test_restrictions.rb +0 -41
- data/test/validate_fixtures.rb +0 -74
@@ -1,320 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* redcloth_scan.rl
|
3
|
-
*
|
4
|
-
* Copyright (C) 2009 Jason Garber
|
5
|
-
*/
|
6
|
-
%%{
|
7
|
-
|
8
|
-
machine redcloth_scan;
|
9
|
-
|
10
|
-
# blocks
|
11
|
-
notextile_tag = notextile (LF | EOF) ;
|
12
|
-
noparagraph_line_start = " "+ ;
|
13
|
-
notextile_block_start = ( "notextile" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
|
14
|
-
pre_tag_start = "<pre" [^>]* ">" (space* code_tag_start)? ;
|
15
|
-
pre_tag_end = (code_tag_end space*)? "</pre>" LF? ;
|
16
|
-
pre_block_start = ( "pre" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
|
17
|
-
bc_start = ( "bc" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
|
18
|
-
bq_start = ( "bq" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) ( ":" %A uri %{ STORE("cite"); } )? " "+ ) ;
|
19
|
-
non_ac_btype = ( "bq" | "bc" | "pre" | "notextile" );
|
20
|
-
btype = (alpha alnum*) -- (non_ac_btype | "fn" digit+);
|
21
|
-
block_start = ( btype >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) >B %{ STORE_B("fallback"); };
|
22
|
-
all_btypes = btype | non_ac_btype;
|
23
|
-
next_block_start = ( all_btypes A_noactions C_noactions :> "."+ " " ) >A @{ p = reg - 1; } ;
|
24
|
-
double_return = LF{2,} ;
|
25
|
-
block_end = ( double_return | EOF );
|
26
|
-
ftype = ( "fn" >A %{ STORE("type"); } digit+ >A %{ STORE("id"); } ) ;
|
27
|
-
footnote_start = ( ftype A C :> dotspace ) ;
|
28
|
-
ul = "*" %{nest++; list_type = "ul";};
|
29
|
-
ol = "#" %{nest++; list_type = "ol";};
|
30
|
-
ul_start = ( ul | ol )* ul A C :> " "+ ;
|
31
|
-
ol_start = ( ul | ol )* ol N A C :> " "+ ;
|
32
|
-
list_start = " "* ( ul_start | ol_start ) >{nest = 0;} ;
|
33
|
-
dt_start = "-" . " "+ ;
|
34
|
-
dd_start = ":=" ;
|
35
|
-
long_dd = dd_start " "* LF %{ ADD_BLOCK(); ASET("type", "dd"); } any+ >A %{ TRANSFORM("text"); } :>> "=:" ;
|
36
|
-
dl_start = (dt_start mtext (LF dt_start mtext)* " "* dd_start) ;
|
37
|
-
blank_line = LF;
|
38
|
-
link_alias = ( "[" >{ ASET("type", "ignore"); } %A chars %T "]" %A uri %{ STORE_URL("href"); } ) ;
|
39
|
-
horizontal_rule = '*'{3,} | '-'{3,} | '_'{3,} ;
|
40
|
-
|
41
|
-
# image lookahead
|
42
|
-
IMG_A_LEFT = "<" %{ ASET("float", "left"); } ;
|
43
|
-
IMG_A_RIGHT = ">" %{ ASET("float", "right"); } ;
|
44
|
-
aligned_image = ( "["? "!" (IMG_A_LEFT | IMG_A_RIGHT) ) >A @{ p = reg - 1; } ;
|
45
|
-
|
46
|
-
# html blocks
|
47
|
-
BlockTagName = Name - ("pre" | "notextile" | "a" | "applet" | "basefont" | "bdo" | "br" | "font" | "iframe" | "img" | "map" | "object" | "param" | "embed" | "q" | "script" | "span" | "sub" | "sup" | "abbr" | "acronym" | "cite" | "code" | "del" | "dfn" | "em" | "ins" | "kbd" | "samp" | "strong" | "var" | "b" | "big" | "i" | "s" | "small" | "strike" | "tt" | "u");
|
48
|
-
block_start_tag = "<" BlockTagName space+ AttrSet* (AttrEnd)? ">" | "<" BlockTagName ">";
|
49
|
-
block_empty_tag = "<" BlockTagName space+ AttrSet* (AttrEnd)? "/>" | "<" BlockTagName "/>" ;
|
50
|
-
block_end_tag = "</" BlockTagName space* ">" ;
|
51
|
-
html_start = indent >B %{STORE_B("indent_before_start");} block_start_tag >B %{STORE_B("start_tag");} indent >B %{STORE_B("indent_after_start");} ;
|
52
|
-
html_end = indent >B %{STORE_B("indent_before_end");} block_end_tag >B %{STORE_B("end_tag");} (indent LF?) >B %{STORE_B("indent_after_end");} ;
|
53
|
-
standalone_html = indent (block_start_tag | block_empty_tag | block_end_tag) indent (LF+ | EOF);
|
54
|
-
html_end_terminating_block = ( LF indent block_end_tag ) >A @{ p = reg - 1; } ;
|
55
|
-
|
56
|
-
# tables
|
57
|
-
para = ( default+ ) -- LF ;
|
58
|
-
btext = para ( LF{2} )? ;
|
59
|
-
tddef = ( D? S A C :> dotspace ) ;
|
60
|
-
td = ( tddef? btext >A %T :> "|" >{PASS(table, "text", "td");} ) >X ;
|
61
|
-
trdef = ( A C :> dotspace ) ;
|
62
|
-
tr = ( trdef? "|" %{INLINE(table, "tr_open");} td+ ) >X %{INLINE(table, "tr_close");} ;
|
63
|
-
trows = ( tr (LF >X tr)* ) ;
|
64
|
-
tdef = ( "table" >X A C :> dotspace LF ) ;
|
65
|
-
table = ( tdef? trows >{CLEAR(table); INLINE(table, "table_open"); RESET_REG();} ) ;
|
66
|
-
|
67
|
-
# info
|
68
|
-
redcloth_version = ("RedCloth" >A ("::" | " " ) "VERSION"i ":"? " ")? %{STORE("prefix");} "RedCloth::VERSION" (LF* EOF | double_return) ;
|
69
|
-
|
70
|
-
pre_tag := |*
|
71
|
-
pre_tag_end { CAT(block); DONE(block); fgoto main; };
|
72
|
-
default => esc_pre;
|
73
|
-
*|;
|
74
|
-
|
75
|
-
pre_block := |*
|
76
|
-
EOF {
|
77
|
-
ADD_BLOCKCODE();
|
78
|
-
fgoto main;
|
79
|
-
};
|
80
|
-
double_return {
|
81
|
-
if (IS_NOT_EXTENDED()) {
|
82
|
-
ADD_BLOCKCODE();
|
83
|
-
fgoto main;
|
84
|
-
} else {
|
85
|
-
ADD_EXTENDED_BLOCKCODE();
|
86
|
-
}
|
87
|
-
};
|
88
|
-
double_return next_block_start {
|
89
|
-
if (IS_NOT_EXTENDED()) {
|
90
|
-
ADD_BLOCKCODE();
|
91
|
-
fgoto main;
|
92
|
-
} else {
|
93
|
-
ADD_EXTENDED_BLOCKCODE();
|
94
|
-
END_EXTENDED();
|
95
|
-
fgoto main;
|
96
|
-
}
|
97
|
-
};
|
98
|
-
default => esc_pre;
|
99
|
-
*|;
|
100
|
-
|
101
|
-
script_tag := |*
|
102
|
-
script_tag_end { CAT(block); ASET("type", "ignore"); ADD_BLOCK(); fgoto main; };
|
103
|
-
EOF { ASET("type", "ignore"); ADD_BLOCK(); fgoto main; };
|
104
|
-
default => cat;
|
105
|
-
*|;
|
106
|
-
|
107
|
-
noparagraph_line := |*
|
108
|
-
LF { ADD_BLOCK(); fgoto main; };
|
109
|
-
default => cat;
|
110
|
-
*|;
|
111
|
-
|
112
|
-
notextile_block := |*
|
113
|
-
EOF {
|
114
|
-
ADD_BLOCK();
|
115
|
-
fgoto main;
|
116
|
-
};
|
117
|
-
double_return {
|
118
|
-
if (IS_NOT_EXTENDED()) {
|
119
|
-
ADD_BLOCK();
|
120
|
-
CAT(html);
|
121
|
-
fgoto main;
|
122
|
-
} else {
|
123
|
-
CAT(block);
|
124
|
-
ADD_EXTENDED_BLOCK();
|
125
|
-
CAT(html);
|
126
|
-
}
|
127
|
-
};
|
128
|
-
double_return next_block_start {
|
129
|
-
if (IS_NOT_EXTENDED()) {
|
130
|
-
ADD_BLOCK();
|
131
|
-
CAT(html);
|
132
|
-
fgoto main;
|
133
|
-
} else {
|
134
|
-
CAT(block);
|
135
|
-
ADD_EXTENDED_BLOCK();
|
136
|
-
END_EXTENDED();
|
137
|
-
fgoto main;
|
138
|
-
}
|
139
|
-
};
|
140
|
-
default => cat;
|
141
|
-
*|;
|
142
|
-
|
143
|
-
html := |*
|
144
|
-
html_end { ADD_BLOCK(); fgoto main; };
|
145
|
-
default => cat;
|
146
|
-
*|;
|
147
|
-
|
148
|
-
bc := |*
|
149
|
-
EOF {
|
150
|
-
ADD_BLOCKCODE();
|
151
|
-
INLINE(html, "bc_close");
|
152
|
-
SET_PLAIN_BLOCK("p");
|
153
|
-
fgoto main;
|
154
|
-
};
|
155
|
-
double_return {
|
156
|
-
if (IS_NOT_EXTENDED()) {
|
157
|
-
ADD_BLOCKCODE();
|
158
|
-
INLINE(html, "bc_close");
|
159
|
-
SET_PLAIN_BLOCK("p");
|
160
|
-
fgoto main;
|
161
|
-
} else {
|
162
|
-
ADD_EXTENDED_BLOCKCODE();
|
163
|
-
CAT(html);
|
164
|
-
}
|
165
|
-
};
|
166
|
-
double_return next_block_start {
|
167
|
-
if (IS_NOT_EXTENDED()) {
|
168
|
-
ADD_BLOCKCODE();
|
169
|
-
INLINE(html, "bc_close");
|
170
|
-
SET_PLAIN_BLOCK("p");
|
171
|
-
fgoto main;
|
172
|
-
} else {
|
173
|
-
ADD_EXTENDED_BLOCKCODE();
|
174
|
-
CAT(html);
|
175
|
-
RSTRIP_BANG(html);
|
176
|
-
INLINE(html, "bc_close");
|
177
|
-
SET_PLAIN_BLOCK("p");
|
178
|
-
END_EXTENDED();
|
179
|
-
fgoto main;
|
180
|
-
}
|
181
|
-
};
|
182
|
-
default => esc_pre;
|
183
|
-
*|;
|
184
|
-
|
185
|
-
bq := |*
|
186
|
-
EOF {
|
187
|
-
ADD_BLOCK();
|
188
|
-
INLINE(html, "bq_close");
|
189
|
-
fgoto main;
|
190
|
-
};
|
191
|
-
double_return {
|
192
|
-
if (IS_NOT_EXTENDED()) {
|
193
|
-
ADD_BLOCK();
|
194
|
-
INLINE(html, "bq_close");
|
195
|
-
fgoto main;
|
196
|
-
} else {
|
197
|
-
ADD_EXTENDED_BLOCK();
|
198
|
-
}
|
199
|
-
};
|
200
|
-
double_return next_block_start {
|
201
|
-
if (IS_NOT_EXTENDED()) {
|
202
|
-
ADD_BLOCK();
|
203
|
-
INLINE(html, "bq_close");
|
204
|
-
fgoto main;
|
205
|
-
} else {
|
206
|
-
ADD_EXTENDED_BLOCK();
|
207
|
-
INLINE(html, "bq_close");
|
208
|
-
END_EXTENDED();
|
209
|
-
fgoto main;
|
210
|
-
}
|
211
|
-
};
|
212
|
-
html_end_terminating_block {
|
213
|
-
if (IS_NOT_EXTENDED()) {
|
214
|
-
ADD_BLOCK();
|
215
|
-
INLINE(html, "bq_close");
|
216
|
-
fgoto main;
|
217
|
-
} else {
|
218
|
-
ADD_EXTENDED_BLOCK();
|
219
|
-
INLINE(html, "bq_close");
|
220
|
-
END_EXTENDED();
|
221
|
-
fgoto main;
|
222
|
-
}
|
223
|
-
};
|
224
|
-
default => cat;
|
225
|
-
*|;
|
226
|
-
|
227
|
-
block := |*
|
228
|
-
EOF {
|
229
|
-
ADD_BLOCK();
|
230
|
-
fgoto main;
|
231
|
-
};
|
232
|
-
double_return {
|
233
|
-
if (IS_NOT_EXTENDED()) {
|
234
|
-
ADD_BLOCK();
|
235
|
-
fgoto main;
|
236
|
-
} else {
|
237
|
-
ADD_EXTENDED_BLOCK();
|
238
|
-
}
|
239
|
-
};
|
240
|
-
double_return next_block_start {
|
241
|
-
if (IS_NOT_EXTENDED()) {
|
242
|
-
ADD_BLOCK();
|
243
|
-
fgoto main;
|
244
|
-
} else {
|
245
|
-
ADD_EXTENDED_BLOCK();
|
246
|
-
END_EXTENDED();
|
247
|
-
fgoto main;
|
248
|
-
}
|
249
|
-
};
|
250
|
-
html_end_terminating_block {
|
251
|
-
if (IS_NOT_EXTENDED()) {
|
252
|
-
ADD_BLOCK();
|
253
|
-
fgoto main;
|
254
|
-
} else {
|
255
|
-
ADD_EXTENDED_BLOCK();
|
256
|
-
END_EXTENDED();
|
257
|
-
fgoto main;
|
258
|
-
}
|
259
|
-
};
|
260
|
-
LF list_start {
|
261
|
-
ADD_BLOCK();
|
262
|
-
CLEAR_LIST();
|
263
|
-
LIST_ITEM();
|
264
|
-
fgoto list;
|
265
|
-
};
|
266
|
-
|
267
|
-
default => cat;
|
268
|
-
*|;
|
269
|
-
|
270
|
-
footnote := |*
|
271
|
-
block_end { ADD_BLOCK(); fgoto main; };
|
272
|
-
default => cat;
|
273
|
-
*|;
|
274
|
-
|
275
|
-
list := |*
|
276
|
-
LF list_start { ADD_BLOCK(); LIST_ITEM(); };
|
277
|
-
block_end { ADD_BLOCK(); nest = 0; LIST_CLOSE(); fgoto main; };
|
278
|
-
default => cat;
|
279
|
-
*|;
|
280
|
-
|
281
|
-
dl := |*
|
282
|
-
LF dt_start { ADD_BLOCK(); ASET("type", "dt"); };
|
283
|
-
dd_start { ADD_BLOCK(); ASET("type", "dd"); };
|
284
|
-
long_dd { INLINE(html, "dd"); CLEAR_REGS(); };
|
285
|
-
block_end { ADD_BLOCK(); INLINE(html, "dl_close"); fgoto main; };
|
286
|
-
default => cat;
|
287
|
-
*|;
|
288
|
-
|
289
|
-
main := |*
|
290
|
-
noparagraph_line_start { ASET("type", "ignored_line"); fgoto noparagraph_line; };
|
291
|
-
notextile_tag { INLINE(block, "notextile"); };
|
292
|
-
notextile_block_start { ASET("type", "notextile"); fgoto notextile_block; };
|
293
|
-
script_tag_start { CAT(block); fgoto script_tag; };
|
294
|
-
pre_tag_start { ASET("type", "notextile"); CAT(block); fgoto pre_tag; };
|
295
|
-
pre_block_start { fgoto pre_block; };
|
296
|
-
standalone_html { ASET("type", "html"); CAT(block); ADD_BLOCK(); };
|
297
|
-
html_start { ASET("type", "html_block"); fgoto html; };
|
298
|
-
bc_start { INLINE(html, "bc_open"); ASET("type", "code"); SET_PLAIN_BLOCK("code"); fgoto bc; };
|
299
|
-
bq_start { INLINE(html, "bq_open"); ASET("type", "p"); fgoto bq; };
|
300
|
-
block_start { fgoto block; };
|
301
|
-
footnote_start { fgoto footnote; };
|
302
|
-
horizontal_rule { INLINE(html, "hr"); };
|
303
|
-
list_start { CLEAR_LIST(); LIST_ITEM(); fgoto list; };
|
304
|
-
dl_start { p = ts; INLINE(html, "dl_open"); ASET("type", "dt"); fgoto dl; };
|
305
|
-
table { INLINE(table, "table_close"); DONE(table); fgoto block; };
|
306
|
-
link_alias { STORE_LINK_ALIAS(); DONE(block); };
|
307
|
-
aligned_image { RESET_TYPE(); fgoto block; };
|
308
|
-
redcloth_version { INLINE(html, "redcloth_version"); };
|
309
|
-
blank_line => cat;
|
310
|
-
default
|
311
|
-
{
|
312
|
-
CLEAR_REGS();
|
313
|
-
RESET_TYPE();
|
314
|
-
CAT(block);
|
315
|
-
fgoto block;
|
316
|
-
};
|
317
|
-
EOF;
|
318
|
-
*|;
|
319
|
-
|
320
|
-
}%%;
|
data/extras/ragel_profiler.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
class RagelProfiler
|
2
|
-
MEM_CONVERSION = 1024
|
3
|
-
|
4
|
-
COMMANDS = { :compile => %w(ragel rlgen-cd gcc-4.0 gnumake cc1),
|
5
|
-
:test => %w(ruby) }
|
6
|
-
|
7
|
-
FIELDS = %w(compile_time compile_max_rss test_time test_max_rss ext_so_size)
|
8
|
-
|
9
|
-
@@results = {}
|
10
|
-
|
11
|
-
def initialize(name)
|
12
|
-
@name = name
|
13
|
-
@@results[name] = []
|
14
|
-
end
|
15
|
-
|
16
|
-
def measure(type)
|
17
|
-
raise "not a valid type" unless COMMANDS.keys.include?(type)
|
18
|
-
regex = COMMANDS[type].map {|c| Regexp.escape(c) }.join("|")
|
19
|
-
t = Thread.new do
|
20
|
-
Thread.current[:max] = 0
|
21
|
-
loop do
|
22
|
-
Thread.current[:max] = [run(regex), Thread.current[:max]].max
|
23
|
-
sleep 0.5
|
24
|
-
end
|
25
|
-
end
|
26
|
-
begin_time = Time.now
|
27
|
-
yield
|
28
|
-
total_time = Time.now - begin_time
|
29
|
-
|
30
|
-
t.kill
|
31
|
-
store_result(type, "time", total_time)
|
32
|
-
store_result(type, "max_rss", t[:max])
|
33
|
-
end
|
34
|
-
|
35
|
-
def ext_size(ext_so)
|
36
|
-
store_result(:ext_so, "size", File.size(ext_so) / MEM_CONVERSION)
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.results
|
40
|
-
out = []
|
41
|
-
out << "name\t" + FIELDS.join("\t")
|
42
|
-
@@results.each do |name, results|
|
43
|
-
out << [name, results ].flatten.join("\t")
|
44
|
-
end
|
45
|
-
out.join("\n")
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def store_result(type, metric, value)
|
51
|
-
index = FIELDS.index("#{type.to_s}_#{metric}")
|
52
|
-
@@results[@name][index] = "%.2f" % value
|
53
|
-
end
|
54
|
-
|
55
|
-
def run(ps_regex)
|
56
|
-
ps_command = "ps axucww"
|
57
|
-
ps_output = `#{ps_command}`
|
58
|
-
fields = ps_output.to_a.first.downcase.split
|
59
|
-
memory_index = fields.index("rss")
|
60
|
-
pid_index = fields.index("pid")
|
61
|
-
ppid_index = fields.index("ppid")
|
62
|
-
total = ps_output.grep(/(#{ps_regex})\s+$/i).map do |com|
|
63
|
-
Float(com.split[memory_index]).abs
|
64
|
-
end.inject(0) { |s,v| s += v }
|
65
|
-
if total
|
66
|
-
return total/MEM_CONVERSION
|
67
|
-
else
|
68
|
-
STDERR.puts "Command not found. No processes found matching #{ps_regex}."
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
$:.unshift File.dirname(__FILE__) + "/../lib"
|
3
|
-
require 'redcloth'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
module Test
|
7
|
-
module Unit
|
8
|
-
|
9
|
-
class TestCase
|
10
|
-
def self.generate_formatter_tests(formatter, &block)
|
11
|
-
define_method("format_as_#{formatter}", &block)
|
12
|
-
|
13
|
-
fixtures.each do |name, doc|
|
14
|
-
if doc[formatter]
|
15
|
-
define_method("test_#{formatter}_#{name}") do
|
16
|
-
output = method("format_as_#{formatter}").call(doc)
|
17
|
-
assert_equal doc[formatter], output
|
18
|
-
end
|
19
|
-
else
|
20
|
-
define_method("test_#{formatter}_#{name}_raises_nothing") do
|
21
|
-
assert_nothing_raised(Exception) { method("format_as_#{formatter}").call(doc) }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.fixtures
|
28
|
-
return @fixtures if @fixtures
|
29
|
-
@fixtures = {}
|
30
|
-
Dir[File.join(File.dirname(__FILE__), "*.yml")].each do |testfile|
|
31
|
-
testgroup = File.basename(testfile, '.yml')
|
32
|
-
num = 0
|
33
|
-
YAML::load_documents(File.open(testfile)) do |doc|
|
34
|
-
name = doc['name'] ? doc['name'].downcase.gsub(/[- ]/, '_') : num
|
35
|
-
@fixtures["#{testgroup}_#{name}"] = doc
|
36
|
-
num += 1
|
37
|
-
end
|
38
|
-
end
|
39
|
-
@fixtures
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
module Assertions
|
45
|
-
# Browsers ignore tabs and newlines (generally), so don't quibble
|
46
|
-
def assert_html_equal(expected, actual, message=nil)
|
47
|
-
assert_equal(expected.gsub(/[\n\t]+/, ''), actual.gsub(/[\n\t]+/, ''), message)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Colorize differences in assert_equal failure messages.
|
54
|
-
begin
|
55
|
-
require 'rubygems'
|
56
|
-
require 'diff/lcs'
|
57
|
-
require 'test/unit'
|
58
|
-
|
59
|
-
DIFF_COLOR = "\e[7m" unless defined?(DIFF_COLOR)
|
60
|
-
DEFAULT_COLOR = "\e[0m" unless defined?(DEFAULT_COLOR)
|
61
|
-
|
62
|
-
def highlight_differences(a, b)
|
63
|
-
sdiff = Diff::LCS.sdiff(a, b, Diff::LCS::ContextDiffCallbacks)
|
64
|
-
return highlight_string(sdiff, :old, a), highlight_string(sdiff, :new, b)
|
65
|
-
end
|
66
|
-
|
67
|
-
def highlight_string(sdiff, pos, s)
|
68
|
-
s = s.dup
|
69
|
-
offset = 0
|
70
|
-
sdiff.each do |hunk|
|
71
|
-
if hunk.first.send("#{pos}_element")
|
72
|
-
s.insert(hunk.first.send("#{pos}_position") + offset, DIFF_COLOR)
|
73
|
-
offset += DIFF_COLOR.length
|
74
|
-
end
|
75
|
-
if hunk.last.send("#{pos}_element")
|
76
|
-
s.insert(hunk.last.send("#{pos}_position") + 1 + offset, DEFAULT_COLOR)
|
77
|
-
offset += DEFAULT_COLOR.length
|
78
|
-
end
|
79
|
-
end
|
80
|
-
s = DEFAULT_COLOR + s + DEFAULT_COLOR
|
81
|
-
end
|
82
|
-
|
83
|
-
module Test::Unit::Assertions
|
84
|
-
# Show differences in expected and actual
|
85
|
-
def assert_equal(expected, actual, message=nil)
|
86
|
-
full_message = build_message(message, <<EOT, *highlight_differences(expected, actual))
|
87
|
-
expected: ?
|
88
|
-
but was: ?
|
89
|
-
EOT
|
90
|
-
assert_block(full_message) { expected == actual }
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
|
95
|
-
module ShowColorCodes
|
96
|
-
def self.included(base)
|
97
|
-
base.class_eval do
|
98
|
-
alias_method :result_without_color_codes, :result unless method_defined?(:result_without_color_codes)
|
99
|
-
alias_method :result, :result_with_color_codes
|
100
|
-
end
|
101
|
-
end
|
102
|
-
def result_with_color_codes(parameters)
|
103
|
-
result_without_color_codes(parameters.collect {|p| p.gsub(/\\e\[(\d+)m/) {"\e[#{$1}m"} })
|
104
|
-
end
|
105
|
-
end
|
106
|
-
Test::Unit::Assertions::AssertionMessage::Template.send(:include, ShowColorCodes)
|
107
|
-
rescue LoadError
|
108
|
-
end
|