-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some more tests to cover new comment loading system
- Loading branch information
Showing
10 changed files
with
231 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
'use strict' | ||
describe 'AcfunFormat', -> | ||
jasmine.getFixtures().fixturesPath = "test/" | ||
it 'works', -> | ||
json = readFixtures 'ACFun.json' | ||
comments = AcfunParser(json) | ||
expect(comments.length).toBe 155 | ||
expect(comments[0]).toEqual | ||
stime: 98200 | ||
color: 16777215 | ||
mode: 1 | ||
size: 25 | ||
hash: 'guest' | ||
date: 1315564729 | ||
position: 'absolute' | ||
text: '我谢了你的爱' | ||
jasmine.getFixtures().fixturesPath = "test/synthetic/" | ||
textfix = (text) -> text.replace(/\ /g, "\u00a0") | ||
|
||
it 'provides json parser', -> | ||
expect(typeof AcfunFormat.JSONParser).toBe "function" | ||
|
||
describe '.JSONParser', -> | ||
raw = readFixtures 'AcfunFormat.json' | ||
parser = data = null | ||
|
||
beforeEach -> | ||
parser = new AcfunFormat.JSONParser() | ||
data = JSON.parse(raw) | ||
|
||
it 'can parse one', -> | ||
expect(parser.parseOne(data[0])).toEqual | ||
stime: 1000 | ||
color: 16763904 | ||
mode: 5 | ||
size: 25 | ||
hash: 'guest' | ||
date: 1315736602.0 | ||
position: 'absolute' | ||
text: textfix 'This is just some test.' | ||
|
||
it 'can parse list', -> | ||
comments = parser.parseMany(data) | ||
expect(comments.length).toBe 2 | ||
expect(comments[0]).toEqual | ||
stime: 1000 | ||
color: 16763904 | ||
mode: 5 | ||
size: 25 | ||
hash: 'guest' | ||
date: 1315736602.0 | ||
position: 'absolute' | ||
text: textfix 'This is just some test.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,103 @@ | ||
'use strict' | ||
describe 'BilibiliFormat', -> | ||
jasmine.getFixtures().fixturesPath = "test/" | ||
it 'parses normal comments', -> | ||
# TODO: Update testing to pass in an XML object instead of | ||
# relying on the unsafe innerHTML. | ||
xml_text = readFixtures 'av207527.xml' | ||
comments = BilibiliParser(null, xml_text) | ||
expect(comments.length).toBe 12546 | ||
expect(comments[0]).toEqual | ||
stime: 15105 | ||
size: 25 | ||
color: 16777215 | ||
mode: 1 | ||
date: 1388314569 | ||
pool: 0 | ||
position: 'absolute' | ||
dbid: 364586099 | ||
hash: '1a87dd40' | ||
border: false | ||
text: '关了弹幕瞬间好多了' | ||
|
||
it 'parses scripting comments', -> | ||
xml_text = readFixtures 'scripting/tsubasa.xml' | ||
comments = BilibiliParser(null, xml_text) | ||
expect(comments.length).toBe 654 | ||
expect(comments[0].mode).toEqual 7 | ||
expect(comments[653].mode).toEqual 8 | ||
|
||
it 'parses advanced comments', -> | ||
xml_text = readFixtures 'boss.xml' | ||
comments = BilibiliParser(null, xml_text) | ||
expect(comments.length).toBe 1000 | ||
expect(comments[0].mode).toEqual 7 | ||
expect(comments[0].motion).not.toBe null | ||
|
||
it 'provides xml parser', -> | ||
expect(typeof BilibiliFormat.XMLParser).toBe 'function' | ||
|
||
it 'provides text parser', -> | ||
expect(typeof BilibiliFormat.TextParser).toBe 'function' | ||
|
||
describe '.XMLParser', -> | ||
parser = null | ||
|
||
beforeEach -> | ||
parser = new BilibiliFormat.XMLParser() | ||
|
||
it 'has sane defaults', -> | ||
expect(parser._attemptFix).toBe true | ||
expect(parser._logBadComments).toBe true | ||
|
||
it 'can be configured', -> | ||
parser = new BilibiliFormat.XMLParser | ||
attemptFix: false | ||
logBadComments: false | ||
expect(parser._attemptFix).toBe false | ||
expect(parser._logBadComments).toBe false | ||
|
||
it 'only accepts xml documents', -> | ||
expect( => parser.parseOne "foo").toThrow() | ||
|
||
it 'can parse one', -> | ||
xmltext = readFixtures 'av207527.xml' | ||
dom = (new DOMParser()).parseFromString xmltext, "application/xml" | ||
expect(parser.parseOne dom.getElementsByTagName('d')[0]).toEqual | ||
stime: 15105 | ||
size: 25 | ||
color: 16777215 | ||
mode: 1 | ||
date: 1388314569 | ||
pool: 0 | ||
position: 'absolute' | ||
dbid: 364586099 | ||
hash: '1a87dd40' | ||
border: false | ||
text: '关了弹幕瞬间好多了' | ||
|
||
it 'can parse many', -> | ||
xmltext = readFixtures 'av207527.xml' | ||
dom = (new DOMParser()).parseFromString xmltext, "application/xml" | ||
comments = parser.parseMany dom | ||
expect(comments.length).toBe 12546 | ||
expect(comments[0]).toEqual | ||
stime: 15105 | ||
size: 25 | ||
color: 16777215 | ||
mode: 1 | ||
date: 1388314569 | ||
pool: 0 | ||
position: 'absolute' | ||
dbid: 364586099 | ||
hash: '1a87dd40' | ||
border: false | ||
text: '关了弹幕瞬间好多了' | ||
|
||
describe '.TextParser', -> | ||
parser = null | ||
|
||
beforeEach -> | ||
parser = new BilibiliFormat.TextParser() | ||
|
||
it 'has sane defaults', -> | ||
expect(parser._allowInsecureDomParsing).toBe true | ||
expect(parser._attemptEscaping).toBe true | ||
|
||
it 'can be configured', -> | ||
parser = new BilibiliFormat.TextParser | ||
allowInsecureDomParsing: false | ||
attemptEscaping: false | ||
expect(parser._allowInsecureDomParsing).toBe false | ||
expect(parser._attemptEscaping).toBe false | ||
|
||
it 'propagates parameters', -> | ||
parser = new BilibiliFormat.TextParser | ||
attemptFix: false | ||
logBadComments: false | ||
allowInsecureDomParsing: true | ||
expect(parser._xmlParser instanceof BilibiliFormat.XMLParser).toBe true | ||
expect(parser._xmlParser._attemptFix).toBe false | ||
expect(parser._xmlParser._logBadComments).toBe false | ||
|
||
# it 'parses scripting comments', -> | ||
# xml_text = readFixtures 'scripting/tsubasa.xml' | ||
# comments = BilibiliParser(null, xml_text) | ||
# expect(comments.length).toBe 654 | ||
# expect(comments[0].mode).toEqual 7 | ||
# expect(comments[653].mode).toEqual 8 | ||
|
||
# it 'parses advanced comments', -> | ||
# xml_text = readFixtures 'boss.xml' | ||
# comments = BilibiliParser(null, xml_text) | ||
# expect(comments.length).toBe 1000 | ||
# expect(comments[0].mode).toEqual 7 | ||
# expect(comments[0].motion).not.toBe null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,7 @@ | |
* `scripting/*.biliscript` | ||
|
||
测试代码弹幕的各种小脚本 | ||
|
||
* `synthetic/*` | ||
|
||
人造弹幕文件,目标是测试到所有的属性的解析 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"c":"1,16763904,5,25,guest,1315736602.0", | ||
"m":"This is just some test." | ||
}, | ||
{ | ||
"c":"1,16777215,1,25,guest,1315736602.0", | ||
"m":"Comment 2." | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<i> | ||
<d p="">这是一个测试</d> | ||
</i> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[ | ||
{ | ||
"mode": 1, | ||
"text": "This is a normal scrolling comment. Color is white.", | ||
"size": 25, | ||
"color": 16777215, | ||
"stime": 0 | ||
}, | ||
{ | ||
"mode": 1, | ||
"text": "This is a normal scrolling comment. Size is large", | ||
"size": 60, | ||
"color": 16777215, | ||
"stime": 100 | ||
}, | ||
{ | ||
"mode": 1, | ||
"text": "This is a normal scrolling comment. Color is red.", | ||
"size": 25, | ||
"color": 16711680, | ||
"stime": 200 | ||
}, | ||
{ | ||
"mode": 2, | ||
"text": "This is a normal " | ||
} | ||
] |