fdlint 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +8 -0
- data/Gemfile.lock +14 -0
- data/README.md +68 -0
- data/Rakefile +92 -0
- data/bin/fdlint +17 -0
- data/lib/base_parser.rb +143 -0
- data/lib/cmd_runner.rb +145 -0
- data/lib/context.rb +31 -0
- data/lib/css/parser.rb +186 -0
- data/lib/css/reader.rb +30 -0
- data/lib/css/rule/check_compression_rule.rb +48 -0
- data/lib/css/rule/checklist.rb +45 -0
- data/lib/css/struct.rb +111 -0
- data/lib/encoding_error.rb +6 -0
- data/lib/file_validator.rb +38 -0
- data/lib/helper/code_type.rb +50 -0
- data/lib/helper/color_string.rb +44 -0
- data/lib/helper/file_reader.rb +22 -0
- data/lib/helper/strenc.rb +65 -0
- data/lib/html/parser.rb +212 -0
- data/lib/html/query.rb +96 -0
- data/lib/html/rule/check_tag_rule.rb +80 -0
- data/lib/html/struct.rb +291 -0
- data/lib/js/expr/expr.rb +66 -0
- data/lib/js/expr/left_hand.rb +63 -0
- data/lib/js/expr/operate.rb +92 -0
- data/lib/js/expr/primary.rb +166 -0
- data/lib/js/parser.rb +116 -0
- data/lib/js/rule/all.rb +35 -0
- data/lib/js/rule/checklist.rb +41 -0
- data/lib/js/rule/file_checker.rb +42 -0
- data/lib/js/rule/helper.rb +96 -0
- data/lib/js/rule/no_global.rb +87 -0
- data/lib/js/stat/if.rb +25 -0
- data/lib/js/stat/iter.rb +85 -0
- data/lib/js/stat/stat.rb +117 -0
- data/lib/js/stat/switch.rb +65 -0
- data/lib/js/stat/try.rb +28 -0
- data/lib/js/stat/var.rb +40 -0
- data/lib/js/struct.rb +248 -0
- data/lib/log_entry.rb +49 -0
- data/lib/node.rb +28 -0
- data/lib/parse_error.rb +13 -0
- data/lib/parser_visitable.rb +138 -0
- data/lib/position_info.rb +46 -0
- data/lib/printer/base_printer.rb +24 -0
- data/lib/printer/console_printer.rb +66 -0
- data/lib/printer/nocolor_printer.rb +27 -0
- data/lib/printer/vim_printer.rb +19 -0
- data/lib/rule.rb +241 -0
- data/lib/rule_helper.rb +14 -0
- data/lib/runner.rb +225 -0
- data/rules.d/css.rule +127 -0
- data/rules.d/html.dtd.rule +22 -0
- data/rules.d/html.prop.rule +51 -0
- data/rules.d/html.tag.rule +136 -0
- data/rules.d/js.file.rule +13 -0
- data/rules.d/js.jquery.rule +56 -0
- data/rules.d/js.mergefile.rule +71 -0
- data/rules.d/js.rule +84 -0
- data/test/all_tests.rb +84 -0
- data/test/cli/cli_test.rb +70 -0
- data/test/cli/log_level_test.rb +51 -0
- data/test/cli/output_format_test.rb +47 -0
- data/test/cli/type_test.rb +77 -0
- data/test/css/mac_line_end_support_test.rb +38 -0
- data/test/css/parser_test.rb +276 -0
- data/test/css/rule/check_encoding_test.rb +66 -0
- data/test/css/rule/check_list_rule_test.rb +167 -0
- data/test/css/rule/compression_test.rb +53 -0
- data/test/css/rule/file_name_test.rb +76 -0
- data/test/fixtures/css/broken.css +4 -0
- data/test/fixtures/css/cbu/36.css +52 -0
- data/test/fixtures/css/cbu/china_top.css +324 -0
- data/test/fixtures/css/cbu/default-merge.css +3 -0
- data/test/fixtures/css/cbu/default.css +13 -0
- data/test/fixtures/css/cbu/diy-merge.css +25 -0
- data/test/fixtures/css/cbu/fns-v1.css +27 -0
- data/test/fixtures/css/cbu/index_v0.1.css +12 -0
- data/test/fixtures/css/cbu/merge.css +11 -0
- data/test/fixtures/css/cbu/min.css +2 -0
- data/test/fixtures/css/cbu/my_home_admin.css +126 -0
- data/test/fixtures/css/cbu/nav.css +95 -0
- data/test/fixtures/css/cbu/pic_list.css +386 -0
- data/test/fixtures/css/cbu/quote-edit.css +18 -0
- data/test/fixtures/css/cbu/selloffer.shopwindow.css +1 -0
- data/test/fixtures/css/cbu/v1.css +9 -0
- data/test/fixtures/css/css3.css +30 -0
- data/test/fixtures/css/empty-min.css +0 -0
- data/test/fixtures/css/empty.css +0 -0
- data/test/fixtures/css/font-family.css +4 -0
- data/test/fixtures/css/gb-good.css +14 -0
- data/test/fixtures/css/gb_using_star.css +4 -0
- data/test/fixtures/css/import.css +18 -0
- data/test/fixtures/css/mac-line-sep-err-min.css +1 -0
- data/test/fixtures/css/mac-line-sep-err.css +1 -0
- data/test/fixtures/css/mac-line-sep-good-min.css +1 -0
- data/test/fixtures/css/mac-line-sep-good.css +1 -0
- data/test/fixtures/css/multi-encoding-in-a-file.css +0 -0
- data/test/fixtures/css/simple.css +1 -0
- data/test/fixtures/css/using_expr.css +8 -0
- data/test/fixtures/css/using_hack.css +21 -0
- data/test/fixtures/css/using_id.css +1 -0
- data/test/fixtures/css/using_star.css +4 -0
- data/test/fixtures/css/utf8_good.css +6 -0
- data/test/fixtures/css/utf8_good_declaring_charset.css +7 -0
- data/test/fixtures/css/utf8_using_star.css +5 -0
- data/test/fixtures/html/1-1.html +120 -0
- data/test/fixtures/html/1-2.html +120 -0
- data/test/fixtures/html/cms.html +373 -0
- data/test/fixtures/html/css_out_of_head.html +9 -0
- data/test/fixtures/html/fdev-template.html +22 -0
- data/test/fixtures/html/google.com.html +33 -0
- data/test/fixtures/html/mixed_log_levels.html +4 -0
- data/test/fixtures/html/mixed_types.html +13 -0
- data/test/fixtures/html/no_dtd.html +6 -0
- data/test/fixtures/html/readme.html +94 -0
- data/test/fixtures/html/review.board.html +163 -0
- data/test/fixtures/html/syntax_err.html +3 -0
- data/test/fixtures/html/train/detail/345/233/276/346/226/207/347/273/223/345/220/210.html +208 -0
- data/test/fixtures/html/train/detail/347/232/204Flash.html +212 -0
- data/test/fixtures/html/train/detail/347/232/204Vedio.html +212 -0
- data/test/fixtures/html/train/index.html +37 -0
- data/test/fixtures/html/train/test.html +1 -0
- data/test/fixtures/html/train//344/277/256/346/224/271/344/270/200/347/272/247/345/210/206/347/261/273.html +112 -0
- data/test/fixtures/html/train//344/277/256/346/224/271/345/255/220/345/210/206/347/261/273.html +108 -0
- data/test/fixtures/html/train//344/277/256/346/224/271/350/257/276/347/250/213.html +195 -0
- data/test/fixtures/html/train//345/215/232/345/256/242/350/256/276/347/275/256.html +142 -0
- data/test/fixtures/html/train//346/265/217/350/247/210/350/256/260/345/275/225.html +191 -0
- data/test/fixtures/html/train//346/267/273/345/212/240/344/270/200/347/272/247/345/210/206/347/261/273.html +113 -0
- data/test/fixtures/html/train//346/267/273/345/212/240/345/255/220/345/210/206/347/261/273.html +112 -0
- data/test/fixtures/html/train//346/267/273/345/212/240/350/257/276/347/250/213.html +195 -0
- data/test/fixtures/html/train//347/231/273/345/275/225.html +20 -0
- data/test/fixtures/html/train//347/256/241/347/220/206/345/210/206/347/261/273.html +210 -0
- data/test/fixtures/html/train//347/256/241/347/220/206/345/217/215/351/246/210.html +222 -0
- data/test/fixtures/html/train//347/256/241/347/220/206/350/257/276/347/250/213.html +284 -0
- data/test/fixtures/html/train//347/256/241/347/220/206/350/264/246/346/210/267.html +107 -0
- data/test/fixtures/html/train//347/275/221/344/270/212/345/237/271/350/256/255home/351/241/265.html +354 -0
- data/test/fixtures/html/train//347/275/221/345/225/206/345/237/271/350/256/255list/351/241/265.html +255 -0
- data/test/fixtures/html/train//350/256/276/347/275/256/351/246/226/351/241/265/346/216/250/350/215/220.html +168 -0
- data/test/fixtures/html/train//350/257/264/346/230/216.txt +3 -0
- data/test/fixtures/html/train//351/246/226/351/241/265/345/271/277/345/221/212/350/256/276/347/275/256.html +297 -0
- data/test/fixtures/html/unescaped.html +2 -0
- data/test/fixtures/html/view.vm +916 -0
- data/test/fixtures/js/jquery-1.7.js +9300 -0
- data/test/fixtures/js/scope-test.js +22 -0
- data/test/helper.rb +41 -0
- data/test/html/mixed_type_test.rb +35 -0
- data/test/html/parser/parse_comment_test.rb +47 -0
- data/test/html/parser/parse_dtd_test.rb +46 -0
- data/test/html/parser/parse_script_tag_test.rb +55 -0
- data/test/html/parser/parse_with_auto_close_tag_test.rb +41 -0
- data/test/html/parser/parse_with_diff_case_test.rb +38 -0
- data/test/html/parser/parse_with_emtpy_test.rb +22 -0
- data/test/html/parser/parse_with_multi_children_test.rb +27 -0
- data/test/html/parser/parse_with_multi_line_test.rb +41 -0
- data/test/html/parser/parse_with_prop_test.rb +88 -0
- data/test/html/parser/parse_with_script_tag_test.rb +26 -0
- data/test/html/parser/parse_with_selfclosing_test.rb +39 -0
- data/test/html/parser/parse_with_simple_tag_test.rb +44 -0
- data/test/html/parser/parse_with_simple_tree_test.rb +40 -0
- data/test/html/parser/parse_with_style_tag_test.rb +22 -0
- data/test/html/parser/parse_with_text_test.rb +45 -0
- data/test/html/parser_test.rb +52 -0
- data/test/html/query_test.rb +52 -0
- data/test/html/rule/check_block_level_element_test.rb +52 -0
- data/test/html/rule/check_button_test.rb +45 -0
- data/test/html/rule/check_class_count_test.rb +36 -0
- data/test/html/rule/check_css_in_head_test.rb +53 -0
- data/test/html/rule/check_dtd_test.rb +46 -0
- data/test/html/rule/check_form_element_name_test.rb +49 -0
- data/test/html/rule/check_head_contain_meta_and_title_test.rb +52 -0
- data/test/html/rule/check_html_template_test.rb +103 -0
- data/test/html/rule/check_hyperlink_with_target_test.rb +40 -0
- data/test/html/rule/check_hyperlink_with_title_test.rb +43 -0
- data/test/html/rule/check_id_n_class_downcase_test.rb +40 -0
- data/test/html/rule/check_img_with_alt_prop_test.rb +33 -0
- data/test/html/rule/check_no_import_css_test.rb +36 -0
- data/test/html/rule/check_prop_have_value_test.rb +32 -0
- data/test/html/rule/check_prop_seperator_test.rb +32 -0
- data/test/html/rule/check_style_prop_test.rb +30 -0
- data/test/html/rule/check_tag_closed_test.rb +59 -0
- data/test/html/rule/check_tag_downcase_test.rb +51 -0
- data/test/html/rule/check_unescape_char_test.rb +35 -0
- data/test/html/rule/check_unique_import_test.rb +56 -0
- data/test/html/rule_test.rb +62 -0
- data/test/js/expr/expr.rb +57 -0
- data/test/js/expr/left_hand.rb +25 -0
- data/test/js/expr/operate.rb +145 -0
- data/test/js/expr/primary.rb +89 -0
- data/test/js/parser_test.rb +98 -0
- data/test/js/rule/alert_check_test.rb +37 -0
- data/test/js/rule/all_test.rb +23 -0
- data/test/js/rule/base_test.rb +34 -0
- data/test/js/rule/file_checker_test.rb +131 -0
- data/test/js/rule/jq_check_test.rb +90 -0
- data/test/js/rule/nest_try_catch_test.rb +71 -0
- data/test/js/rule/new_object_and_new_array_test.rb +38 -0
- data/test/js/rule/no_eval_test.rb +34 -0
- data/test/js/rule/no_global_test.rb +88 -0
- data/test/js/rule/private_method_check_test.rb +58 -0
- data/test/js/rule/semicolon_test.rb +63 -0
- data/test/js/rule/stat_if_with_brace_test.rb +68 -0
- data/test/js/rule/stat_if_with_muti_else_test.rb +68 -0
- data/test/js/rule/use_strict_equal_test.rb +44 -0
- data/test/js/rule_test.rb +47 -0
- data/test/js/stat/if.rb +26 -0
- data/test/js/stat/iter.rb +115 -0
- data/test/js/stat/stat.rb +91 -0
- data/test/js/stat/switch.rb +37 -0
- data/test/js/stat/try.rb +32 -0
- data/test/js/stat/var.rb +38 -0
- data/test/parser_visitable_test.rb +102 -0
- data/test/position_info_test.rb +66 -0
- data/test/rule_dsl/dsl_basic_test.rb +91 -0
- data/test/rule_dsl/importing_test.rb +48 -0
- data/test/runner/log_level_test.rb +58 -0
- metadata +317 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckHyperlinkWithTitleTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
14
|
+
end
|
|
15
|
+
|
|
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
|
|
20
|
+
|
|
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
|
|
25
|
+
|
|
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
|
|
30
|
+
|
|
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
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckIDAndClassPropCaseTest < Test::Unit::TestCase
|
|
11
|
+
|
|
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
|
|
20
|
+
|
|
21
|
+
def test_check_downcase_class
|
|
22
|
+
prop = XRay::HTML::Property.new('class', 'uploader info')
|
|
23
|
+
assert_equal [], @rule.check_html_property(prop)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_check_upcase_id
|
|
27
|
+
prop = XRay::HTML::Property.new('id', 'Nogo')
|
|
28
|
+
assert_equal [["id名称全部小写,单词分隔使用中横线", :error]], @rule.check_html_property(prop)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_check_upcase_class
|
|
32
|
+
prop = XRay::HTML::Property.new('class', 'Nogo')
|
|
33
|
+
assert_equal [["class名称全部小写,单词分隔使用中横线", :error]], @rule.check_html_property(prop)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckImgWithAltPropTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
14
|
+
end
|
|
15
|
+
|
|
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
|
|
20
|
+
|
|
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
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckNoCSSImportTest < Test::Unit::TestCase
|
|
11
|
+
|
|
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)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckPropHaveValueTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
include XRay::HTML
|
|
13
|
+
|
|
14
|
+
def setup
|
|
15
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_check_double_quote
|
|
19
|
+
prop = XRay::HTML::Property.new('checked', 'true')
|
|
20
|
+
assert_equal [], @rule.check_html_property(prop)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_check_single_quote
|
|
24
|
+
prop = XRay::HTML::Property.new('checked', nil)
|
|
25
|
+
assert_equal [["不能仅有属性名", :error]], @rule.check_html_property(prop)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckPropSeperatorTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
include XRay::HTML
|
|
13
|
+
|
|
14
|
+
def setup
|
|
15
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_check_double_quote
|
|
19
|
+
prop = XRay::HTML::Property.new('id', 'info', "\"")
|
|
20
|
+
assert_equal [], @rule.check_html_property(prop)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_check_single_quote
|
|
24
|
+
prop = XRay::HTML::Property.new('id', 'info', "\'")
|
|
25
|
+
assert_equal [["属性值必须使用双引号", :error]], @rule.check_html_property(prop)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckStylePropTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_check_normal
|
|
17
|
+
prop = XRay::HTML::Property.new('href', '#nogo')
|
|
18
|
+
assert_equal [], @rule.check_html_property(prop)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_check_tag_with_style_prop
|
|
22
|
+
prop = XRay::HTML::Property.new('style', 'nogo')
|
|
23
|
+
assert_equal [["不能定义内嵌样式style", :error]], @rule.check_html_property(prop)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckTagClosedTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_check_normal_tag
|
|
17
|
+
tag = XRay::HTML::Element.new('div', {:class=>'footer'})
|
|
18
|
+
assert_equal [], @rule.check_html_tag(tag)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_check_normal_tag_not_closed
|
|
22
|
+
tag = XRay::HTML::Element.new('div', {:class=>'footer'})
|
|
23
|
+
tag.close_type = :none
|
|
24
|
+
assert_equal [["标签必须正确闭合", :error]], @rule.check_html_tag(tag)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_check_normal_tag_self_closed
|
|
28
|
+
tag = XRay::HTML::Element.new('div', {:class=>'footer'})
|
|
29
|
+
tag.close_type = :self
|
|
30
|
+
assert_equal [], @rule.check_html_tag(tag)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_check_self_close_tag_right
|
|
34
|
+
tag = XRay::HTML::Element.new('img', {:class=>'footer', :alt=>'image'})
|
|
35
|
+
tag.close_type = :self
|
|
36
|
+
assert_equal [], @rule.check_html_tag(tag)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_check_self_close_tag_close_after
|
|
40
|
+
tag = XRay::HTML::Element.new('img', {:class=>'footer', :alt=>'image'})
|
|
41
|
+
assert_equal [["标签必须正确闭合", :error]], @rule.check_html_tag(tag)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_check_text
|
|
45
|
+
tag = XRay::HTML::TextElement.new('hello world')
|
|
46
|
+
assert_equal [], @rule.check_html_tag(tag)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_check_comment
|
|
50
|
+
tag = XRay::HTML::CommentElement.new('hello world')
|
|
51
|
+
assert_equal [], @rule.check_html_tag(tag)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckTagDowncaseTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_check_normal_prop_name
|
|
17
|
+
prop = XRay::HTML::Property.new('href', '#nogo')
|
|
18
|
+
assert_equal [], @rule.check_html_property(prop)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_check_normal_tag_name
|
|
22
|
+
tag = XRay::HTML::Element.new('div', {:class=>'footer'})
|
|
23
|
+
assert_equal [], @rule.check_html_tag(tag)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_check_tag_with_upcase_name
|
|
27
|
+
tag = XRay::HTML::Element.new('DIV', {:class=>'footer'})
|
|
28
|
+
assert_equal [["标签名必须小写", :error]], @rule.check_html_tag(tag)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_check_tag_with_upcase_ending
|
|
32
|
+
tag = XRay::HTML::Element.new('div', nil, [], :after, '</DIV>')
|
|
33
|
+
assert_equal [["标签名必须小写", :error]], @rule.check_html_tag(tag)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_check_tag_with_simple_upcase_prop_name
|
|
37
|
+
prop = XRay::HTML::Property.new('Href', 'nogo')
|
|
38
|
+
assert_equal [["属性名必须小写,连字符用中横线", :error]], @rule.check_html_property(prop)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_check_tag_with_style_prop
|
|
42
|
+
prop = XRay::HTML::Property.new('Style', 'nogo')
|
|
43
|
+
assert_equal [["不能定义内嵌样式style", :error], ["属性名必须小写,连字符用中横线", :error]], @rule.check_html_property(prop)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckUnescapedCharTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_check_normal_text_tag
|
|
17
|
+
tag = XRay::HTML::TextElement.new('hello')
|
|
18
|
+
assert_equal [], @rule.check_html_text(tag)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_check_text_el_with_rt
|
|
22
|
+
tag = XRay::HTML::TextElement.new('>>>')
|
|
23
|
+
assert_equal [["特殊HTML符号(>和<)必须转义", :error]], @rule.check_html_text(tag)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_check_text_el_with_lt
|
|
27
|
+
tag = XRay::HTML::TextElement.new('<<<<')
|
|
28
|
+
assert_equal [["特殊HTML符号(>和<)必须转义", :error]], @rule.check_html_text(tag)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
require 'html/rule/check_tag_rule'
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module HTML
|
|
8
|
+
module Rule
|
|
9
|
+
|
|
10
|
+
class CheckUniqueImportTest < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_check_normal_script
|
|
17
|
+
tag = XRay::HTML::Element.new('script', {:src=>'http://style.china.alibaba.com/lib/fdev-v4/core/fdev-min.js'})
|
|
18
|
+
assert_equal [], @rule.visit_tag(tag)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_check_repeated_script
|
|
22
|
+
tag = XRay::HTML::Element.new('script', {:src=>'http://style.china.alibaba.com/lib/fdev-v4/core/fdev-min.js'})
|
|
23
|
+
assert_equal [], @rule.visit_tag(tag)
|
|
24
|
+
(1..10).each do
|
|
25
|
+
assert_equal [["避免重复引用同一或相同功能文件", :error]], @rule.visit_tag(tag)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_check_with_inline_script
|
|
30
|
+
tag = XRay::HTML::Element.new('script')
|
|
31
|
+
assert_equal [], @rule.visit_tag(tag)
|
|
32
|
+
(1..10).each do
|
|
33
|
+
assert_equal [], @rule.visit_tag(tag)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_check_normal_style
|
|
38
|
+
tag = XRay::HTML::Element.new('link', {:rel => 'stylesheet', :href=>'http://style.china.alibaba.com/css/lib/fdev-v4/core/fdev-min.css'}, [], :self)
|
|
39
|
+
assert_equal [], @rule.visit_tag(tag)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_check_repeated_style
|
|
43
|
+
tag = XRay::HTML::Element.new('link', {:rel => 'stylesheet', :href=>'http://style.china.alibaba.com/css/lib/fdev-v4/core/fdev-min.css'}, [], :self)
|
|
44
|
+
assert_equal [], @rule.visit_tag(tag)
|
|
45
|
+
(1..10).each do
|
|
46
|
+
assert_equal [["避免重复引用同一或相同功能文件", :error]], @rule.visit_tag(tag)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
gem 'test-unit' if defined? gem
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'test/unit/testsuite'
|
|
4
|
+
require 'test/unit/ui/console/testrunner'
|
|
5
|
+
|
|
6
|
+
require_relative 'rule/check_style_prop_test'
|
|
7
|
+
require_relative 'rule/check_unique_import_test'
|
|
8
|
+
require_relative 'rule/check_tag_downcase_test'
|
|
9
|
+
require_relative 'rule/check_img_with_alt_prop_test'
|
|
10
|
+
require_relative 'rule/check_hyperlink_with_target_test'
|
|
11
|
+
require_relative 'rule/check_hyperlink_with_title_test'
|
|
12
|
+
require_relative 'rule/check_dtd_test'
|
|
13
|
+
require_relative 'rule/check_id_n_class_downcase_test'
|
|
14
|
+
require_relative 'rule/check_no_import_css_test'
|
|
15
|
+
require_relative 'rule/check_prop_seperator_test'
|
|
16
|
+
require_relative 'rule/check_prop_have_value_test'
|
|
17
|
+
require_relative 'rule/check_head_contain_meta_and_title_test'
|
|
18
|
+
require_relative 'rule/check_block_level_element_test'
|
|
19
|
+
require_relative 'rule/check_form_element_name_test'
|
|
20
|
+
require_relative 'rule/check_button_test'
|
|
21
|
+
require_relative 'rule/check_class_count_test'
|
|
22
|
+
require_relative 'rule/check_tag_closed_test'
|
|
23
|
+
require_relative 'rule/check_html_template_test'
|
|
24
|
+
require_relative 'rule/check_css_in_head_test'
|
|
25
|
+
require_relative 'rule/check_unescape_char_test'
|
|
26
|
+
|
|
27
|
+
module XRayTest
|
|
28
|
+
|
|
29
|
+
module HTML
|
|
30
|
+
|
|
31
|
+
class RuleTest < Test::Unit::TestSuite
|
|
32
|
+
|
|
33
|
+
def self.suite
|
|
34
|
+
tests = Test::Unit::TestSuite.new
|
|
35
|
+
tests << Rule::CheckStylePropTest.suite
|
|
36
|
+
tests << Rule::CheckUniqueImportTest.suite
|
|
37
|
+
tests << Rule::CheckTagDowncaseTest.suite
|
|
38
|
+
tests << Rule::CheckImgWithAltPropTest.suite
|
|
39
|
+
tests << Rule::CheckHyperlinkWithTargetTest.suite
|
|
40
|
+
tests << Rule::CheckHyperlinkWithTitleTest.suite
|
|
41
|
+
tests << Rule::CheckDTDTest.suite
|
|
42
|
+
tests << Rule::CheckIDAndClassPropCaseTest.suite
|
|
43
|
+
tests << Rule::CheckNoCSSImportTest.suite
|
|
44
|
+
tests << Rule::CheckPropSeperatorTest.suite
|
|
45
|
+
tests << Rule::CheckPropHaveValueTest.suite
|
|
46
|
+
tests << Rule::CheckHeadTest.suite
|
|
47
|
+
tests << Rule::CheckBlockLevelElementTest.suite
|
|
48
|
+
tests << Rule::CheckFormElementNameTest.suite
|
|
49
|
+
tests << Rule::CheckButtonTest.suite
|
|
50
|
+
tests << Rule::CheckClassCountTest.suite
|
|
51
|
+
tests << Rule::CheckTagClosedTest.suite
|
|
52
|
+
tests << Rule::CheckHTMLTemplateTest.suite
|
|
53
|
+
tests << Rule::CheckCSSInHeadTest.suite
|
|
54
|
+
tests << Rule::CheckUnescapedCharTest.suite
|
|
55
|
+
tests
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Test::Unit::UI::Console::TestRunner.run( XRayTest::HTML::RuleTest ) if __FILE__ == $0
|
|
62
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require_relative 'primary'
|
|
2
|
+
require_relative 'left_hand'
|
|
3
|
+
require_relative 'operate'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module XRayTest
|
|
7
|
+
module JS
|
|
8
|
+
module Expr
|
|
9
|
+
|
|
10
|
+
module Expr
|
|
11
|
+
|
|
12
|
+
include Primary, LeftHand, Operate
|
|
13
|
+
|
|
14
|
+
def test_parse_expression
|
|
15
|
+
jses = [
|
|
16
|
+
'a = 1, b = 2, c = 3'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
exprs = [
|
|
20
|
+
'(,,(,,(=,a,1),(=,b,2)),(=,c,3))'
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
add_test :parse_expression, jses, exprs
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_parse_expr_assignment
|
|
27
|
+
jses = [
|
|
28
|
+
'a = 1 + 2 == 0 ? 1 : 0',
|
|
29
|
+
'a *= 1 + 2'
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
exprs = [
|
|
33
|
+
'(=,a,(?:,(==,(+,1,2),0),1,0))',
|
|
34
|
+
'(*=,a,(+,1,2))'
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
add_test :parse_expr_assignment, jses, exprs
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_parse_expr_condition
|
|
42
|
+
jses = [
|
|
43
|
+
'a + 1 == 0 ? 1 : 2'
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
exprs = [
|
|
47
|
+
'(?:,(==,(+,a,1),0),1,2)'
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
add_test :parse_expr_condition, jses, exprs
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module XRayTest
|
|
2
|
+
module JS
|
|
3
|
+
module Expr
|
|
4
|
+
|
|
5
|
+
module LeftHand
|
|
6
|
+
|
|
7
|
+
def test_parse_expr_member
|
|
8
|
+
jses = [
|
|
9
|
+
'abc[123].bcd[hello]["hello"]',
|
|
10
|
+
'abc(1, abc, "hello", /hello/, 11.10)[hello].abc["bcd"](1, 2, 3)'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
exprs = [
|
|
14
|
+
'([,([,(.,([,abc,123),bcd),hello),"hello")',
|
|
15
|
+
'((,([,(.,([,((,abc,[1,abc,"hello",/hello/,11.10]),hello),abc),"bcd"),[1,2,3])'
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
add_test :parse_expr_member, jses, exprs
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|