fdlint 0.2.0.pre → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +36 -15
  4. data/Rakefile +1 -1
  5. data/bin/fdlint +30 -9
  6. data/lib/fdlint/cli.rb +62 -10
  7. data/lib/fdlint/helper/logger.rb +1 -1
  8. data/lib/fdlint/log_entry.rb +14 -0
  9. data/lib/fdlint/parser/html/html_parser.rb +10 -12
  10. data/lib/fdlint/parser/html/query.rb +64 -50
  11. data/lib/fdlint/parser/html/struct.rb +20 -3
  12. data/lib/fdlint/parser/parser_visitable.rb +11 -5
  13. data/lib/fdlint/printer/base_printer.rb +6 -0
  14. data/lib/fdlint/printer/console_printer.rb +15 -23
  15. data/lib/fdlint/rule.rb +4 -4
  16. data/lib/fdlint/support/core/object.rb +6 -0
  17. data/lib/fdlint/support/core_ext.rb +1 -0
  18. data/lib/fdlint/validator.rb +60 -8
  19. data/lib/fdlint/version.rb +1 -1
  20. data/lib/hook/git_pre_commit +18 -0
  21. data/rules.d/css.rule.rb +1 -1
  22. data/rules.d/filename.rule.rb +3 -1
  23. data/rules.d/html.rule.rb +45 -32
  24. data/rules.d/js.rule.rb +2 -2
  25. data/test/all_tests.rb +28 -42
  26. data/test/css/mac_line_end_support_test.rb +10 -12
  27. data/test/css/parser_test.rb +4 -5
  28. data/test/css/rule/check_encoding_test.rb +7 -8
  29. data/test/css/rule/check_list_rule_test.rb +85 -102
  30. data/test/css/rule/file_name_test.rb +18 -39
  31. data/test/default_test.rb +1 -14
  32. data/test/fixtures/css/ad.css +0 -0
  33. data/test/fixtures/css/adver/test.css +0 -0
  34. data/test/fixtures/css/camelCase.css +0 -0
  35. data/test/fixtures/css/min/ad.css +0 -0
  36. data/test/fixtures/css/min/ad.min.css +0 -0
  37. data/test/fixtures/html/mixed_log_levels.html +1 -0
  38. data/test/fixtures/html/mixed_types.html +3 -0
  39. data/test/helper.rb +116 -16
  40. data/test/html/mixed_type_test.rb +14 -20
  41. data/test/html/parser/parse_comment_test.rb +4 -4
  42. data/test/html/parser/parse_dtd_test.rb +7 -7
  43. data/test/html/parser/parse_script_tag_test.rb +21 -14
  44. data/test/html/parser/parse_with_auto_close_tag_test.rb +12 -10
  45. data/test/html/parser/parse_with_diff_case_test.rb +8 -9
  46. data/test/html/parser/parse_with_emtpy_test.rb +5 -3
  47. data/test/html/parser/parse_with_multi_children_test.rb +4 -4
  48. data/test/html/parser/parse_with_multi_line_test.rb +5 -5
  49. data/test/html/parser/parse_with_prop_test.rb +10 -10
  50. data/test/html/parser/parse_with_script_tag_test.rb +4 -4
  51. data/test/html/parser/parse_with_selfclosing_test.rb +11 -11
  52. data/test/html/parser/parse_with_simple_tag_test.rb +7 -7
  53. data/test/html/parser/parse_with_simple_tree_test.rb +6 -6
  54. data/test/html/parser/parse_with_style_tag_test.rb +4 -4
  55. data/test/html/parser/parse_with_text_test.rb +7 -7
  56. data/test/html/parser_test.rb +19 -19
  57. data/test/html/query_test.rb +18 -18
  58. data/test/html/rule/check_block_level_element_test.rb +22 -24
  59. data/test/html/rule/check_button_test.rb +9 -9
  60. data/test/html/rule/check_css_in_head_test.rb +11 -32
  61. data/test/html/rule/check_dtd_test.rb +15 -11
  62. data/test/html/rule/check_form_element_name_test.rb +10 -9
  63. data/test/html/rule/check_head_contain_meta_and_title_test.rb +28 -34
  64. data/test/html/rule/check_hyperlink_with_target_test.rb +23 -17
  65. data/test/html/rule/check_hyperlink_with_title_test.rb +13 -20
  66. data/test/html/rule/check_id_n_class_downcase_test.rb +8 -19
  67. data/test/html/rule/check_img_with_alt_prop_test.rb +11 -12
  68. data/test/html/rule/check_no_import_css_test.rb +20 -20
  69. data/test/html/rule/check_prop_have_value_test.rb +9 -13
  70. data/test/html/rule/check_prop_seperator_test.rb +9 -13
  71. data/test/html/rule/check_style_prop_test.rb +7 -12
  72. data/test/html/rule/check_tag_closed_test.rb +15 -40
  73. data/test/html/rule/check_tag_downcase_test.rb +31 -28
  74. data/test/html/rule/check_unescape_char_test.rb +17 -17
  75. data/test/html/rule/check_unique_import_test.rb +15 -33
  76. data/test/html/rule_test.rb +2 -6
  77. data/test/js/expr/expr.rb +1 -1
  78. data/test/js/expr/left_hand.rb +1 -1
  79. data/test/js/expr/operate.rb +1 -1
  80. data/test/js/expr/primary.rb +1 -1
  81. data/test/js/parser_test.rb +3 -6
  82. data/test/js/rule/alert_check_test.rb +5 -19
  83. data/test/js/rule/base_test.rb +5 -19
  84. data/test/js/rule/jq_check_test.rb +26 -58
  85. data/test/js/rule/nest_try_catch_test.rb +26 -43
  86. data/test/js/rule/new_object_and_new_array_test.rb +5 -21
  87. data/test/js/rule/no_eval_test.rb +3 -19
  88. data/test/js/rule/no_global_test.rb +34 -73
  89. data/test/js/rule/private_method_check_test.rb +14 -43
  90. data/test/js/rule/semicolon_test.rb +18 -47
  91. data/test/js/rule/stat_if_with_brace_test.rb +30 -53
  92. data/test/js/rule/stat_if_with_muti_else_test.rb +36 -53
  93. data/test/js/rule/use_strict_equal_test.rb +16 -29
  94. data/test/js/rule_test.rb +2 -4
  95. data/test/js/stat/if.rb +1 -1
  96. data/test/js/stat/iter.rb +1 -1
  97. data/test/js/stat/stat.rb +1 -1
  98. data/test/js/stat/switch.rb +1 -1
  99. data/test/js/stat/try.rb +1 -1
  100. data/test/js/stat/var.rb +1 -1
  101. data/test/parser_visitable_test.rb +14 -36
  102. data/test/position_info_test.rb +4 -5
  103. data/test/runner/log_level_test.rb +30 -25
  104. metadata +11 -14
  105. data/lib/fdlint/file_validator.rb +0 -38
  106. data/lib/fdlint/parser/html/rule/check_tag_rule.rb +0 -80
  107. data/test/css/rule/compression_test.rb +0 -53
  108. data/test/html/rule/check_class_count_test.rb +0 -36
  109. data/test/html/rule/check_html_template_test.rb +0 -103
  110. data/test/js/rule/all_test.rb +0 -23
  111. data/test/js/rule/file_checker_test.rb +0 -131
  112. data/test/rule_dsl/dsl_basic_test.rb +0 -91
  113. data/test/rule_dsl/importing_test.rb +0 -48
  114. data/test/test_helper.rb +0 -9
