Skip to content

Commit

Permalink
Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsu committed Mar 26, 2010
1 parent d26f3bd commit 2a7cd6b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
2 changes: 2 additions & 0 deletions config/js2.yml
@@ -0,0 +1,2 @@
js2_dir: './test/fixtures'
out_dir: './test/out'
23 changes: 14 additions & 9 deletions lib/js2/standard/factory.rb
Expand Up @@ -82,7 +82,7 @@ def createName

class JS2::Standard::PrivateNode < JS2::Standard::Node
def handle_first_string (str)
return first.sub(/private/m, '// private')
return str.sub(/private/m, '// private')
end
end

Expand All @@ -102,15 +102,16 @@ def handle_first_string (s)
s = s.sub(/static\s*/, '')
end

return s.sub(/var\s*([\$\w]+)/) { "K.oo('#{method}', '" + $1 + "'" }.sub(/;$/, ');').sub(/\s*=/, ', ');
return s.sub(/var\s*([\$\w]+)/) { "K.oo('#{method}', '" + $1 + "'" }.sub(/;(\s*)$/) { ");#{$1}" }.sub(/\s*=/, ', ');
end

end

class JS2::Standard::CurryNode < JS2::Standard::Node
REGEX = %r|^curry\s*([^\{]*)?\{(.*)$|m
REGEX_WITH = %r|with\s+\(([^)]*)\)|
REGEX_ARGS = %r|^\s*\(([^)]*)\)|
REGEX = %r|^curry\s*([^\{]*)?\{(.*)$|m
REGEX_WITH = %r|with\s+\(([^)]*)\)|
REGEX_ARGS = %r|^\s*\(([^)]*)\)|
REGEX_ENDING = %r|}([^}]*)\z|

def handle_first_string (str)
m = str.match(REGEX)
Expand Down Expand Up @@ -138,7 +139,11 @@ def handle_first_string (str)
end

def handle_ending (str)
return %|#{str}})(#{@in_scoped})|
if m = str.match(REGEX_ENDING)
return str.sub(REGEX_ENDING) { |str| "}})(#{@in_scoped})#{m[1]}" }
end

return str
end
end

Expand Down Expand Up @@ -220,8 +225,8 @@ def self.reset!

class JS2::Standard::PropertyNode < JS2::Standard::Node
REGEX = /(\s*)property(\s+)([\w+,\s]+\w)(\s*);(\s*)/
def setup!
m = first.match(REGEX)
def handle_first_string (s)
m = s.match(REGEX)
space = m[1]
mid_space = m[2]
list = m[3].split(/,/).collect { |i| i.strip }
Expand All @@ -240,7 +245,7 @@ class JS2::Standard::StuffNode < JS2::Standard::Node
class JS2::Standard::Factory
attr_accessor :decorators

@@supports = [ :CLASS, :MEMBER, :METHOD, :ACCESSOR, :FOREACH, :PROPERTY, :INCLUDE, :CURRY, :PAGE, :COMMENT, :STUFF, :MODULE ]
@@supports = [ :CLASS, :MEMBER, :METHOD, :ACCESSOR, :FOREACH, :PROPERTY, :INCLUDE, :CURRY, :PAGE, :COMMENT, :STUFF, :MODULE, :PRIVATE ]
@@lookup = Hash.new

@@supports.each do |v|
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/curry.js2
@@ -0,0 +1,5 @@
curry (hello) with (this) {

}

hello.foo(curry (hello) with (this) { });
14 changes: 14 additions & 0 deletions test/fixtures/member.js2
@@ -0,0 +1,14 @@
class TestMember {

var WIDTH = 84;
var MENU_ACTIONS = [ 'sortData', 'sortData', 'hideColumn' ];

var arr = [ 'hello', 'world' ];
var one, two, three;
var foo = {};
var bar;
var foo1 = 'hello';
var bar1 = {
hello: "world"
};
}
5 changes: 5 additions & 0 deletions test/fixtures/private.js2
@@ -0,0 +1,5 @@
class TestPrivate {

private

}
4 changes: 4 additions & 0 deletions test/fixtures/property.js2
@@ -0,0 +1,4 @@
class TestProperty {
property foo;
property foo, bar;
}

0 comments on commit 2a7cd6b

Please sign in to comment.