JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
add scripting flag to tests, fixes
[peach-html5-editor.git] / test.coffee
index baea4e7..289f46d 100644 (file)
@@ -3474,27 +3474,33 @@ tests = [
        }, {
                name: "tests16.dat #84"
                html: "<!doctype html><noscript><!--<noscript></noscript>--></noscript>"
+               scripting: true
                errors: 1
                expected: "| <!DOCTYPE html>\n| <html>\n|   <head>\n|     <noscript>\n|       \"<!--<noscript>\"\n|   <body>\n|     \"-->\"\n"
        }, {
                name: "tests16.dat #85"
                html: "<!doctype html><noscript><!--<noscript></noscript>--></noscript>"
+               scripting: false
                expected: "| <!DOCTYPE html>\n| <html>\n|   <head>\n|     <noscript>\n|       <!-- <noscript></noscript> -->\n|   <body>\n"
        }, {
                name: "tests16.dat #86"
                html: "<!doctype html><noscript><!--</noscript>X<noscript>--></noscript>"
+               scripting: true
                expected: "| <!DOCTYPE html>\n| <html>\n|   <head>\n|     <noscript>\n|       \"<!--\"\n|   <body>\n|     \"X\"\n|     <noscript>\n|       \"-->\"\n"
        }, {
                name: "tests16.dat #87"
                html: "<!doctype html><noscript><!--</noscript>X<noscript>--></noscript>"
+               scripting: false
                expected: "| <!DOCTYPE html>\n| <html>\n|   <head>\n|     <noscript>\n|       <!-- </noscript>X<noscript> -->\n|   <body>\n"
        }, {
                name: "tests16.dat #88"
                html: "<!doctype html><noscript><iframe></noscript>X"
+               scripting: true
                expected: "| <!DOCTYPE html>\n| <html>\n|   <head>\n|     <noscript>\n|       \"<iframe>\"\n|   <body>\n|     \"X\"\n"
        }, {
                name: "tests16.dat #89"
                html: "<!doctype html><noscript><iframe></noscript>X"
+               scripting: false
                errors: 2
                expected: "| <!DOCTYPE html>\n| <html>\n|   <head>\n|     <noscript>\n|   <body>\n|     <iframe>\n|       \"</noscript>X\"\n"
        }, {
@@ -3950,31 +3956,37 @@ tests = [
        }, {
                name: "tests16.dat #181"
                html: "<noscript><!--<noscript></noscript>--></noscript>"
+               scripting: true
                errors: 2
                expected: "| <html>\n|   <head>\n|     <noscript>\n|       \"<!--<noscript>\"\n|   <body>\n|     \"-->\"\n"
        }, {
                name: "tests16.dat #182"
                html: "<noscript><!--<noscript></noscript>--></noscript>"
+               scripting: false
                errors: 1
                expected: "| <html>\n|   <head>\n|     <noscript>\n|       <!-- <noscript></noscript> -->\n|   <body>\n"
        }, {
                name: "tests16.dat #183"
                html: "<noscript><!--</noscript>X<noscript>--></noscript>"
+               scripting: true
                errors: 1
                expected: "| <html>\n|   <head>\n|     <noscript>\n|       \"<!--\"\n|   <body>\n|     \"X\"\n|     <noscript>\n|       \"-->\"\n"
        }, {
                name: "tests16.dat #184"
                html: "<noscript><!--</noscript>X<noscript>--></noscript>"
+               scripting: false
                errors: 1
                expected: "| <html>\n|   <head>\n|     <noscript>\n|       <!-- </noscript>X<noscript> -->\n|   <body>\n"
        }, {
                name: "tests16.dat #185"
                html: "<noscript><iframe></noscript>X"
+               scripting: true
                errors: 1
                expected: "| <html>\n|   <head>\n|     <noscript>\n|       \"<iframe>\"\n|   <body>\n|     \"X\"\n"
        }, {
                name: "tests16.dat #186"
                html: "<noscript><iframe></noscript>X"
+               scripting: false
                errors: 3
                expected: "| <html>\n|   <head>\n|     <noscript>\n|   <body>\n|     <iframe>\n|       \"</noscript>X\"\n"
        }, {
@@ -6389,11 +6401,13 @@ tests = [
        }, {
                name: "tests5.dat #16"
                html: "<noscript><!--</noscript>--></noscript>"
+               scripting: true
                errors: 2
                expected: "| <html>\n|   <head>\n|     <noscript>\n|       \"<!--\"\n|   <body>\n|     \"-->\"\n"
        }, {
                name: "tests5.dat #17"
                html: "<noscript><!--</noscript>--></noscript>"
+               scripting: false
                errors: 1
                expected: "| <html>\n|   <head>\n|     <noscript>\n|       <!-- </noscript> -->\n|   <body>\n"
        }, {
@@ -7390,6 +7404,7 @@ tests = [
                expected: "| <frame>\n"
        }, {
                name: "tests_innerHTML_1.dat #85"
+               html: ""
                fragment: "html"
                expected: "| <head>\n| <body>\n"
        }, {
@@ -7689,11 +7704,13 @@ tests = [
        }, {
                name: "webkit02.dat #2"
                html: "<p id=\"status\"><noscript><strong>A</strong></noscript><span>B</span></p>"
+               scripting: true
                errors: 1
                expected: "| <html>\n|   <head>\n|   <body>\n|     <p>\n|       id=\"status\"\n|       <noscript>\n|         \"<strong>A</strong>\"\n|       <span>\n|         \"B\"\n"
        }, {
                name: "webkit02.dat #3"
                html: "<p id=\"status\"><noscript><strong>A</strong></noscript><span>B</span></p>"
+               scripting: false
                errors: 1
                expected: "| <html>\n|   <head>\n|   <body>\n|     <p>\n|       id=\"status\"\n|       <noscript>\n|         <strong>\n|           \"A\"\n|       <span>\n|         \"B\"\n"
        }, {
@@ -7795,39 +7812,56 @@ serialize_els = (els, prefix = '| ') ->
        for el in els
                switch el.type
                        when wheic.TYPE_TAG
-                               ret += "#{prefix}<#{el.name}>\n"
+                               ret += "#{prefix}<"
+                               if el.namespace is wheic.NS_MATHML
+                                       ret += "math "
+                               if el.namespace is wheic.NS_SVG
+                                       ret += "svg "
+                               ret += "#{el.name}>\n"
                                attr_keys = []
                                for k of el.attrs
                                        attr_keys.push k
                                attr_keys.sort() # TODO this should be "lexicographically by UTF-16 code unit"
                                for k in attr_keys
                                        ret += "#{prefix}  #{k}=\"#{el.attrs[k]}\"\n"
-                               # FIXME template shows as "content" with children below it
-                               ret += serialize_els el.children, "#{prefix}  "
+                               if el.name is 'template' # ?check ns
+                                       ret += "#{prefix}  content\n"
+                                       ret += serialize_els el.children, "#{prefix}    "
+                               else
+                                       ret += serialize_els el.children, "#{prefix}  "
                        when wheic.TYPE_TEXT
                                ret += "#{prefix}\"#{el.text}\"\n"
                        when wheic.TYPE_COMMENT
                                ret += "#{prefix}<!-- #{el.text} -->\n"
                        when wheic.TYPE_DOCTYPE
-                               ret += "#{prefix}<!DOCTYPE#{el.name}>\n" # FIXME add ids
+                               ret += "#{prefix}<!DOCTYPE #{el.name}"
+                               if (el.public_identifier? and el.public_identifier.length > 0) or (el.system_identifier? and el.system_identifier.length > 0)
+                                       ret += " \"#{el.public_identifier ? ''}\""
+                                       ret += " \"#{el.system_identifier ? ''}\""
+                               ret += ">\n"
                        else
                                ret += "#{prefix}UNKNOWN TAG TYPE #{el.type}"
        return ret
 
-test_results = passed: 0, failed: 0
+test_results = passed: 0, failed: 0, fragment: 0
 test_parser = (args) ->
+       if args.fragment? # hide fragment tests for now
+               test_results.fragment += 1
+               return
        wheic.debug_log_reset()
        parse_errors = []
-       errors_cb = (i) ->
+       args.error_cb = (i) ->
                parse_errors.push i
        prev_node_id = 0 # reset counter
-       parsed = wheic.parse_html args.html, errors_cb
+       parsed = wheic.parse_html args
        serialized = serialize_els parsed
        if serialized isnt args.expected
                #wheic.debug_log_each (str) ->
                #       console.log str
                console.log "FAILED: \"#{args.name}\""
                console.log "      Input: #{args.html}"
+               if args.fragment?
+                       console.log "   Fragment: #{args.fragment}"
                console.log "    Correct: #{args.expected}"
                console.log "     Output: #{serialized}"
                if parse_errors.length > 0
@@ -7839,8 +7873,7 @@ test_parser = (args) ->
                console.log "passed \"#{args.name}\""
                test_results.passed += 1
 test_summary = ->
-       console.log "Tests passed: #{test_results.passed}"
-       console.log "Tests Failed: #{test_results.failed}"
+       console.log "Tests passed: #{test_results.passed}, Failed: #{test_results.failed}, ignored: #{test_results.fragment}"
 
 
 next_test = 0
@@ -7848,11 +7881,12 @@ run_tests_and_breathe = ->
        start_time = new Date()
        loop
                if next_test >= tests.length
+                       test_summary()
                        return
                test_parser tests[next_test]
                next_test += 1
                now = new Date()
                if now - start_time > 100 # miliseconds
-                       setTimeout run_tests_and_breathe, 1
+                       break
+       setTimeout run_tests_and_breathe, 1
 run_tests_and_breathe()
-test_summary()