aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/robertkrimen/otto/underscore/testify
blob: 7f6e0f7c1194299454d5841ca90ab0dd389f40ac (plain) (blame)
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
#!/usr/bin/env perl

use strict;
use warnings;

my $underscore_test = shift @ARGV || "";
if (!-d $underscore_test) {
    print <<_END_;
Usage:

    testify ./underscore/test

    # Should look something like:
    arrays.js
    chaining.js
    collections.js
    functions.js
    index.html
    objects.js
    speed.js
    utility.js
    vendor

_END_
    if ($underscore_test) {
        die "!: Not a directory: $underscore_test\n"
    }
    exit;
}

chdir $underscore_test or die "!: $!";

my @js = <*.js>;

for my $file (@js) {
    open my $fh, '<', $file or die "!: $!";
    my $tests = join "", <$fh>;
    my @tests = $tests =~ m/
        ^(\s{2}test\(.*?
        ^\s{2}}\);)$
    /mgxs;
    close $fh;
    next unless @tests;
    print "$file: ", scalar(@tests), "\n";
    my $underscore_name = "underscore_$file";
    $underscore_name =~ s/.js$//;
    my $go_file = "${underscore_name}_test.go";
    $go_file =~ s/.js$/.go/;
    open $fh, '>', $go_file or die "!: $!";

    $fh->print(<<_END_);
package otto

import (
    "testing"
)

_END_

    my $count = 0;
    for my $test (@tests) {
        $test =~ s/`([^`]+)`/<$1>/g;
        my ($name) = $test =~ m/^\s*test\(['"]([^'"]+)['"]/;
        $fh->print(<<_END_);
// $name
func Test_${underscore_name}_$count(t *testing.T) {
    tt(t, func(){
        test := underscoreTest()

        test(`
$test
        `)
    })
}

_END_
        $count++;
    }
}

#  test('#779 - delimeters are applied to unescaped text.', 1, function() {
#    var template = _.template('<<\nx\n>>', null, {evaluate: /<<(.*?)>>/g});
#    strictEqual(template(), '<<\nx\n>>');
#  });