@@ -1,47 +1,45 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckBlockLevelElementTest < Test::Unit::TestCase
11
10
 
12
- include XRay::HTML
11
+ include FdlintTest::HTML
13
12
 
14
13
  def setup
15
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
+ @block_level_err = [:error, "行内标签不得包含块级标签,a标签例外"]
16
15
  end
17
16
 
18
17
  def test_check_normal
19
- tag = Element.new('div', nil, [
20
- Element.new('span', nil, [
21
- TextElement.new('good day, commander!')
22
- ])
23
- ])
24
- assert_equal [], @rule.check_html_tag(tag)
18
+ src = %Q{<div><span>good day, commander!</span></div>}
19
+ parse src do |results|
20
+ assert_not_has_result results, @block_level_err
21
+ end
25
22
  end
26
23
 
27
24
  def test_check_block_in_inline
28
- tag = Element.new('span', nil, [
29
- Element.new('div', nil, [
30
- TextElement.new('good day, commander!')
31
- ])
32
- ])
33
- assert_equal [["行内标签不得包含块级标签,a标签例外", :error]], @rule.check_html_tag(tag)
25
+ src = %Q{<span><div>good day, commander!</div></span>}
26
+ parse src do |results|
27
+ assert_has_result results, @block_level_err
28
+ end
34
29
  end
