|
1 | 1 | 'use strict' |
2 | 2 | describe 'BilibiliFormat', -> |
3 | 3 | jasmine.getFixtures().fixturesPath = "test/" |
4 | | - it 'parses normal comments', -> |
5 | | - # TODO: Update testing to pass in an XML object instead of |
6 | | - # relying on the unsafe innerHTML. |
7 | | - xml_text = readFixtures 'av207527.xml' |
8 | | - comments = BilibiliParser(null, xml_text) |
9 | | - expect(comments.length).toBe 12546 |
10 | | - expect(comments[0]).toEqual |
11 | | - stime: 15105 |
12 | | - size: 25 |
13 | | - color: 16777215 |
14 | | - mode: 1 |
15 | | - date: 1388314569 |
16 | | - pool: 0 |
17 | | - position: 'absolute' |
18 | | - dbid: 364586099 |
19 | | - hash: '1a87dd40' |
20 | | - border: false |
21 | | - text: '关了弹幕瞬间好多了' |
22 | | - |
23 | | - it 'parses scripting comments', -> |
24 | | - xml_text = readFixtures 'scripting/tsubasa.xml' |
25 | | - comments = BilibiliParser(null, xml_text) |
26 | | - expect(comments.length).toBe 654 |
27 | | - expect(comments[0].mode).toEqual 7 |
28 | | - expect(comments[653].mode).toEqual 8 |
29 | | - |
30 | | - it 'parses advanced comments', -> |
31 | | - xml_text = readFixtures 'boss.xml' |
32 | | - comments = BilibiliParser(null, xml_text) |
33 | | - expect(comments.length).toBe 1000 |
34 | | - expect(comments[0].mode).toEqual 7 |
35 | | - expect(comments[0].motion).not.toBe null |
| 4 | + |
| 5 | + it 'provides xml parser', -> |
| 6 | + expect(typeof BilibiliFormat.XMLParser).toBe 'function' |
| 7 | + |
| 8 | + it 'provides text parser', -> |
| 9 | + expect(typeof BilibiliFormat.TextParser).toBe 'function' |
| 10 | + |
| 11 | + describe '.XMLParser', -> |
| 12 | + parser = null |
| 13 | + |
| 14 | + beforeEach -> |
| 15 | + parser = new BilibiliFormat.XMLParser() |
| 16 | + |
| 17 | + it 'has sane defaults', -> |
| 18 | + expect(parser._attemptFix).toBe true |
| 19 | + expect(parser._logBadComments).toBe true |
| 20 | + |
| 21 | + it 'can be configured', -> |
| 22 | + parser = new BilibiliFormat.XMLParser |
| 23 | + attemptFix: false |
| 24 | + logBadComments: false |
| 25 | + expect(parser._attemptFix).toBe false |
| 26 | + expect(parser._logBadComments).toBe false |
| 27 | + |
| 28 | + it 'only accepts xml documents', -> |
| 29 | + expect( => parser.parseOne "foo").toThrow() |
| 30 | + |
| 31 | + it 'can parse one', -> |
| 32 | + xmltext = readFixtures 'av207527.xml' |
| 33 | + dom = (new DOMParser()).parseFromString xmltext, "application/xml" |
| 34 | + expect(parser.parseOne dom.getElementsByTagName('d')[0]).toEqual |
| 35 | + stime: 15105 |
| 36 | + size: 25 |
| 37 | + color: 16777215 |
| 38 | + mode: 1 |
| 39 | + date: 1388314569 |
| 40 | + pool: 0 |
| 41 | + position: 'absolute' |
| 42 | + dbid: 364586099 |
| 43 | + hash: '1a87dd40' |
| 44 | + border: false |
| 45 | + text: '关了弹幕瞬间好多了' |
| 46 | + |
| 47 | + it 'can parse many', -> |
| 48 | + xmltext = readFixtures 'av207527.xml' |
| 49 | + dom = (new DOMParser()).parseFromString xmltext, "application/xml" |
| 50 | + comments = parser.parseMany dom |
| 51 | + expect(comments.length).toBe 12546 |
| 52 | + expect(comments[0]).toEqual |
| 53 | + stime: 15105 |
| 54 | + size: 25 |
| 55 | + color: 16777215 |
| 56 | + mode: 1 |
| 57 | + date: 1388314569 |
| 58 | + pool: 0 |
| 59 | + position: 'absolute' |
| 60 | + dbid: 364586099 |
| 61 | + hash: '1a87dd40' |
| 62 | + border: false |
| 63 | + text: '关了弹幕瞬间好多了' |
| 64 | + |
| 65 | + describe '.TextParser', -> |
| 66 | + parser = null |
| 67 | + |
| 68 | + beforeEach -> |
| 69 | + parser = new BilibiliFormat.TextParser() |
| 70 | + |
| 71 | + it 'has sane defaults', -> |
| 72 | + expect(parser._allowInsecureDomParsing).toBe true |
| 73 | + expect(parser._attemptEscaping).toBe true |
| 74 | + |
| 75 | + it 'can be configured', -> |
| 76 | + parser = new BilibiliFormat.TextParser |
| 77 | + allowInsecureDomParsing: false |
| 78 | + attemptEscaping: false |
| 79 | + expect(parser._allowInsecureDomParsing).toBe false |
| 80 | + expect(parser._attemptEscaping).toBe false |
| 81 | + |
| 82 | + it 'propagates parameters', -> |
| 83 | + parser = new BilibiliFormat.TextParser |
| 84 | + attemptFix: false |
| 85 | + logBadComments: false |
| 86 | + allowInsecureDomParsing: true |
| 87 | + expect(parser._xmlParser instanceof BilibiliFormat.XMLParser).toBe true |
| 88 | + expect(parser._xmlParser._attemptFix).toBe false |
| 89 | + expect(parser._xmlParser._logBadComments).toBe false |
| 90 | + |
| 91 | +# it 'parses scripting comments', -> |
| 92 | +# xml_text = readFixtures 'scripting/tsubasa.xml' |
| 93 | +# comments = BilibiliParser(null, xml_text) |
| 94 | +# expect(comments.length).toBe 654 |
| 95 | +# expect(comments[0].mode).toEqual 7 |
| 96 | +# expect(comments[653].mode).toEqual 8 |
| 97 | + |
| 98 | +# it 'parses advanced comments', -> |
| 99 | +# xml_text = readFixtures 'boss.xml' |
| 100 | +# comments = BilibiliParser(null, xml_text) |
| 101 | +# expect(comments.length).toBe 1000 |
| 102 | +# expect(comments[0].mode).toEqual 7 |
| 103 | +# expect(comments[0].motion).not.toBe null |
0 commit comments