Skip to content

Commit 2a4a74f

Browse files
committed
Added tests for TagSoup parsing
1 parent 4797307 commit 2a4a74f

6 files changed

Lines changed: 42 additions & 8 deletions

File tree

demo/debugger.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var tests = {
1212
"test-s":"tests/kanpai.xml",
1313
"test-ac-1":{"f":'tests/ACFun.json',"p":"acfun"},
1414
"test-ac-2":{"f":'tests/ac940133.json',"p":"acfun"},
15+
"test-ts-1":"tests/invalid/no_closing.xml",
16+
"test-ts-2":"tests/invalid/syntax_error.xml"
1517
};
1618

1719
var debugs = {

demo/index.htm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h2>Tests</h2>
4545
</div>
4646
<h2>Extended</h2>
4747
<div>
48-
<a id="test-7" class="button" href="javascript:;">Run Test 7 (WIP)</a>
48+
<a id="test-7" class="button" href="javascript:;">Run Test 7</a>
4949
<a id="test-8" class="button" href="javascript:;">Run Test 8</a>
5050
<a id="test-9" class="button" href="javascript:;">Run Test 9</a>
5151
<a id="test-s" class="button" href="javascript:;">Run Test Scripting</a>
@@ -57,6 +57,10 @@ <h3>AcFun (Experimental)</h3>
5757
<a id="test-ac-2" class="button" href="javascript:;">Run Test 2</a>
5858
<div style="clear:both;"></div>
5959
</div>
60+
<p>TagSoup: <br>
61+
<a id="test-ts-1" href="javascript:;">Tag Soup 1</a>,
62+
<a id="test-ts-2" href="javascript:;">Tag Soup 2</a>
63+
</p>
6064
<p>Filters: <br>
6165
<a onclick="cm.filter.setRuntimeFilter(fefx.center_dim);" href="javascript:;">Apply Center-Transparency</a><br>
6266
<a onclick="cm.filter.setRuntimeFilter(fefx.center_speedup);" href="javascript:;">Apply Center-Speedup</a><br>

demo/libxml.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ function CommentLoader(url,xcm,mode){
2222
var f = new ActiveXObject("Microsoft.XMLDOM");
2323
f.async = false;
2424
f.loadXML(xmlhttp.responseText);
25-
cm.load(BilibiliParser(f));
25+
cm.load(BilibiliParser(f, xmlhttp.responseText));
2626
}else{
27-
cm.load(BilibiliParser(xmlhttp.responseXML));
27+
cm.load(BilibiliParser(xmlhttp.responseXML, xmlHTTP.responseText));
2828
}
2929
}else if(mode == 'acfun'){
3030
cm.load(AcfunParser(xmlhttp.responseText));

src/parsers/BilibiliFormat.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
22
Bilibili Format
33
Licensed Under MIT License
4-
Takes in an XMLDoc and parses that into a Generic Comment List
4+
Takes in an XMLDoc/LooseXMLDoc and parses that into a Generic Comment List
55
**/
6-
function BilibiliParser(xmlDoc){
7-
//Parse into Array
6+
function BilibiliParser(xmlDoc, text){
87
function fillRGB(string){
98
while(string.length < 6){
109
string = "0" + string;
@@ -16,8 +15,13 @@ function BilibiliParser(xmlDoc){
1615
function format(string){
1716
return string.replace(/\t/,"\\t");
1817
}
19-
20-
var elems = xmlDoc.getElementsByTagName('d');
18+
if(xmlDoc !== null){
19+
var elems = xmlDoc.getElementsByTagName('d');
20+
}else{
21+
var tmp = document.createElement("div");
22+
tmp.innerHTML = text;
23+
var elems = tmp.getElementsByTagName('d');
24+
}
2125
var tlist = [];
2226
for(var i=0;i<elems.length;i++){
2327
if(elems[i].getAttribute('p') != null){

tests/invalid/no_closing.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?><i>
2+
<chatserver>chat.bilibili.tv</chatserver>
3+
<chatid>91236</chatid>
4+
<source>k-v</source>
5+
<d p="0,1,25,16777215,1296965347,0,c4c06db0,14089276">[1]-。-</d>
6+
<d p="1000,1,25,16777215,1296965353,0,c4c06db0,14089285">[2]路过</d>
7+
<d p="2000,1,25,16777215,1296965413,0,c4c06db0,14089404">[3]说真的原曲好听很多</d>
8+
<d p="3000,1,25,16777215,1299993365,0,Dea1a7cd,18515460">[4]音响坏了?
9+
<d p="4000,1,25,16777215,1309012585,0,D75a006c,32875515">[5]喜欢这个啊</d>
10+
<d p="5000,1,25,16777215,1310784225,0,D31ffff4,36898041">[6]= =</d>
11+
<d p="6000,1,25,16777215,1310784237,0,D31ffff4,36898069">[7]G_&lt;</d>
12+
</i>

tests/invalid/syntax_error.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?><i>
2+
<chatserver>chat.bilibili.tv</chatserver>
3+
<chatid>91236</chatid>
4+
<source>k-v</source>
5+
<d p="0,1,25,16777215,1296965347,0,c4c06db0,14089276">[1]-。-</d>
6+
<d p="1000,1,25,16777215,1296965353,0,c4c06db0,14089285">[2]路过</d>
7+
<d p="2000,1,25,16777215,1296965413,0,c4c06db0,14089404">[3]说真的原曲好听很多</d>
8+
<d p="3000,1,25,16777215,1299993365,0,Dea1a7cd,18515460"[4]音响坏了?</d>
9+
<d p="4000,1,25,16777215,1309012585,0,D75a006c,32875515">[5]喜欢这个啊</d>
10+
<d p="5000,1,25,16777215,1310784225,0,D31ffff4,36898041">[6]= =</d>
11+
<d p="6000,1,25,16777215,1310784237,0,D31ffff4,36898069">[7]G_&lt;</d>
12+
</i>

0 commit comments

Comments
 (0)