BuildTest: close menu, ignore whitespace diffs, better first diff finding

This commit is contained in:
ccd0 2014-06-27 19:58:09 -07:00
parent deedfba851
commit a914a29380
2 changed files with 26 additions and 16 deletions

View File

@ -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()
<% } %>

View File

@ -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
<% } %>