| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
my $underscore_test = shift @ARGV || ""; |
| 7 |
if (!-d $underscore_test) { |
| 8 |
print <<_END_; |
| 9 |
Usage: |
| 10 |
|
| 11 |
testify ./underscore/test |
| 12 |
|
| 13 |
# Should look something like: |
| 14 |
arrays.js |
| 15 |
chaining.js |
| 16 |
collections.js |
| 17 |
functions.js |
| 18 |
index.html |
| 19 |
objects.js |
| 20 |
speed.js |
| 21 |
utility.js |
| 22 |
vendor |
| 23 |
|
| 24 |
_END_ |
| 25 |
if ($underscore_test) { |
| 26 |
die "!: Not a directory: $underscore_test\n" |
| 27 |
} |
| 28 |
exit; |
| 29 |
} |
| 30 |
|
| 31 |
chdir $underscore_test or die "!: $!"; |
| 32 |
|
| 33 |
my @js = <*.js>; |
| 34 |
|
| 35 |
for my $file (@js) { |
| 36 |
open my $fh, '<', $file or die "!: $!"; |
| 37 |
my $tests = join "", <$fh>; |
| 38 |
my @tests = $tests =~ m/ |
| 39 |
^(\s{2}test\(.*? |
| 40 |
^\s{2}}\);)$ |
| 41 |
/mgxs; |
| 42 |
close $fh; |
| 43 |
next unless @tests; |
| 44 |
print "$file: ", scalar(@tests), "\n"; |
| 45 |
my $underscore_name = "underscore_$file"; |
| 46 |
$underscore_name =~ s/.js$//; |
| 47 |
my $go_file = "${underscore_name}_test.go"; |
| 48 |
$go_file =~ s/.js$/.go/; |
| 49 |
open $fh, '>', $go_file or die "!: $!"; |
| 50 |
|
| 51 |
$fh->print(<<_END_); |
| 52 |
package otto |
| 53 |
|
| 54 |
import ( |
| 55 |
"testing" |
| 56 |
) |
| 57 |
|
| 58 |
_END_ |
| 59 |
|
| 60 |
my $count = 0; |
| 61 |
for my $test (@tests) { |
| 62 |
$test =~ s/`([^`]+)`/<$1>/g; |
| 63 |
my ($name) = $test =~ m/^\s*test\(['"]([^'"]+)['"]/; |
| 64 |
$fh->print(<<_END_); |
| 65 |
// $name |
| 66 |
func Test_${underscore_name}_$count(t *testing.T) { |
| 67 |
tt(t, func(){ |
| 68 |
test := underscoreTest() |
| 69 |
|
| 70 |
test(` |
| 71 |
$test |
| 72 |
`) |
| 73 |
}) |
| 74 |
} |
| 75 |
|
| 76 |
_END_ |
| 77 |
$count++; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
# test('#779 - delimeters are applied to unescaped text.', 1, function() { |
| 82 |
# var template = _.template('<<\nx\n>>', null, {evaluate: /<<(.*?)>>/g}); |
| 83 |
# strictEqual(template(), '<<\nx\n>>'); |
| 84 |
# }); |