fdlint 0.2.0.pre → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +36 -15
- data/Rakefile +1 -1
- data/bin/fdlint +30 -9
- data/lib/fdlint/cli.rb +62 -10
- data/lib/fdlint/helper/logger.rb +1 -1
- data/lib/fdlint/log_entry.rb +14 -0
- data/lib/fdlint/parser/html/html_parser.rb +10 -12
- data/lib/fdlint/parser/html/query.rb +64 -50
- data/lib/fdlint/parser/html/struct.rb +20 -3
- data/lib/fdlint/parser/parser_visitable.rb +11 -5
- data/lib/fdlint/printer/base_printer.rb +6 -0
- data/lib/fdlint/printer/console_printer.rb +15 -23
- data/lib/fdlint/rule.rb +4 -4
- data/lib/fdlint/support/core/object.rb +6 -0
- data/lib/fdlint/support/core_ext.rb +1 -0
- data/lib/fdlint/validator.rb +60 -8
- data/lib/fdlint/version.rb +1 -1
- data/lib/hook/git_pre_commit +18 -0
- data/rules.d/css.rule.rb +1 -1
- data/rules.d/filename.rule.rb +3 -1
- data/rules.d/html.rule.rb +45 -32
- data/rules.d/js.rule.rb +2 -2
- data/test/all_tests.rb +28 -42
- data/test/css/mac_line_end_support_test.rb +10 -12
- data/test/css/parser_test.rb +4 -5
- data/test/css/rule/check_encoding_test.rb +7 -8
- data/test/css/rule/check_list_rule_test.rb +85 -102
- data/test/css/rule/file_name_test.rb +18 -39
- data/test/default_test.rb +1 -14
- data/test/fixtures/css/ad.css +0 -0
- data/test/fixtures/css/adver/test.css +0 -0
- data/test/fixtures/css/camelCase.css +0 -0
- data/test/fixtures/css/min/ad.css +0 -0
- data/test/fixtures/css/min/ad.min.css +0 -0
- data/test/fixtures/html/mixed_log_levels.html +1 -0
- data/test/fixtures/html/mixed_types.html +3 -0
- data/test/helper.rb +116 -16
- data/test/html/mixed_type_test.rb +14 -20
- data/test/html/parser/parse_comment_test.rb +4 -4
- data/test/html/parser/parse_dtd_test.rb +7 -7
- data/test/html/parser/parse_script_tag_test.rb +21 -14
- data/test/html/parser/parse_with_auto_close_tag_test.rb +12 -10
- data/test/html/parser/parse_with_diff_case_test.rb +8 -9
- data/test/html/parser/parse_with_emtpy_test.rb +5 -3
- data/test/html/parser/parse_with_multi_children_test.rb +4 -4
- data/test/html/parser/parse_with_multi_line_test.rb +5 -5
- data/test/html/parser/parse_with_prop_test.rb +10 -10
- data/test/html/parser/parse_with_script_tag_test.rb +4 -4
- data/test/html/parser/parse_with_selfclosing_test.rb +11 -11
- data/test/html/parser/parse_with_simple_tag_test.rb +7 -7
- data/test/html/parser/parse_with_simple_tree_test.rb +6 -6
- data/test/html/parser/parse_with_style_tag_test.rb +4 -4
- data/test/html/parser/parse_with_text_test.rb +7 -7
- data/test/html/parser_test.rb +19 -19
- data/test/html/query_test.rb +18 -18
- data/test/html/rule/check_block_level_element_test.rb +22 -24
- data/test/html/rule/check_button_test.rb +9 -9
- data/test/html/rule/check_css_in_head_test.rb +11 -32
- data/test/html/rule/check_dtd_test.rb +15 -11
- data/test/html/rule/check_form_element_name_test.rb +10 -9
- data/test/html/rule/check_head_contain_meta_and_title_test.rb +28 -34
- data/test/html/rule/check_hyperlink_with_target_test.rb +23 -17
- data/test/html/rule/check_hyperlink_with_title_test.rb +13 -20
- data/test/html/rule/check_id_n_class_downcase_test.rb +8 -19
- data/test/html/rule/check_img_with_alt_prop_test.rb +11 -12
- data/test/html/rule/check_no_import_css_test.rb +20 -20
- data/test/html/rule/check_prop_have_value_test.rb +9 -13
- data/test/html/rule/check_prop_seperator_test.rb +9 -13
- data/test/html/rule/check_style_prop_test.rb +7 -12
- data/test/html/rule/check_tag_closed_test.rb +15 -40
- data/test/html/rule/check_tag_downcase_test.rb +31 -28
- data/test/html/rule/check_unescape_char_test.rb +17 -17
- data/test/html/rule/check_unique_import_test.rb +15 -33
- data/test/html/rule_test.rb +2 -6
- data/test/js/expr/expr.rb +1 -1
- data/test/js/expr/left_hand.rb +1 -1
- data/test/js/expr/operate.rb +1 -1
- data/test/js/expr/primary.rb +1 -1
- data/test/js/parser_test.rb +3 -6
- data/test/js/rule/alert_check_test.rb +5 -19
- data/test/js/rule/base_test.rb +5 -19
- data/test/js/rule/jq_check_test.rb +26 -58
- data/test/js/rule/nest_try_catch_test.rb +26 -43
- data/test/js/rule/new_object_and_new_array_test.rb +5 -21
- data/test/js/rule/no_eval_test.rb +3 -19
- data/test/js/rule/no_global_test.rb +34 -73
- data/test/js/rule/private_method_check_test.rb +14 -43
- data/test/js/rule/semicolon_test.rb +18 -47
- data/test/js/rule/stat_if_with_brace_test.rb +30 -53
- data/test/js/rule/stat_if_with_muti_else_test.rb +36 -53
- data/test/js/rule/use_strict_equal_test.rb +16 -29
- data/test/js/rule_test.rb +2 -4
- data/test/js/stat/if.rb +1 -1
- data/test/js/stat/iter.rb +1 -1
- data/test/js/stat/stat.rb +1 -1
- data/test/js/stat/switch.rb +1 -1
- data/test/js/stat/try.rb +1 -1
- data/test/js/stat/var.rb +1 -1
- data/test/parser_visitable_test.rb +14 -36
- data/test/position_info_test.rb +4 -5
- data/test/runner/log_level_test.rb +30 -25
- metadata +11 -14
- data/lib/fdlint/file_validator.rb +0 -38
- data/lib/fdlint/parser/html/rule/check_tag_rule.rb +0 -80
- data/test/css/rule/compression_test.rb +0 -53
- data/test/html/rule/check_class_count_test.rb +0 -36
- data/test/html/rule/check_html_template_test.rb +0 -103
- data/test/js/rule/all_test.rb +0 -23
- data/test/js/rule/file_checker_test.rb +0 -131
- data/test/rule_dsl/dsl_basic_test.rb +0 -91
- data/test/rule_dsl/importing_test.rb +0 -48
- data/test/test_helper.rb +0 -9
@@ -1,18 +1,20 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseScriptTagTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
10
|
+
|
11
11
|
def test_simple_script
|
12
12
|
parse('<script>alert("hello");</script>') do |element|
|
13
|
-
assert_equal
|
14
|
-
|
15
|
-
|
13
|
+
assert_equal Document.new(
|
14
|
+
Element.new('script', nil, [
|
15
|
+
TextElement.new('alert("hello");')
|
16
|
+
])
|
17
|
+
), element
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -24,7 +26,9 @@ module XRayTest
|
|
24
26
|
src = %Q(<script type="text/javascript">#{script}</script>)
|
25
27
|
|
26
28
|
parse(src) do |e|
|
27
|
-
assert_equal
|
29
|
+
assert_equal Document.new(
|
30
|
+
Element.new('script', {:type=>"text/javascript"}, [ TextElement.new(script) ])
|
31
|
+
), e
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -36,17 +40,20 @@ module XRayTest
|
|
36
40
|
src = %Q(<head><script type="text/javascript">#{script}</script> </head>)
|
37
41
|
|
38
42
|
parse(src) do |e|
|
39
|
-
assert_equal
|
40
|
-
Element.new('
|
41
|
-
|
42
|
-
|
43
|
+
assert_equal Document.new(
|
44
|
+
Element.new('head', nil, [
|
45
|
+
Element.new('script', {:type=>"text/javascript"}, [ TextElement.new(script) ]),
|
46
|
+
TextElement.new(' ')
|
47
|
+
])
|
48
|
+
), e
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
46
52
|
protected
|
47
|
-
|
48
|
-
|
49
|
-
|
53
|
+
|
54
|
+
def parse(src, &block)
|
55
|
+
Fdlint::Parser::HTML::HtmlParser.parse(src, &block)
|
56
|
+
end
|
50
57
|
|
51
58
|
end
|
52
59
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithAutoCloseTagTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
9
|
+
include Fdlint::Parser::HTML
|
10
10
|
|
11
11
|
%w(area base basefont br col frame hr img input link meta param).each do |tag|
|
12
12
|
define_method("test_#{tag}_tag") { check_tag tag }
|
@@ -15,14 +15,16 @@ module XRayTest
|
|
15
15
|
|
16
16
|
def test_manual_close
|
17
17
|
src = %q(<div class="main"><input type="hidden" name="next_page" value="/dashboard/" ></input></div>)
|
18
|
-
|
19
|
-
assert_equal
|
20
|
-
Element.new('
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
HtmlParser.parse(src) do |e|
|
19
|
+
assert_equal Document.new(
|
20
|
+
Element.new('div', {:class => 'main'}, [
|
21
|
+
Element.new('input', [
|
22
|
+
Property.new(:type, 'hidden'),
|
23
|
+
Property.new(:name, 'next_page'),
|
24
|
+
Property.new(:value, '/dashboard/')
|
25
|
+
])
|
24
26
|
])
|
25
|
-
|
27
|
+
), e
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -30,7 +32,7 @@ module XRayTest
|
|
30
32
|
assert_equal Document.new([
|
31
33
|
Element.new( name, {:name => 'test'}),
|
32
34
|
TextElement.new(' text' )
|
33
|
-
]),
|
35
|
+
]), HtmlParser.parse("<#{name} name=\"test\"> text"),
|
34
36
|
"TAG: #{name} will auto close and have no children"
|
35
37
|
end
|
36
38
|
|
@@ -1,25 +1,24 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithDiffCaseTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
11
10
|
def setup
|
12
|
-
@parser =
|
11
|
+
@parser = HtmlParser.new('<div class="info">information</DIV>')
|
13
12
|
@element = @parser.parse
|
14
13
|
end
|
15
14
|
|
16
15
|
def test_is_a_div_element
|
17
|
-
assert @element.is_a?(
|
18
|
-
assert_equal @element.tag_name, 'div'
|
16
|
+
assert @element.is_a?(Document)
|
17
|
+
assert_equal @element.children.first.tag_name, 'div'
|
19
18
|
end
|
20
19
|
|
21
20
|
def test_have_one_child
|
22
|
-
assert_equal [TextElement.new('information')], @element.children
|
21
|
+
assert_equal [TextElement.new('information')], @element.children.first.children
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_has_text
|
@@ -27,8 +26,8 @@ module XRayTest
|
|
27
26
|
end
|
28
27
|
|
29
28
|
def test_has_html_text
|
30
|
-
assert_equal @element.inner_html, 'information'
|
31
|
-
assert_equal @element.outer_html, '<div class="info">information</DIV>'
|
29
|
+
assert_equal @element.children.first.inner_html, 'information'
|
30
|
+
assert_equal @element.children.first.outer_html, '<div class="info">information</DIV>'
|
32
31
|
end
|
33
32
|
|
34
33
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithEmptyTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include Fdlint::Parser::HTML
|
8
10
|
|
9
11
|
def setup
|
10
|
-
@parser =
|
12
|
+
@parser = HtmlParser.new('')
|
11
13
|
@element = @parser.parse
|
12
14
|
end
|
13
15
|
|
14
16
|
def test_type_is_nil
|
15
|
-
assert_equal @element,
|
17
|
+
assert_equal @element, Document.new
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithMultiChildrenTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
include
|
8
|
+
|
9
|
+
include Fdlint::Parser::HTML
|
10
10
|
|
11
11
|
def setup
|
12
|
-
@parser =
|
12
|
+
@parser = HtmlParser.new('<em>important</em> information!! Attention please!')
|
13
13
|
@element = @parser.parse
|
14
14
|
end
|
15
15
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithMultiLineTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
include
|
8
|
+
|
9
|
+
include Fdlint::Parser::HTML
|
10
10
|
|
11
11
|
def setup
|
12
12
|
src = %q(<div
|
13
13
|
class="info"
|
14
14
|
>information</div>)
|
15
|
-
@parser =
|
16
|
-
@element = @parser.parse
|
15
|
+
@parser = HtmlParser.new(src)
|
16
|
+
@element = @parser.parse.children.first
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_is_a_div_element
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require File.expand_path('../../helper', File.dirname(__FILE__))
|
2
2
|
require_relative '../../helper'
|
3
3
|
|
4
|
-
module
|
4
|
+
module FdlintTest
|
5
5
|
module HTML
|
6
6
|
module Parser
|
7
7
|
|
8
8
|
class ParsePropertyTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
include
|
9
|
+
|
10
|
+
include Fdlint::Parser::HTML
|
11
11
|
|
12
12
|
def test_data_prop
|
13
13
|
parse('<div class="info" data-creater="vim">information</div>') do |element|
|
@@ -16,7 +16,7 @@ module XRayTest
|
|
16
16
|
Property.new('data-creater', 'vim')
|
17
17
|
], [
|
18
18
|
TextElement.new('information')
|
19
|
-
]), element
|
19
|
+
]), element.children.first
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -30,7 +30,7 @@ module XRayTest
|
|
30
30
|
Property.new('alink', '#ff0000', ''),
|
31
31
|
Property.new('onload', %q(try{!google.j.b&&document.f.q.focus()}catch(e){};if(document.images)new Image().src='/images/experiments/nav_logo78.png'), '"')
|
32
32
|
]
|
33
|
-
assert_equal Element.new('body', props), e
|
33
|
+
assert_equal Element.new('body', props), e.children.first
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -40,7 +40,7 @@ module XRayTest
|
|
40
40
|
Property.new(:type, 'checkbox'),
|
41
41
|
Property.new(:name, 'agreement'),
|
42
42
|
Property.new(:checked, nil)
|
43
|
-
]), e
|
43
|
+
]), e.children.first
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ module XRayTest
|
|
51
51
|
Property.new(:type, 'checkbox'),
|
52
52
|
Property.new(:name, 'agreement'),
|
53
53
|
Property.new(:checked, nil)
|
54
|
-
]), e
|
54
|
+
]), e.children.first
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -68,18 +68,18 @@ module XRayTest
|
|
68
68
|
Property.new('ns:name', 'checkbox'),
|
69
69
|
Property.new(:name, 'agreement'),
|
70
70
|
Property.new(:checked, nil)
|
71
|
-
]), e
|
71
|
+
]), e.children.first
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_parse_invalid_prop_syntax
|
76
|
-
assert_raise(
|
76
|
+
assert_raise(Fdlint::Parser::ParseError) do
|
77
77
|
parse %Q(<a href="#"title="title\n">link test</a>)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
def parse(src, &block)
|
82
|
-
|
82
|
+
HtmlParser.parse(src, &block)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithScriptTagTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
10
|
+
|
11
11
|
def test_parse_script
|
12
12
|
text = %q(<script>(function(){
|
13
13
|
var b,d,e,f;function g(a,c){if(a.removeEventListener){a.removeEventListener("load",c,false);a.removeEventListener("error",c,false)}else{a.detachEvent("onload",c);a.detachEvent("onerror",c)}}function h(a){f=(new Date).getTime();++d;a=a||window.event;var c=a.target||a.srcElement;g(c,h)}var i=document.getElementsByTagName("img");b=i.length;d=0;for(var j=0,k;j<b;++j){k=i[j];if(k.complete||typeof k.src!="string"||!k.src)++d;else if(k.addEventListener){k.addEventListener("load",h,false);k.addEventListener("error",
|
14
14
|
h,false)}else{k.attachEvent("onload",h);k.attachEvent("onerror",h)}}e=b-d;function l(){if(!google.timers.load.t)return;google.timers.load.t.ol=(new Date).getTime();google.timers.load.t.iml=f;google.kCSI.imc=d;google.kCSI.imn=b;google.kCSI.imp=e;google.timers.load.t.xjs&&google.report&&google.report(google.timers.load,google.kCSI)}if(window.addEventListener)window.addEventListener("load",l,false);else if(window.attachEvent)window.attachEvent("onload",l);google.timers.load.t.prt=(f=(new Date).getTime());
|
15
15
|
})();
|
16
16
|
</script>)
|
17
|
-
|
17
|
+
HtmlParser.parse(text) do |e|
|
18
18
|
assert_equal text, e.outer_html
|
19
19
|
end
|
20
20
|
end
|
@@ -1,34 +1,34 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithSelfClosingTagTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
10
|
+
|
11
11
|
def test_self_close
|
12
|
-
|
13
|
-
assert_equal Element.new('div', {:class=>"info"}), e
|
12
|
+
HtmlParser.parse('<div class="info" />') do |e|
|
13
|
+
assert_equal Element.new('div', {:class=>"info"}), e.children.first
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_br_tag_closed_without_space
|
18
|
-
|
19
|
-
assert_equal Element.new('br'), e
|
18
|
+
HtmlParser.parse('<br/>') do |e|
|
19
|
+
assert_equal Element.new('br'), e.children.first
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_close_outside
|
24
|
-
|
25
|
-
assert_equal Element.new('div', {:class=>"info"}), e
|
24
|
+
HtmlParser.parse('<div class="info" ></div>') do |e|
|
25
|
+
assert_equal Element.new('div', {:class=>"info"}), e.children.first
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_center_tag
|
30
|
-
|
31
|
-
assert_equal Element.new('center'), e
|
30
|
+
HtmlParser.parse('<center></center>') do |e|
|
31
|
+
assert_equal Element.new('center'), e.children.first
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithSimpleTagTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
10
|
+
|
11
11
|
def setup
|
12
|
-
@parser =
|
13
|
-
@element = @parser.parse
|
12
|
+
@parser = HtmlParser.new('<div class="info">information</div>')
|
13
|
+
@element = @parser.parse.children.first
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_is_a_div_element
|
@@ -32,8 +32,8 @@ module XRayTest
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_raise_error_on_invalid_tag_name
|
35
|
-
assert_raise(
|
36
|
-
|
35
|
+
assert_raise(Fdlint::Parser::ParseError) do
|
36
|
+
HtmlParser.new('<tag(name) />').parse
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithSimpleTreeTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
10
|
+
|
11
11
|
def test_simple_tree
|
12
12
|
parse('<div><em>important</em> information!! Attention please!</div>') do |element|
|
13
13
|
assert_equal Element.new('div', nil, [
|
14
14
|
Element.new('em', nil, [TextElement.new('important')]),
|
15
15
|
TextElement.new(' information!! Attention please!')
|
16
|
-
]), element, 'must contain two children'
|
16
|
+
]), element.children.first, 'must contain two children'
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -24,13 +24,13 @@ module XRayTest
|
|
24
24
|
Element.new('em', nil, [TextElement.new('important')]),
|
25
25
|
TextElement.new(' information!! Attention please!')
|
26
26
|
])
|
27
|
-
]), element, 'must contain two children'
|
27
|
+
]), element.children.first, 'must contain two children'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
protected
|
32
32
|
def parse(src, &block)
|
33
|
-
|
33
|
+
HtmlParser.parse(src, &block)
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithStyleTagTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
10
|
+
|
11
11
|
def test_parse_style
|
12
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
|
-
|
13
|
+
HtmlParser.parse(text) do |e|
|
14
14
|
assert_equal text, e.outer_html
|
15
15
|
end
|
16
16
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseWithTextTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
10
|
+
|
11
11
|
def setup
|
12
|
-
@parser =
|
13
|
-
@element = @parser.parse
|
12
|
+
@parser = HtmlParser.new('information')
|
13
|
+
@element = @parser.parse.children.first
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_type_is_element
|
@@ -31,11 +31,11 @@ module XRayTest
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_with_lt_mark
|
34
|
-
assert_equal TextElement.new('1 < 3 > 2'),
|
34
|
+
assert_equal TextElement.new('1 < 3 > 2'), HtmlParser.parse('1 < 3 > 2')
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_with_and_mark
|
38
|
-
assert_equal TextElement.new('1 < 3 > 2'),
|
38
|
+
assert_equal TextElement.new('1 < 3 > 2'), HtmlParser.parse('1 < 3 > 2')
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
data/test/html/parser_test.rb
CHANGED
@@ -19,34 +19,34 @@ require_relative 'parser/parse_with_diff_case_test'
|
|
19
19
|
require_relative 'parser/parse_dtd_test'
|
20
20
|
require_relative 'parser/parse_script_tag_test'
|
21
21
|
|
22
|
-
module
|
22
|
+
module FdlintTest
|
23
23
|
|
24
24
|
module HTML
|
25
25
|
|
26
26
|
class ParserTest < Test::Unit::TestSuite
|
27
27
|
|
28
28
|
def self.suite
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
Test::Unit::TestSuite.new.tap do |tests|
|
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
|
+
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
Test::Unit::UI::Console::TestRunner.run(
|
51
|
+
Test::Unit::UI::Console::TestRunner.run( FdlintTest::HTML::ParserTest ) if __FILE__ == $0
|
52
52
|
|
data/test/html/query_test.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
require_relative '../helper'
|
2
|
-
require 'html/
|
3
|
-
require 'html/query'
|
2
|
+
require 'fdlint/parser/html/html_parser'
|
3
|
+
require 'fdlint/parser/html/query'
|
4
4
|
|
5
|
-
module
|
5
|
+
module FdlintTest
|
6
6
|
module HTML
|
7
7
|
|
8
8
|
class QueryTest < Test::Unit::TestCase
|
9
9
|
|
10
|
-
include
|
10
|
+
include Fdlint::Parser::HTML
|
11
11
|
|
12
|
-
def
|
13
|
-
assert
|
14
|
-
assert
|
12
|
+
def _test_query_with_tag_name
|
13
|
+
assert Tag.new('div') === 'div'
|
14
|
+
assert Tag.new('a', {:href=>'#'}) === 'a'
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
assert
|
19
|
-
assert
|
17
|
+
def _test_query_with_id
|
18
|
+
assert Tag.new('div', { :id => 'info' }) === '#info'
|
19
|
+
assert Tag.new('div', { :id => 'info' }) === 'div#info'
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_query_with_class
|
23
|
-
assert
|
24
|
-
assert
|
25
|
-
assert
|
26
|
-
assert
|
23
|
+
assert Tag.new('div', { :class => 'info' }) === '.info'
|
24
|
+
#assert Tag.new('div', { :id => 'info-1', :class => 'info' }) === '#info-1.info'
|
25
|
+
#assert Tag.new('div', { :id => 'info-1', :class => 'info' }) === '.info#info-1'
|
26
|
+
#assert Tag.new('div', { :id => 'info-1', :class => 'info' }) === 'div.info#info-1'
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
assert
|
29
|
+
def _test_query_with_prop
|
30
|
+
assert Tag.new('div', { :class => 'info' }) === 'div[class==info]'
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
el =
|
33
|
+
def _test_deep_query
|
34
|
+
el = HtmlParser.parse(%Q{<div class="mod">
|
35
35
|
<div>
|
36
36
|
<ul>
|
37
37
|
<li></li>
|