35
30
 
36
31
  def test_check_inline_inline_block
37
- tag = Element.new('span', nil, [
38
- Element.new('span', nil, [
39
- Element.new('div', nil, [
40
- TextElement.new('good day, commander!')
41
- ])
42
- ])
43
- ])
44
- assert_equal [], @rule.check_html_tag(tag)
32
+ src = %Q{<span><span>good day, commander!</span></span>}
33
+ parse src do |results|
34
+ assert_not_has_result results, @block_level_err
35
+ end
36
+ end
37
+
38
+ def test_check_block_in_a
39
+ src = %Q{<a><div>good day, commander!</div></a>}
40
+ parse src do |results|
41
+ assert_not_has_result results, @block_level_err
42
+ end
45
43
  end
46
44
 
47
45
  end
@@ -1,26 +1,25 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckButtonTest < Test::Unit::TestCase
11
10
 
12
- include XRay::HTML
11
+ include FdlintTest::HTML
13
12
 
14
13
  def setup
15
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
+ @button_err = [:error, "所有按钮必须用button(button/submit/reset)"]
16
15
  end
17
16
 
18
17
  def test_check_normal
19
18
  src = %q(<button type="button" name="usernmae" />
20
19
  <button type="submit" name="male" />
21
20
  <button type="reset" name="food" />)
22
- XRay::HTML::Parser.parse(src).each do |tag|
23
- assert_equal [], @rule.check_html_tag(tag)
21
+ parse src do |results|
22
+ assert_not_has_result results, @button_err
24
23
  end
25
24
  end
26
25
 
@@ -28,9 +27,10 @@ module XRayTest
28
27
  src = %q(<input type="button" value="btn" />
29
28
  <input type="submit" name="submit" value="submit"/>
30
29
  <input type="reset" />)
31
- XRay::HTML::Parser.parse(src).each do |tag|
32
- unless tag.is_a? TextElement
33
- assert_equal [["所有按钮必须用button(button/submit/reset)", :error]], @rule.check_html_tag(tag)
30
+
31
+ src.each_line do |src|
32
+ parse src do |results|
33
+ assert_has_result results, @button_err
34
34
  end
35
35
  end
36
36
  end
@@ -1,46 +1,28 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckCSSInHeadTest < Test::Unit::TestCase
11
10
 
12
- def setup
13
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
- end
11
+ include FdlintTest::HTML
15
12
 
16
- def test_check_alone_css_tag
17
- tag = css_link('test.css')
18
- assert_equal [], @rule.check_html_tag(tag)
19
- end
13
+ check_rule [:warn, '外链CSS置于head里(例外:应用里的footer样式)'] do
20
14
 
