Class: SourceLineTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- SourceLineTest
- Defined in:
- lib/sprockets/test/test_source_line.rb
Instance Method Summary collapse
- #test_comment_should_be_extracted_from_comment_lines ⇒ Object
- #test_inspect_should_include_source_file_location_and_line_number ⇒ Object
- #test_interpolation_of_constants ⇒ Object
- #test_interpolation_of_missing_constant_raises_undefined_constant_error ⇒ Object
- #test_line_that_begins_a_multiline_comment ⇒ Object
- #test_line_that_begins_a_pdoc_comment ⇒ Object
- #test_line_that_begins_with_double_slash_should_be_a_comment ⇒ Object
- #test_line_that_contains_a_provide_comment_should_be_a_provide ⇒ Object
- #test_line_that_contains_but_does_not_begin_with_double_slash_should_not_be_a_comment ⇒ Object
- #test_line_that_contains_require_comment_should_be_a_require ⇒ Object
- #test_line_that_ends_a_multiline_comment ⇒ Object
- #test_line_that_ends_a_pdoc_comment ⇒ Object
- #test_provide_should_be_extracted_from_provide_lines ⇒ Object
- #test_require_should_be_extracted_from_require_lines ⇒ Object
- #test_to_s_should_strip_trailing_whitespace_before_adding_line_ending ⇒ Object
Instance Method Details
#test_comment_should_be_extracted_from_comment_lines ⇒ Object
38 39 40 41 42 |
# File 'lib/sprockets/test/test_source_line.rb', line 38 def test_comment_should_be_extracted_from_comment_lines assert_equal "test", source_line("//test").comment assert_equal " test", source_line("// test").comment assert_equal nil, source_line("f //test").comment end |
#test_inspect_should_include_source_file_location_and_line_number ⇒ Object
69 70 71 72 73 74 |
# File 'lib/sprockets/test/test_source_line.rb', line 69 def test_inspect_should_include_source_file_location_and_line_number environment = environment_for_fixtures pathname = Sprockets::Pathname.new(environment, "/a/b/c.js") source_file = Sprockets::SourceFile.new(environment, pathname) assert_equal "line 25 of #{File.expand_path("/a/b/c.js")}", source_line("hello", source_file, 25).inspect end |
#test_interpolation_of_constants ⇒ Object
76 77 78 |
# File 'lib/sprockets/test/test_source_line.rb', line 76 def test_interpolation_of_constants assert_equal %(var VERSION = "1.0";\n), source_line('var VERSION = "<%= VERSION %>";').to_s("VERSION" => "1.0") end |
#test_interpolation_of_missing_constant_raises_undefined_constant_error ⇒ Object
80 81 82 83 84 |
# File 'lib/sprockets/test/test_source_line.rb', line 80 def test_interpolation_of_missing_constant_raises_undefined_constant_error assert_raises(Sprockets::UndefinedConstantError) do source_line('<%= NONEXISTENT %>').to_s("VERSION" => "1.0") end end |
#test_line_that_begins_a_multiline_comment ⇒ Object
13 14 15 16 |
# File 'lib/sprockets/test/test_source_line.rb', line 13 def test_line_that_begins_a_multiline_comment assert source_line(" /*").begins_multiline_comment? assert source_line(" /**").begins_multiline_comment? end |
#test_line_that_begins_a_pdoc_comment ⇒ Object
18 19 20 21 |
# File 'lib/sprockets/test/test_source_line.rb', line 18 def test_line_that_begins_a_pdoc_comment assert !source_line(" /*").begins_pdoc_comment? assert source_line(" /**").begins_pdoc_comment? end |
#test_line_that_begins_with_double_slash_should_be_a_comment ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/sprockets/test/test_source_line.rb', line 4 def test_line_that_begins_with_double_slash_should_be_a_comment assert source_line("//").comment? assert source_line("//test").comment? assert source_line("//= require").comment? assert source_line("//= require <foo>").comment? assert source_line(" //").comment? assert source_line("\t//").comment? end |
#test_line_that_contains_a_provide_comment_should_be_a_provide ⇒ Object
58 59 60 61 62 |
# File 'lib/sprockets/test/test_source_line.rb', line 58 def test_line_that_contains_a_provide_comment_should_be_a_provide assert source_line("//= provide \"../assets\"").provide? assert !source_line("//= provide").provide? assert !source_line("//= provide <../assets>").provide? end |
#test_line_that_contains_but_does_not_begin_with_double_slash_should_not_be_a_comment ⇒ Object
33 34 35 36 |
# File 'lib/sprockets/test/test_source_line.rb', line 33 def test_line_that_contains_but_does_not_begin_with_double_slash_should_not_be_a_comment assert !source_line("f //").comment? assert !source_line("f //= require <foo>").comment? end |
#test_line_that_contains_require_comment_should_be_a_require ⇒ Object
44 45 46 47 48 49 |
# File 'lib/sprockets/test/test_source_line.rb', line 44 def test_line_that_contains_require_comment_should_be_a_require assert source_line("//= require <foo>").require? assert !source_line("//= require<foo>").require? assert source_line("//= require \"foo\"").require? assert !source_line("//= require <foo> f").require? end |
#test_line_that_ends_a_multiline_comment ⇒ Object
23 24 25 26 |
# File 'lib/sprockets/test/test_source_line.rb', line 23 def test_line_that_ends_a_multiline_comment assert source_line(" */").ends_multiline_comment? assert source_line(" **/").ends_multiline_comment? end |
#test_line_that_ends_a_pdoc_comment ⇒ Object
28 29 30 31 |
# File 'lib/sprockets/test/test_source_line.rb', line 28 def test_line_that_ends_a_pdoc_comment assert !source_line(" */").ends_pdoc_comment? assert source_line(" **/").ends_pdoc_comment? end |
#test_provide_should_be_extracted_from_provide_lines ⇒ Object
64 65 66 67 |
# File 'lib/sprockets/test/test_source_line.rb', line 64 def test_provide_should_be_extracted_from_provide_lines assert_nil source_line("//= provide").provide assert_equal "../assets", source_line("//= provide \"../assets\"").provide end |
#test_require_should_be_extracted_from_require_lines ⇒ Object
51 52 53 54 55 56 |
# File 'lib/sprockets/test/test_source_line.rb', line 51 def test_require_should_be_extracted_from_require_lines assert_nil source_line("//= require").require assert_equal "<foo>", source_line("//= require <foo>").require assert_equal "<foo>", source_line("//= require <foo> ").require assert_equal "\"foo\"", source_line("//= require \"foo\"").require end |
#test_to_s_should_strip_trailing_whitespace_before_adding_line_ending ⇒ Object
86 87 88 |
# File 'lib/sprockets/test/test_source_line.rb', line 86 def test_to_s_should_strip_trailing_whitespace_before_adding_line_ending assert_equal "hello();\n", source_line("hello(); \t \r\n").to_s({}) end |