08-27-周三_17-09-29

This commit is contained in:
2025-08-27 17:10:05 +08:00
commit 86df397d8f
12735 changed files with 1145479 additions and 0 deletions

10
node_modules/CSSselect/test/tools/bench.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
var ben = require("ben"),
testString = "doo, *#foo > elem.bar[class$=bAz i]:not([ id *= \"2\" ]):nth-child(2n)",
helper = require("./helper.js"),
CSSselect = helper.CSSselect,
compile = CSSselect.compile,
dom = helper.getDefaultDom();
//console.log("Parsing took:", ben(1e5, function(){compile(testString);}));
var compiled = compile(testString);
console.log("Executing took:", ben(1e6, function(){CSSselect(compiled, dom);})*1e3);

2034
node_modules/CSSselect/test/tools/docs/W3C_Selectors.html generated vendored Normal file

File diff suppressed because it is too large Load Diff

51
node_modules/CSSselect/test/tools/helper.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
var fs = require("fs"),
path = require("path"),
htmlparser2 = require("htmlparser2"),
DomUtils = htmlparser2.DomUtils,
CSSselect = require("../../");
function getDOMFromPath(path, options){
return htmlparser2.parseDOM(fs.readFileSync(path).toString(), options);
}
module.exports = {
CSSselect: CSSselect,
getFile: function(name, options){
return getDOMFromPath(path.join(__dirname, "docs", name), options);
},
getDOMFromPath: getDOMFromPath,
getDOM: htmlparser2.parseDOM,
getDefaultDom: function(){
return htmlparser2.parseDOM(
"<elem id=foo><elem class='bar baz'><tag class='boom'> This is some simple text </tag></elem></elem>"
);
},
getDocument: function(path){
var document = getDOMFromPath(path);
document.getElementsByTagName = function(name){
return DomUtils.getElementsByTagName("*", document);
};
document.getElementById = function(id){
return DomUtils.getElementById(id, document);
};
document.createTextNode = function(content){
return {
type: "text",
data: "content"
};
};
document.createElement = function(name){
return {
type: "tag",
name: name,
children: [],
attribs: {}
};
};
document.body = DomUtils.getElementsByTagName("body", document, true, 1)[0];
document.documentElement = document.filter(DomUtils.isTag)[0];
return document;
}
};

76
node_modules/CSSselect/test/tools/slickspeed.js generated vendored Normal file
View File

@@ -0,0 +1,76 @@
var helper = require("./helper.js"),
doc = helper.getFile("W3C_Selectors.html"),
CSSselect = helper.CSSselect,
soupselect = require("cheerio-soupselect"),
selectors = ["body", "div", "body div", "div p", "div > p", "div + p", "div ~ p", "div[class^=exa][class$=mple]", "div p a", "div, p, a", ".note", "div.example", "ul .tocline2", "div.example, div.note", "#title", "h1#title", "div #title", "ul.toc li.tocline2", "ul.toc > li.tocline2", "h1#title + div > p", "h1[id]:contains(Selectors)", "a[href][lang][class]", "div[class]", "div[class=example]", "div[class^=exa]", "div[class$=mple]", "div[class*=e]", "div[class|=dialog]", "div[class!=made_up]", "div[class~=example]"/*, "div:not(.example)", "p:contains(selectors)", "p:nth-child(even)", "p:nth-child(2n)", "p:nth-child(odd)", "p:nth-child(2n+1)", "p:nth-child(n)", "p:only-child", "p:last-child", "p:first-child"*/];
var engines = [function(a,b){return CSSselect(b,a);}, soupselect.select];
//returns true when an error occurs
function testResult(rule, index){
var results = engines
.map(function(func){ return func(doc, rule); });
//check if both had the same result
for(var i = 1; i < results.length; i++){
//TODO: might be hard to debug with more engines
if(results[i-1].length !== results[i].length){
//console.log(rule, results[i-1].length, results[i].length);
return true;
}
for(var j = 0; j < results[i].length; j++){
if(results[i-1][j] !== results[i][j]){
if(results[i-1].indexOf(results[i][j]) === -1){
return true;
}
}
}
//require("assert").deepEqual(results[i-1], results[i], rule + ": not the same elements");
}
return false;
}
selectors.filter(testResult).forEach(function(rule){ print(rule, "failed!\n"); });
process.exit(0); //don't run speed tests
print("-----\n\nChecking performance\n\n");
//test the speed
var ben = require("ben");
function testSpeed(rule){
print(rule, Array(28-rule.length).join(" "));
var results = engines
.map(function(func){ return function(){ return func(doc, rule); }});
//also add a precompiled CSSselect test
var compiled = CSSselect(rule);
results.unshift(function(){ return CSSselect.iterate(compiled, doc); });
results = results.map(ben);
var min = Math.min.apply(null, results);
var max = Math.max.apply(null, results);
results.forEach(function(result){
if(result === min) return print(" +", result, "+");
if(result === max) return print(" !", result, "!");
if(Math.abs(result-min) > Math.abs(result-max)){
return print(" =", result, "=");
}
print(" ~", result, "~");
});
print("\n");
}
print("RULE ", "CSSselect (pc)", "CSSselect", "soupselect\n");
selectors.forEach(testSpeed);
function print(){
process.stdout.write(Array.prototype.join.call(arguments, " "));
}