21
- def test_check_css_tag_in_head
22
- tag = css_link('test.css')
23
- head = XRay::HTML::Element.new('head', nil, [tag])
24
- assert_equal [], @rule.check_html_tag(tag)
25
- end
26
-
27
- def test_check_css_tag_in_body
28
- tag = css_link('test.css')
29
- body = XRay::HTML::Element.new('body', nil, [tag])
30
- assert_equal [["外链CSS置于head里(例外:应用里的footer样式)", :warn]], @rule.check_html_tag(tag)
31
- end
15
+ should_with_result do
16
+ [
17
+ %Q{<link rel="stylesheet" href="test.css"/>},
18
+ %Q{<body><link rel="stylesheet" href="test.css"/></body>}
19
+ ]
20
+ end
32
21
 
33
- def test_from_fixture
34
- results = XRay::Runner.new.check_html( fixture "html/css_out_of_head.html" )
35
- found = results.find_all do |res|
36
- res.message == "外链CSS置于head里(例外:应用里的footer样式)"
22
+ should_without_result do
23
+ %Q{<head><link rel="stylesheet" href="test.css"/></head>}
37
24
  end
38
- assert_equal 1, found.size
39
- end
40
25
 
41
- protected
42
- def css_link(src)
43
- XRay::HTML::Element.new('link', {:rel => 'stylesheet', :href=>src}, [], :self)
44
26
  end
45
27
 
46
28
  end
@@ -48,6 +30,3 @@ module XRayTest
48
30
  end
49
31
  end
50
32
  end
51
-
52
-
53
-
@@ -1,39 +1,43 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckDTDTest < Test::Unit::TestCase
11
10
 
11
+ include FdlintTest::HTML
12
+
12
13
  def setup
13
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
14
  end
15
15
 
16
16
  def test_check_html5_dtd
17
- tag = XRay::HTML::DTDElement.new('html')
18
- assert_equal [], @rule.check_html_dtd(tag)
17
+ parse '<!DOCTYPE html>' do |results|
18
+ assert results.blank?
19
+ end
19
20
  end
20
21
 
21
22
  def test_check_xhtml_dtd
22
23
  src = %q(html
23
24
  PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
24
25
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd")
25
- tag = XRay::HTML::DTDElement.new(src)
26
- assert_equal [['新页面统一使用HTML 5 DTD', :warn]], @rule.check_html_dtd(tag)
26
+ parse DTDElement.new(src).outer_html do |results|
27
+ assert_has_result results, [:warn, '推荐使用HTML 5 DTD']
28
+ end
27
29
  end
28
30
 
29
31
  def test_check_doctype_upcase
30
- tag = XRay::HTML::DTDElement.new('html', 'doctype')
31
- assert_equal [['必须使用大写的"DOCTYPE"', :warn]], @rule.check_html_dtd(tag)
32
+ parse '<!doctype html>' do |results|
33
+ assert_has_result results, [:warn, '必须使用大写的"DOCTYPE"']
34
+ end
32
35
  end
33
36
 
34
37
  def test_check_dtd_available
35
- doc = XRay::HTML::Parser.new('<html><body></body></html>')
36
- assert @rule.check_html_doc(doc).include?(['必须存在文档类型声明', :error])
38
+ parse '<html><body></body></html>' do |results|
39
+ assert_has_result results, [:error, '必须存在文档类型声明']
40
+ end
37
41
  end
38
42
 
39
43
  end
@@ -1,18 +1,17 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckFormElementNameTest < Test::Unit::TestCase
11
10
 
12
- include XRay::HTML
11
+ include FdlintTest::HTML
13
12
 
14
13
  def setup
15
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
+ @err = [:error, 'text、radio、checkbox、textarea、select必须加name属性']
16
15
  end
17
16
 
18
17
  def test_check_normal
@@ -21,8 +20,10 @@ module XRayTest
21
20
  <input type="checkbox" name="food" />
22
21
  <textarea name="bio">test</textarea>
23
22
  <select name="city"></select>)
24
- XRay::HTML::Parser.parse(src).each do |tag|
25
- assert_equal [], @rule.check_html_tag(tag)
23
+ src.each_line do |src|
24
+ parse src do |results|
25
+ assert_not_has_result results, @err
26
+ end
26
27
  end
