fdlint 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,22 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
module XRayTest
|
4
|
+
module HTML
|
5
|
+
module Parser
|
6
|
+
|
7
|
+
class ParseWithStyleTagTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include XRay::HTML
|
10
|
+
|
11
|
+
def test_parse_style
|
12
|
+
text = %q(<style id=gstyle>body{margin:0;overflow-y:scroll}#gog{padding:3px 8px 0}td{line-height:.8em}.gac_m td{line-height:17px}form{margin-top:10px;margin-bottom:20px}body,td,a,p,.h{font-family:arial,sans-serif}.h{color:#36c}.q{color:#00c}.ts td{padding:0}.ts{border-collapse:collapse}em{color:#c03;font-style:normal;font-weight:normal}a em{text-decoration:underline}.lst{height:25px;width:496px}#lst-ib:hover{border-color:#a0a0a0 #b9b9b9 #b9b9b9 #b9b9b9!important;}#lst-ib.lst-d-f,#lst-ib:hover.lst-d-f{border-color:#4d90fe!important;}.gsfi,.lst{font:18px arial,sans-serif}.gsfs{font:17px arial,sans-serif}.ds{display:-moz-inline-box;display:inline-block;margin:3px 0 4px;margin-left:4px}.jhp input[type="submit"],.gssb_c input,.gac_bt input{background-image:-webkit-gradient(linear,left top,left bottom,from(#f5f5f5),to(#f1f1f1));background-image:-webkit-linear-gradient(top,#f5f5f5,#f1f1f1);-webkit-border-radius:2px;-webkit-user-select:none;background-color:#f5f5f5;background-image:linear-gradient(top,#f5f5f5,#f1f1f1);background-image:-o-linear-gradient(top,#f5f5f5,#f1f1f1);border:1px solid #dcdcdc;border:1px solid rgba(0, 0, 0, 0.1);border-radius:2px;color:#666;cursor:pointer;font-size:11px;font-weight:bold;height:29px;line-height:27px;margin:11px 6px;min-width:54px;padding:0 8px;text-align:center}.jhp input[type="submit"]:hover,.gssb_c input:hover,.gac_bt input:hover{background-image:-webkit-gradient(linear,left top,left bottom,from(#f8f8f8),to(#f1f1f1));background-image:-webkit-linear-gradient(top,#f8f8f8,#f1f1f1);-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.1);background-color:#f8f8f8;background-image:linear-gradient(top,#f8f8f8,#f1f1f1);background-image:-o-linear-gradient(top,#f8f8f8,#f1f1f1);border:1px solid #c6c6c6;box-shadow:0 1px 1px rgba(0,0,0,0.1);color:#333}.jhp input[type="submit"]:focus,.gssb_c input:focus,.gac_bt input:focus{border:1px solid #4d90fe;outline:none}.gssb_c input,.gac_bt input{margin:6px;}input{font-family:inherit}.lsb:active,.gac_sb:active{background:-webkit-gradient(linear,left top,left bottom,from(#ccc),to(#ddd))}a.gb1,a.gb2,a.gb3,a.gb4{color:#11c !important}#gog{background:#fff}#gbar,#guser{font-size:13px;padding-top:1px !important}#gbar{float:left;height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}#gbs,.gbm{background:#fff;left:0;position:absolute;text-align:left;visibility:hidden;z-index:1000}.gbm{border:1px solid;border-color:#c9d7f1 #36c #36c #a2bae7;z-index:1001}.gb1{margin-right:.5em}.gb1,.gb3{zoom:1}.gb2{display:block;padding:.2em .5em}.gb2,.gb3{text-decoration:none !important;border-bottom:none}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb2,a.gb3,a.gb4{color:#00c !important}a.gb2:hover{background:#36c;color:#fff !important}#gbar .gbz0l{color:#000 !important;cursor:default;font-weight:bold;text-decoration:none !important}body{background:#fff;color:black}input{-moz-box-sizing:content-box}a{color:#11c;text-decoration:none}a:hover,a:active{text-decoration:underline}.fl a{color:#36c}a:visited{color:#551a8b}a.gb1,a.gb4{text-decoration:underline}a.gb3:hover{text-decoration:none}#ghead a.gb2:hover{color:#fff!important}.sblc{padding-top:5px}.sblc a{display:block;margin:2px 0;margin-left:13px;font-size:11px;}.lsbb{height:30px;display:block}.ftl,#footer a{color:#2200c1;}#fll a, .ftl{margin: 0 8px;}#fll{display:inline}.lsb{border:none;color:#000;cursor:pointer;height:30px;margin:0;outline:0;font:15px arial,sans-serif;vertical-align:top}.lsb:active{background:#ccc}.lst:focus{outline:none}#addlang a{padding:0 3px}.gac_v div{display:none}.gac_v .gac_v2,.gac_bt{display:block!important}#footer{color:#666;font-size:10pt;min-height:49px;min-width:780px;position:relative}#footer #cp-sol{margin-right:52px;}</style>)
|
13
|
+
XRay::HTML::Parser.parse(text) do |e|
|
14
|
+
assert_equal text, e.outer_html
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
module XRayTest
|
4
|
+
module HTML
|
5
|
+
module Parser
|
6
|
+
|
7
|
+
class ParseWithTextTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include XRay::HTML
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@parser = XRay::HTML::Parser.new('information')
|
13
|
+
@element = @parser.parse
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_type_is_element
|
17
|
+
assert @element.is_a?(TextElement)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_have_no_child
|
21
|
+
assert_equal 0, @element.children.length
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_has_text
|
25
|
+
assert_equal 'information', @element.inner_text
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_has_html_text
|
29
|
+
assert_equal 'information', @element.inner_html
|
30
|
+
assert_equal 'information', @element.outer_html
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_with_lt_mark
|
34
|
+
assert_equal TextElement.new('1 < 3 > 2'), XRay::HTML::Parser.parse('1 < 3 > 2')
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_with_and_mark
|
38
|
+
assert_equal TextElement.new('1 < 3 > 2'), XRay::HTML::Parser.parse('1 < 3 > 2')
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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 'parser/parse_comment_test'
|
7
|
+
require_relative 'parser/parse_with_auto_close_tag_test'
|
8
|
+
require_relative 'parser/parse_with_emtpy_test'
|
9
|
+
require_relative 'parser/parse_with_multi_children_test'
|
10
|
+
require_relative 'parser/parse_with_multi_line_test'
|
11
|
+
require_relative 'parser/parse_with_simple_tag_test'
|
12
|
+
require_relative 'parser/parse_with_simple_tree_test'
|
13
|
+
require_relative 'parser/parse_with_selfclosing_test'
|
14
|
+
require_relative 'parser/parse_with_text_test'
|
15
|
+
require_relative 'parser/parse_with_prop_test'
|
16
|
+
require_relative 'parser/parse_with_script_tag_test'
|
17
|
+
require_relative 'parser/parse_with_style_tag_test'
|
18
|
+
require_relative 'parser/parse_with_diff_case_test'
|
19
|
+
require_relative 'parser/parse_dtd_test'
|
20
|
+
require_relative 'parser/parse_script_tag_test'
|
21
|
+
|
22
|
+
module XRayTest
|
23
|
+
|
24
|
+
module HTML
|
25
|
+
|
26
|
+
class ParserTest < Test::Unit::TestSuite
|
27
|
+
|
28
|
+
def self.suite
|
29
|
+
tests = Test::Unit::TestSuite.new
|
30
|
+
tests << Parser::ParseCommentTest.suite
|
31
|
+
tests << Parser::ParseWithAutoCloseTagTest.suite
|
32
|
+
tests << Parser::ParseWithEmptyTest.suite
|
33
|
+
tests << Parser::ParseWithMultiChildrenTest.suite
|
34
|
+
tests << Parser::ParseWithMultiLineTest.suite
|
35
|
+
tests << Parser::ParseWithSelfClosingTagTest.suite
|
36
|
+
tests << Parser::ParseWithSimpleTagTest.suite
|
37
|
+
tests << Parser::ParseWithSimpleTreeTest.suite
|
38
|
+
tests << Parser::ParsePropertyTest.suite
|
39
|
+
tests << Parser::ParseWithTextTest.suite
|
40
|
+
tests << Parser::ParseWithScriptTagTest.suite
|
41
|
+
tests << Parser::ParseWithStyleTagTest.suite
|
42
|
+
tests << Parser::ParseWithDiffCaseTest.suite
|
43
|
+
tests << Parser::ParseDTDTest.suite
|
44
|
+
tests << Parser::ParseScriptTagTest.suite
|
45
|
+
tests
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Test::Unit::UI::Console::TestRunner.run( XRayTest::HTML::ParserTest ) if __FILE__ == $0
|
52
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'html/parser'
|
3
|
+
require 'html/query'
|
4
|
+
|
5
|
+
module XRayTest
|
6
|
+
module HTML
|
7
|
+
|
8
|
+
class QueryTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
include XRay::HTML
|
11
|
+
|
12
|
+
def test_query_with_tag_name
|
13
|
+
assert Element.new('div') === 'div'
|
14
|
+
assert Element.new('a', {:href=>'#'}) === 'a'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_query_with_id
|
18
|
+
assert Element.new('div', { :id => 'info' }) === '#info'
|
19
|
+
assert Element.new('div', { :id => 'info' }) === 'div#info'
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_query_with_class
|
23
|
+
assert Element.new('div', { :class => 'info' }) === '.info'
|
24
|
+
assert Element.new('div', { :id => 'info-1', :class => 'info' }) === '#info-1.info'
|
25
|
+
assert Element.new('div', { :id => 'info-1', :class => 'info' }) === '.info#info-1'
|
26
|
+
assert Element.new('div', { :id => 'info-1', :class => 'info' }) === 'div.info#info-1'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_query_with_prop
|
30
|
+
assert Element.new('div', { :class => 'info' }) === 'div[class==info]'
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_deep_query
|
34
|
+
el = ::XRay::HTML::Parser.parse(%Q{<div class="mod">
|
35
|
+
<div>
|
36
|
+
<ul>
|
37
|
+
<li></li>
|
38
|
+
<li></li>
|
39
|
+
</ul>
|
40
|
+
</div>
|
41
|
+
</div>})
|
42
|
+
|
43
|
+
assert_equal 2, el.query('li').length
|
44
|
+
assert_equal 2, el.query('div').length
|
45
|
+
assert_equal 1, el.query('ul').length
|
46
|
+
assert_equal 5, el.query('*').length
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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 CheckBlockLevelElementTest < 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 = 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)
|
25
|
+
end
|
26
|
+
|
27
|
+
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)
|
34
|
+
end
|
35
|
+
|
36
|
+
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)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,45 @@
|
|
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 CheckButtonTest < 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
|
+
src = %q(<button type="button" name="usernmae" />
|
20
|
+
<button type="submit" name="male" />
|
21
|
+
<button type="reset" name="food" />)
|
22
|
+
XRay::HTML::Parser.parse(src).each do |tag|
|
23
|
+
assert_equal [], @rule.check_html_tag(tag)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_check_missing_name
|
28
|
+
src = %q(<input type="button" value="btn" />
|
29
|
+
<input type="submit" name="submit" value="submit"/>
|
30
|
+
<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)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
@@ -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 CheckClassCountTest < 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('class', 'info')
|
18
|
+
assert_equal [], @rule.check_html_property(prop)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_check_too_many_classes
|
22
|
+
prop = XRay::HTML::Property.new('class', 'info new red bigger')
|
23
|
+
expected = ["一个节点上定义的class个数最多不超过3个(不含lib中的class)", :error]
|
24
|
+
assert_equal [expected], @rule.check_html_property(prop)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_check_filter_fdev_classes
|
28
|
+
prop = XRay::HTML::Property.new('class', 'info new red fd-main w952 layout grid layout- grid-')
|
29
|
+
assert_equal [], @rule.check_html_property(prop)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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 CheckCSSInHeadTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_check_alone_css_tag
|
17
|
+
tag = css_link('test.css')
|
18
|
+
assert_equal [], @rule.check_html_tag(tag)
|
19
|
+
end
|
20
|
+
|
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
|
32
|
+
|
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样式)"
|
37
|
+
end
|
38
|
+
assert_equal 1, found.size
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
def css_link(src)
|
43
|
+
XRay::HTML::Element.new('link', {:rel => 'stylesheet', :href=>src}, [], :self)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
@@ -0,0 +1,46 @@
|
|
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 CheckDTDTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_check_html5_dtd
|
17
|
+
tag = XRay::HTML::DTDElement.new('html')
|
18
|
+
assert_equal [], @rule.check_html_dtd(tag)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_check_xhtml_dtd
|
22
|
+
src = %q(html
|
23
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
24
|
+
"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)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_check_doctype_upcase
|
30
|
+
tag = XRay::HTML::DTDElement.new('html', 'doctype')
|
31
|
+
assert_equal [['必须使用大写的"DOCTYPE"', :warn]], @rule.check_html_dtd(tag)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_check_dtd_available
|
35
|
+
doc = XRay::HTML::Parser.new('<html><body></body></html>')
|
36
|
+
assert @rule.check_html_doc(doc).include?(['必须存在文档类型声明', :error])
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
@@ -0,0 +1,49 @@
|
|
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 CheckFormElementNameTest < 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
|
+
src = %q(<input type="text" name="usernmae" />
|
20
|
+
<input type="radio" name="male" />
|
21
|
+
<input type="checkbox" name="food" />
|
22
|
+
<textarea name="bio">test</textarea>
|
23
|
+
<select name="city"></select>)
|
24
|
+
XRay::HTML::Parser.parse(src).each do |tag|
|
25
|
+
assert_equal [], @rule.check_html_tag(tag)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_check_missing_name
|
30
|
+
src = %q(<input type="text" />
|
31
|
+
<input type="radio" name="" />
|
32
|
+
<input type="checkbox" />
|
33
|
+
<textarea>test</textarea>
|
34
|
+
<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)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
@@ -0,0 +1,52 @@
|
|
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 CheckHeadTest < Test::Unit::TestCase
|
11
|
+
|
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)
|
39
|
+
end
|
40
|
+
|
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)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,103 @@
|
|
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 CheckHTMLTemplateTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
include XRay::HTML
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
16
|
+
@head = %Q(<head>
|
17
|
+
<meta charset="gbk"/>
|
18
|
+
<title>阿里巴巴</title>
|
19
|
+
<mea name="description" content="阿里巴巴批发大市场"/>
|
20
|
+
<meta name="keywords" content="阿里巴巴,采购批发,1688,行业门户,网上贸易,b2b,电子商务"/>
|
21
|
+
<link href="产品线merge.css" rel="stylesheet"/>
|
22
|
+
<link href="页面merge.css" rel="stylesheet"/>
|
23
|
+
<script src="产品线merge.js"></script>
|
24
|
+
<base target="_blank"/>
|
25
|
+
</head>)
|
26
|
+
@doc = %Q(<div id="doc">
|
27
|
+
<div id="alibar">alibar</div>
|
28
|
+
<div id="header" class="w952">header</div>
|
29
|
+
<div id="content" class="w952">content</div>
|
30
|
+
<div id="footer">footer</div>
|
31
|
+
</div>)
|
32
|
+
@body = %Q(<body>
|
33
|
+
#{@doc}
|
34
|
+
<script src="页面merge.js"></script>
|
35
|
+
</body>)
|
36
|
+
@html = %Q(<html lang="zh-CN">
|
37
|
+
#{@head}
|
38
|
+
#{@body}
|
39
|
+
</html>)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_check_right_tag
|
43
|
+
tag = parse(@html)
|
44
|
+
assert_equal [], @rule.check_html_tag(tag)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_check_missing_desc
|
48
|
+
tag = parse(@head.sub(/<meta name="description".*?\/>/m, ''))
|
49
|
+
assert_equal [["新页面按库中的HTML基本结构模板书写基本页面结构", :warn]], @rule.check_html_tag(tag)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_check_missing_keywords
|
53
|
+
tag = parse(@head.sub(/<meta name="keywords".*?\/>/m, ''))
|
54
|
+
assert_equal [["新页面按库中的HTML基本结构模板书写基本页面结构", :warn]], @rule.check_html_tag(tag)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_check_missing_doc
|
58
|
+
tag = parse(@body.sub(/<div id="doc"/m, '<div id="_doc"'))
|
59
|
+
assert_equal [["新页面按库中的HTML基本结构模板书写基本页面结构", :warn]], @rule.check_html_tag(tag)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_check_missing_alibar
|
63
|
+
tag = parse(@body.sub(/<div id="alibar"/m, '<div id="_alibar"'))
|
64
|
+
assert_equal [], @rule.check_html_tag(tag)
|
65
|
+
|
66
|
+
tag = parse(@doc.sub(/<div id="alibar"/m, '<div id="_alibar"'))
|
67
|
+
assert_equal [["新页面按库中的HTML基本结构模板书写基本页面结构", :warn]], @rule.check_html_tag(tag)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_check_missing_content
|
71
|
+
tag = parse(@body.sub(/<div id="content"/m, '<div id="_content"'))
|
72
|
+
assert_equal [], @rule.check_html_tag(tag)
|
73
|
+
|
74
|
+
tag = parse(@doc.sub(/<div id="content"/m, '<div id="_content"'))
|
75
|
+
assert_equal [["新页面按库中的HTML基本结构模板书写基本页面结构", :warn]], @rule.check_html_tag(tag)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_check_missing_footer
|
79
|
+
tag = parse(@body.sub(/<div id="footer"/m, '<div id="_footer"'))
|
80
|
+
assert_equal [], @rule.check_html_tag(tag)
|
81
|
+
|
82
|
+
tag = parse(@doc.sub(/<div id="footer"/m, '<div id="_footer"'))
|
83
|
+
assert_equal [["新页面按库中的HTML基本结构模板书写基本页面结构", :warn]], @rule.check_html_tag(tag)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_check_missing_header
|
87
|
+
tag = parse(@body.sub(/<div id="header"/m, '<div id="_header"'))
|
88
|
+
assert_equal [], @rule.check_html_tag(tag)
|
89
|
+
|
90
|
+
tag = parse(@doc.sub(/<div id="header"/m, '<div id="_header"'))
|
91
|
+
assert_equal [["新页面按库中的HTML基本结构模板书写基本页面结构", :warn]], @rule.check_html_tag(tag)
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
def parse(src)
|
96
|
+
XRay::HTML::Parser.parse(src)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -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 CheckHyperlinkWithTargetTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
+
end
|
15
|
+
|
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
|
20
|
+
|
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
|
25
|
+
|
26
|
+
def test_when_html_has_base_tag
|
27
|
+
@rule.check_html_tag XRay::HTML::Element.new('base', {:target=>'_self'})
|
28
|
+
|
29
|
+
tag = XRay::HTML::Element.new('a', {:href=>'#nogo'})
|
30
|
+
assert_equal [], @rule.check_html_tag(tag)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|