fixd edge case in jskeycodes & added html to tests

master
Dylan Lloyd 2012-05-21 20:04:36 -04:00
parent e9bc58bd65
commit 071dde7b95
2 changed files with 72 additions and 47 deletions

View File

@ -7,7 +7,7 @@ my $text;
my $key;
my $value;
triggers startend => 'keycode', 'keycodes', 'chars', 'charcode', 'charcodes';
triggers any => 'keycode', 'keycodes', 'char', 'chars', 'charcode', 'charcodes';
my %keys = ('backspace' => '8',
'tab' => '9',
@ -103,22 +103,26 @@ my %keys = ('backspace' => '8',
handle remainder => sub {
return unless exists $keys{$_}
or $_ eq "JavaScript"
or $_ eq "javascript"
or $_ eq "js";
my $header = share('header.txt')->slurp;
my $footer = share('footer.txt')->slurp;
my $query = lc($_);
return unless exists $keys{$query}
or $query =~ s/ *JavaScript *//
or $query =~ s/ *javascript *//
or $query =~ s/ *js *//;
$html .= $header;
$html .= '<tr><td class="c1"><b>' . $_ . '</b></td><td class="c2"><b>' . $keys{$_} . '</b></td>' if (exists $keys{$_});
$html .= share('header.txt')->slurp;
$html .= "\n<tr><td class='c1'><b>$query</b></td>"
. "\n<td class='c2'><b>$keys{$query}</b></td></tr>"
if exists $keys{$query};
foreach $key (sort keys %keys){
$html .= '<tr><td class="c1">' . $key . '</td><td class="c2">'. $keys{$key} . "</td></tr>" unless $key eq $_;
$html .= "\n<tr><td class='c1'>$key</td>"
. "\n<td class='c2'>$keys{$key}</td></tr>"
unless $key eq $query;
};
$html .= $footer;
$text = 'Keycode: ' . $keys{$_} . ' (JavaScript)' unless not exists $keys{$_} or $_ eq "JavaScript" or $_ eq "javascript";
$html .= share('footer.txt')->slurp;
$text = "Keycode for $query: $keys{$query} (JavaScript)"
unless not exists $keys{$query};
return $text, html => $html;
return;
};

View File

@ -12,41 +12,62 @@ ddg_goodie_test(
[qw(
DDG::Goodie::JsKeycodes
)],
'charCode backspace' => test_zci('Keycode: 8 (JavaScript)'),
'charcode tab' => test_zci('Keycode: 9 (JavaScript)'),
'keycode enter' => test_zci('Keycode: 13 (JavaScript)'),
'keyCode shift' => test_zci('Keycode: 16 (JavaScript)'),
'ctrl charcode' => test_zci('Keycode: 17 (JavaScript)'),
'alt charCode' => test_zci('Keycode: 18 (JavaScript)'),
'pause keycode' => test_zci('Keycode: 19 (JavaScript)'),
'break keyCode' => test_zci('Keycode: 19 (JavaScript)'),
'charCode 0' => test_zci('Keycode: 48 (JavaScript)'),,
'charCode 3' => test_zci('Keycode: 51 (JavaScript)'),
'6 charCode' => test_zci('Keycode: 54 (JavaScript)'),
'charcode 8' => test_zci('Keycode: 56 (JavaScript)'),
'a charCode' => test_zci('Keycode: 65 (JavaScript)'),
'charCode A' => test_zci('Keycode: 65 (JavaScript)'),
'charcode H' => test_zci('Keycode: 73 (JavaScript)'),
'charcode h' => test_zci('Keycode: 73 (JavaScript)'),
'p charcode' => test_zci('Keycode: 80 (JavaScript)'),
'charcode P' => test_zci('Keycode: 80 (JavaScript)'),
'charCode f1' => test_zci('Keycode: 112 (JavaScript)'),
'charcode f4' => test_zci('Keycode: 115 (JavaScript)'),
'f6 charCode' => test_zci('Keycode: 117 (JavaScript)'),
'f7 charcode' => test_zci('Keycode: 118 (JavaScript)'),
'f12 keycode' => test_zci('Keycode: 123 (JavaScript)'),
'numpad 1 keyCode' => test_zci('Keycode: 97 (JavaScript)'),
'charCode numpad 3' => test_zci('Keycode: 98 (JavaScript)'),
'keycode numpad 8' => test_zci('Keycode: 104 (JavaScript)'),
'charcode numpad 9' => test_zci('Keycode: 105 (JavaScript)'),
'charCode num lock' => test_zci('Keycode: 144 (JavaScript)'),
'scroll lock charcode ' => test_zci('Keycode: 145 (JavaScript)'),
'charcode ;' => test_zci('Keycode: 186 (JavaScript)'),
'keycode =' => test_zci('Keycode: 187 (JavaScript)'),
'keyCode \\' => test_zci('Keycode: 220 (JavaScript)'),
'charCode quote' => test_zci('Keycode: 222 (JavaScript)'),
'charcode (' => test_zci('Keycode: 219 (JavaScript)'),
') keycode' => test_zci('Keycode: 221 (JavaScript)'),
'js charCode backspace' => test_zci('Keycode for backspace: 8 (JavaScript)',
html => qr:<tr><td class='c1'><b>backspace</b></td>:),
'javascript charcode tab' => test_zci('Keycode for tab: 9 (JavaScript)',
html => qr:<tr><td class='c1'><b>tab</b></td>:),
'JavaScript keycode enter' => test_zci('Keycode for enter: 13 (JavaScript)',
html => qr:<tr><td class='c1'><b>enter</b></td>:),
'js keyCode shift' => test_zci('Keycode for shift: 16 (JavaScript)',
html => qr:<tr><td class='c1'><b>shift</b></td>:),
'js ctrl charcode' => test_zci('Keycode for ctrl: 17 (JavaScript)',
html => qr:<tr><td class='c1'><b>ctrl</b></td>:),
'js alt charCode' => test_zci('Keycode for alt: 18 (JavaScript)',
html => qr:<tr><td class='c1'><b>alt</b></td>:),
'js pause keycode' => test_zci('Keycode for pause: 19 (JavaScript)',
html => qr:<tr><td class='c1'><b>pause</b></td>:),
'js break keyCode' => test_zci('Keycode for break: 19 (JavaScript)',
html => qr:<tr><td class='c1'><b>break</b></td>:),
'js charCode 0' => test_zci('Keycode for 0: 48 (JavaScript)',
html => qr:<tr><td class='c1'><b>0</b></td>:),
'js charCode 3' => test_zci('Keycode for 3: 51 (JavaScript)',
html => qr:<tr><td class='c1'><b>3</b></td>:),
'js 6 charCode' => test_zci('Keycode for 6: 54 (JavaScript)',
html => qr:<tr><td class='c1'><b>6</b></td>:),
'js charcode 8' => test_zci('Keycode for 8: 56 (JavaScript)',
html => qr:<tr><td class='c1'><b>8</b></td>:),
'js a charCode' => test_zci('Keycode for a: 65 (JavaScript)',
html => qr:<tr><td class='c1'><b>a</b></td>:),
'js charCode A' => test_zci('Keycode for a: 65 (JavaScript)',
html => qr:<tr><td class='c1'><b>a</b></td>:),
'js charcode H' => test_zci('Keycode for h: 73 (JavaScript)',
html => qr:<tr><td class='c1'><b>h</b></td>:),
'js charcode h' => test_zci('Keycode for h: 73 (JavaScript)',
html => qr:<tr><td class='c1'><b>h</b></td>:),
'js p charcode' => test_zci('Keycode for p: 80 (JavaScript)',
html => qr:<tr><td class='c1'><b>p</b></td>:),
'js charcode P' => test_zci('Keycode for p: 80 (JavaScript)',
html => qr:<tr><td class='c1'><b>p</b></td>:),
'js charCode f1' => test_zci('Keycode for f1: 112 (JavaScript)',
html => qr:<tr><td class='c1'><b>f1</b></td>:),
'js charcode f4' => test_zci('Keycode for f4: 115 (JavaScript)',
html => qr:<tr><td class='c1'><b>f4</b></td>:),
'js numpad 1 keyCode' => test_zci('Keycode for numpad 1: 97 (JavaScript)',
html => qr:<tr><td class='c1'><b>numpad 1</b></td>:),
'js charCode num lock' => test_zci('Keycode for num lock: 144 (JavaScript)',
html => qr:<tr><td class='c1'><b>num lock</b></td>:),
'js scroll lock charcode ' => test_zci('Keycode for scroll lock: 145 (JavaScript)',
html => qr:<tr><td class='c1'><b>scroll lock</b></td>:),
'js charcode ;' => test_zci('Keycode for ;: 186 (JavaScript)',
html => qr:<tr><td class='c1'><b>;</b></td>:),
'js keycode =' => test_zci('Keycode for =: 187 (JavaScript)',
html => qr:<tr><td class='c1'><b>=</b></td>:),
'js keyCode \\' => test_zci('Keycode for \: 220 (JavaScript)',
html => qr:<tr><td class='c1'><b>\\</b></td>:),
'js charCode quote' => test_zci('Keycode for quote: 222 (JavaScript)',
html => qr:<tr><td class='c1'><b>quote</b></td>:),
'js charcode (' => test_zci('Keycode for (: 219 (JavaScript)',
html => qr:<tr><td class='c1'><b>\(</b></td>:),
);
done_testing;