27
28
  end
28
29
 
@@ -32,9 +33,9 @@ module XRayTest
32
33
  <input type="checkbox" />
33
34
  <textarea>test</textarea>
34
35
  <select></select>)
35
- XRay::HTML::Parser.parse(src).each do |tag|
36
- unless tag.is_a? TextElement
37
- assert_equal [["text、radio、checkbox、textarea、select必须加name属性", :error]], @rule.check_html_tag(tag)
36
+ src.each_line do |src|
37
+ parse src do |results|
38
+ assert_has_result results, @err
38
39
  end
39
40
  end
40
41
  end
@@ -1,48 +1,42 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckHeadTest < Test::Unit::TestCase
11
10
 
12
- include XRay::HTML
13
-
14
- def setup
15
- @rule = XRay::HTML::Rule::CheckTagRule.new
16
- @expect = ["head必须包含字符集meta和title", :error]
17
- end
18
-
19
- def test_check_right_tag
20
- tag = XRay::HTML::Element.new('head',nil, [
21
- Element.new('meta', {:charset => 'utf-8'}),
22
- Element.new('title', nil, [TextElement.new('hello world!')]),
23
- Element.new('meta', {:name => 'description'}),
24
- Element.new('meta', {:name => 'keywords'})
25
- ])
26
- assert_equal [], @rule.check_html_tag(tag)
27
- end
28
-
29
- def test_check_simple_head
30
- tag = XRay::HTML::Element.new('head')
31
- assert @rule.check_html_tag(tag).include?(@expect)
32
- end
33
-
34
- def test_check_head_without_meta
35
- tag = XRay::HTML::Element.new('head',nil, [
36
- Element.new('title', nil, [TextElement.new('hello world!')])
37
- ])
38
- assert @rule.check_html_tag(tag).include?(@expect)
11
+ include FdlintTest::HTML
12
+
13
+ should_with_result [:error, "head必须包含字符集meta和title"] do
14
+ [
15
+ %Q{<head></head>},
16
+
17
+ %Q{<head>
18
+ <title>hello world!</title>
19
+ <meta name="description">
20
+ <meta name="keywords">
21
+ </head>},
22
+
23
+ %Q{<head>
24
+ <meta charset="utf-8">
25
+ <meta name="description">
26
+ <meta name="keywords">
27
+ </head>}
28
+ ]
39
29
  end
40
30
 
41
- def test_check_head_without_title
42
- tag = XRay::HTML::Element.new('head',nil, [
43
- Element.new('meta', {:charset => 'utf-8'})
44
- ])
45
- assert @rule.check_html_tag(tag).include?(@expect)
31
+ should_without_result [:error, "head必须包含字符集meta和title"] do
32
+ <<-SRC
33
+ <head>
34
+ <meta charset="utf-8">
35
+ <title>hello world!</title>
36
+ <meta name="description">
37
+ <meta name="keywords">
38
+ </head>
39
+ SRC
46
40
  end
47
41
 
48
42
  end
@@ -1,33 +1,39 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckHyperlinkWithTargetTest < Test::Unit::TestCase
11
10
 
12
- def setup
13
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
- end
11
+ include FdlintTest::HTML
15
12
 
16
- def test_check_functional_a_with_target
17
- tag = XRay::HTML::Element.new('a', {:href=>'#nogo', :target=>'_self'})
18
- assert_equal [], @rule.check_html_tag(tag)
19
- end
13
+ check_rule [:warn, '功能a必须加target="_self",除非preventDefault过'] do
20
14
 
