From a914a293808579412a1260bb7e1a7f9217f1bdf1 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 27 Jun 2014 19:58:09 -0700 Subject: [PATCH] BuildTest: close menu, ignore whitespace diffs, better first diff finding --- src/General/BuildTest.coffee | 38 +++++++++++++++++++++--------------- src/General/lib/post.class | 4 ++++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/General/BuildTest.coffee b/src/General/BuildTest.coffee index 797388f6e..d3413b240 100644 --- a/src/General/BuildTest.coffee +++ b/src/General/BuildTest.coffee @@ -1,7 +1,7 @@ <% if (tests_enabled) { %> BuildTest = init: -> - return if !Conf['Menu'] + return if !Conf['Menu'] or g.VIEW is 'catalog' a = $.el 'a', textContent: 'Test HTML building' @@ -18,38 +18,44 @@ BuildTest = Header.menu.addEntry el: a2 + firstDiff: (x, y) -> + x2 = x.cloneNode false + y2 = y.cloneNode false + if !x2.isEqualNode y2 + return [x2, y2] + i = 0 + while (x2 = x.childNodes[i]) and (y2 = y.childNodes[i++]) + if !x2.isEqualNode y2 + return BuildTest.firstDiff x2, y2 + return [x2, y2] + runTest: (post) -> $.cache "//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", -> for postData in @response.posts if postData.no is post.ID root = Build.postFromObject postData, post.board.ID post2 = new Post root, post.thread, post.board - if post.normalizedOriginal.isEqualNode post2.normalizedOriginal + x = post.normalizedOriginal + y = post2.normalizedOriginal + if x.isEqualNode y c.log "#{post.fullID} correct" else c.log "#{post.fullID} differs" - html = post.normalizedOriginal.innerHTML - html2 = post2.normalizedOriginal.innerHTML - if html is html2 - c.log post.normalizedOriginal.outerHTML - c.log post2.normalizedOriginal.outerHTML - else - i = 0 - while i < html.length and i < html2.length - break unless html[i] is html2[i] - i++ - c.log html[i..i+80] - c.log html2[i..i+80] - c.log html - c.log html2 + [x2, y2] = BuildTest.firstDiff x, y + c.log x2 + c.log y2 + c.log x.outerHTML + c.log y.outerHTML post2.isFetchedQuote = true Main.callbackNodes Post, [post2] testOne: -> BuildTest.runTest g.posts[@dataset.fullID] + Menu.menu.close() testAll: -> g.posts.forEach (post) -> unless post.isClone or post.isFetchedQuote or $ '.abbr', post.nodes.comment BuildTest.runTest post + Header.menu.close() <% } %> diff --git a/src/General/lib/post.class b/src/General/lib/post.class index 235e9f46d..2ddbe223a 100755 --- a/src/General/lib/post.class +++ b/src/General/lib/post.class @@ -15,6 +15,10 @@ class Post el.removeAttribute 'rel' for el in $$ 'img[src]', root2 el.src = el.src.replace /^(\w+:\/\/)[0-2](\.t\.4cdn\.org\/)/, '$10$2' + textNodes = $.X './/text()', root2 + i = 0 + while node = textNodes.snapshotItem i++ + node.data = node.data.replace /\s+/g, ' ' @normalizedOriginal = root2 <% } %>