Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Light refactoring.

  • Loading branch information...
commit bafbc6123f6b486dacc2a29ffd963aed1285aa81 1 parent e79e6ff
@tobie tobie authored
Showing with 21 additions and 16 deletions.
  1. +21 −16 test/test_parser.rb
View
37 test/test_parser.rb
@@ -3,46 +3,51 @@
require "../lib/modulr/parser"
class TestLibModulrParser < Test::Unit::TestCase
- def get_module_identifier(src)
+ def assert_found_module(name, src, message="")
@parser ||= Modulr::Parser.new
- @parser.get_require_expressions(src).first[:identifier]
+ template = "Could not find module ? in JavaScript source code ?."
+ message = build_message(message, template, name, src)
+ assert_block(message) do
+ requires = @parser.get_require_expressions(src)
+ requires.first && requires.first[:identifier] == name
+ end
end
def test_simple_require_function
- assert_equal 'foo', get_module_identifier('require("foo")')
+ assert_found_module('foo', 'require("foo")')
end
def test_setting_variable
- assert_equal 'foo', get_module_identifier("var bar = require('foo');")
+ assert_found_module('foo', "var bar = require('foo');")
end
def test_accessing_property
- assert_equal 'foo', get_module_identifier("require('foo').bar;")
+ assert_found_module('foo', "require('foo').bar;")
end
def test_accessing_nested_property
- assert_equal 'foo', get_module_identifier("require('foo').baz.bar;")
+ assert_found_module('foo', "require('foo').baz.bar;")
end
def test_calling_method
- assert_equal 'foo', get_module_identifier("require('foo').bar();")
+ assert_found_module('foo', "require('foo').bar();")
end
def test_calling_nested_method
- assert_equal 'foo', get_module_identifier("require('foo').bar.baz();")
+ assert_found_module('foo', "require('foo').bar.baz();")
end
def test_instanciating_constructor
- assert_equal 'foo', get_module_identifier("new require('foo').Foo();")
- assert_equal 'foo', get_module_identifier("new require('foo').Foo;")
- assert_equal 'foo', get_module_identifier("new require('foo').Foo(1, 2, 3);")
- assert_equal 'foo', get_module_identifier("new (require('foo')).Foo();")
+ assert_found_module('foo', "new require('foo').Foo();")
+ assert_found_module('foo', "new require('foo').Foo;")
+ assert_found_module('foo', "new require('foo').Foo(1, 2, 3);")
+ assert_found_module('foo', "new (require('foo')).Foo();")
end
def test_instanciating_nested_constructor
- assert_equal 'foo', get_module_identifier("new require('foo').bar.Foo();")
- assert_equal 'foo', get_module_identifier("new require('foo').bar.Foo;")
- assert_equal 'foo', get_module_identifier("new require('foo').bar.Foo(1, 2, 3);")
- assert_equal 'foo', get_module_identifier("new (require('foo').bar).Foo();")
+ assert_found_module('foo', "new require('foo').bar.Foo();")
+ assert_found_module('foo', "new require('foo').bar.Foo;")
+ assert_found_module('foo', "new require('foo').bar.Foo(1, 2, 3);")
+ assert_found_module('foo', "new (require('foo').bar).Foo();")
end
end

0 comments on commit bafbc61

Please sign in to comment.
Something went wrong with that request. Please try again.