21
- def test_check_functional_a_without_target
22
- tag = XRay::HTML::Element.new('a', {:href=>'#nogo'})
23
- assert_equal [['功能a必须加target="_self",除非preventDefault过', :warn]], @rule.check_html_tag(tag)
24
- end
15
+ should_with_result do
16
+ [
17
+ %Q{<a href="#nogo"></a>},
18
+
19
+ %Q{
20
+ <base target="_blank">
21
+ <a href="#nogo"></a>
22
+ }
23
+ ]
24
+ end
25
+
26
+ should_without_result do
27
+ [
28
+ %Q{<a href="#nogo" target="_self"></a>},
25
29
 
26
- def test_when_html_has_base_tag
27
- @rule.check_html_tag XRay::HTML::Element.new('base', {:target=>'_self'})
30
+ %Q{
31
+ <base target="_self">
32
+ <a href="#nogo"></a>
33
+ }
34
+ ]
35
+ end
28
36
 
29
- tag = XRay::HTML::Element.new('a', {:href=>'#nogo'})
30
- assert_equal [], @rule.check_html_tag(tag)
31
37
  end
32
38
 
33
39
  end
@@ -1,36 +1,29 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckHyperlinkWithTitleTest < Test::Unit::TestCase
11
10
 
12
- def setup
13
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
- end
11
+ include FdlintTest::HTML
15
12
 
16
- def test_check_functional_a_with_title
17
- tag = XRay::HTML::Element.new('a', {:href=>'#nogo', :title=>'it is a hyperlink', :target=>'_self'})
18
- assert_equal [], @rule.check_html_tag(tag)
19
- end
13
+ check_rule [:error, '非功能能点的a标签必须加上title属性'] do
20
14
 
21
- def test_check_functional_a_without_title
22
- tag = XRay::HTML::Element.new('a', {:href=>'#nogo', :target=>'_self'})
23
- assert_equal [], @rule.check_html_tag(tag)
24
- end
15
+ should_with_result do
16
+ %Q{<a href="new-page.html"></a>}
17
+ end
25
18
 
26
- def test_check_normal_a_with_title
27
- tag = XRay::HTML::Element.new('a', {:href=>'new-page.html', :title=>'new page'})
28
- assert_equal [], @rule.check_html_tag(tag)
29
- end
19
+ should_without_result do
20
+ [
21
+ %Q{<a href="new-page.html" title="new page"></a>},
22
+
23
+ %Q{<a href="#nogo"></a>}
24
+ ]
25
+ end
30
26
 
31
- def test_check_normal_a_without_title
32
- tag = XRay::HTML::Element.new('a', {:href=>'new-page.html'})
33
- assert_equal [['非功能能点的a标签必须加上title属性', :error]], @rule.check_html_tag(tag)
34
27
  end
35
28
 
36
29
  end
@@ -1,36 +1,25 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckIDAndClassPropCaseTest < Test::Unit::TestCase
11
10
 
12
- def setup
13
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
- end
15
-
16
- def test_check_downcase_id
17
- prop = XRay::HTML::Property.new('id', 'uploader')
18
- assert_equal [], @rule.check_html_property(prop)
19
- end
11
+ include FdlintTest::HTML
20
12
 
21
- def test_check_downcase_class
22
- prop = XRay::HTML::Property.new('class', 'uploader info')
23
- assert_equal [], @rule.check_html_property(prop)
13
+ should_with_result [:error, "id名称全部小写,单词分隔使用中横线"] do
14
+ %Q{<a id="Nogo" href="#nogo"></a>}
24
15
  end
25
16
 
26
- def test_check_upcase_id
27
- prop = XRay::HTML::Property.new('id', 'Nogo')
28
- assert_equal [["id名称全部小写,单词分隔使用中横线", :error]], @rule.check_html_property(prop)
17
+ should_with_result [:error, "class名称全部小写"] do
18
+ %Q{<a class="Nogo" href="#nogo" target="_self"></a>}
29
19
  end
30
20
 
31
- def test_check_upcase_class
32
- prop = XRay::HTML::Property.new('class', 'Nogo')
33
- assert_equal [["class名称全部小写,单词分隔使用中横线", :error]], @rule.check_html_property(prop)
21
+ should_with_result [:error, "class名称单词分隔使用中横线"] do
22
+ %Q{<a class="no_go" href="#nogo" target="_self"></a>}
34
23
  end
35
24
 
36
25
  end
@@ -1,26 +1,25 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckImgWithAltPropTest < Test::Unit::TestCase
11
10
 
12
- def setup
13
- @rule = XRay::HTML::Rule::CheckTagRule.new
14
- end
11
+ include FdlintTest::HTML
15
12
 
16
- def test_check_img_with_alt
17
- tag = XRay::HTML::Element.new('img', {:src=>'http://pnq.cc/icon.png', :alt=>'图片'}, [], :self)
18
- assert_equal [], @rule.check_html_tag(tag)
19
- end
13
+ check_rule [:error, 'img标签必须加上alt属性'] do
14
+
15
+ should_with_result do
16
+ %Q{<img src="http://pnq.cc/icon.png" />}
17
+ end
18
+
19
+ should_without_result do
20
+ %Q{<img src="http://pnq.cc/icon.png" alt="test" />}
21
+ end
20
22
 
21
- def test_check_img_without_alt
22
- tag = XRay::HTML::Element.new('img', {:src=>'http://pnq.cc/icon.png'}, [], :self)
23
- assert_equal [["img标签必须加上alt属性", :error]], @rule.check_html_tag(tag)
24
23
  end
25
24
 
26
25
  end
@@ -1,32 +1,32 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckNoCSSImportTest < Test::Unit::TestCase
11
10
 
12
- include XRay::HTML
13
-
14
- def setup
15
- @rule = XRay::HTML::Rule::CheckTagRule.new
16
- end
17
-
18
- def test_check_normal
19
- tag = XRay::HTML::Element.new('style', nil, [
20
- TextElement.new('body { background-color:#fff; }')
21
- ])
22
- assert_equal [], @rule.check_html_tag(tag)
23
- end
24
-
25
- def test_check_style_with_import
26
- tag = XRay::HTML::Element.new('style', nil, [
27
- TextElement.new('@import style.css')
28
- ])
29
- assert_equal [["不通过@import在页面上引入CSS", :error]], @rule.check_html_tag(tag)
11
+ include FdlintTest::HTML
12
+
13
+ check_rule [:error, '不通过@import在页面上引入CSS'] do
14
+
15
+ should_with_result do
16
+ <<-SRC
17
+ <style>
18
+ @import "style.css"
19
+ </style>
20
+ SRC
21
+ end
22
+
23
+ should_without_result do
24
+ <<-SRC
25
+ <style>
26
+ body { background-color: #fff; }
27
+ </style>
28
+ SRC
29
+ end
30
30
  end
31
31
 
32
32
  end
@@ -1,28 +1,24 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative '../../helper'
4
- require 'html/rule/check_tag_rule'
5
4
 
6
- module XRayTest
5
+ module FdlintTest
7
6
  module HTML
8
7
  module Rule
9
8
 
10
9
  class CheckPropHaveValueTest < Test::Unit::TestCase
11
10
 
12
- include XRay::HTML
11
+ include FdlintTest::HTML
13
12
 
14
- def setup
15
- @rule = XRay::HTML::Rule::CheckTagRule.new
16
- end
13
+ check_rule [:error, '不能仅有属性名'] do
17
14
 
18
- def test_check_double_quote
19
- prop = XRay::HTML::Property.new('checked', 'true')
20
- assert_equal [], @rule.check_html_property(prop)
21
- end
15
+ should_with_result do
16
+ %Q{<input type="radio" checked />}
17
+ end
22
18
 
23
- def test_check_single_quote
24
- prop = XRay::HTML::Property.new('checked', nil)
25
- assert_equal [["不能仅有属性名", :error]], @rule.check_html_property(prop)
19
+ should_without_result do
20
+ %Q{<input type="radio" checked="true" />}
21
+ end
26
22
  end
27
23
 
28
24
  end