1
0
Fork 0
radiomanifest.js/test/parser-M3U.test.js
2021-12-26 19:59:59 +01:00

53 lines
1.6 KiB
JavaScript

const parseM3U = require('../radiomanifest.js').parsers.M3U
const chai = require('chai')
chai.use(require('chai-as-promised'))
const assert = chai.assert
const expect = chai.expect
describe('parseM3U parses basic M3U', () => {
describe('empty M3U', () => {
it('should return empty list', () => {
var r = parseM3U("")
assert.equal(r.length, 0)
})
it('should discard empty lines', () => {
var r = parseM3U("\n\n\n")
assert.equal(r.length, 0)
})
})
describe('just some lines', () => {
it('should return appropriate list', () => {
var r = parseM3U("http://foo")
assert.equal(r.length, 1)
assert.equal(r[0], "http://foo")
})
it('should work with longer list', () => {
var r = parseM3U("http://foo\nhttp://baz\nhttp://bar\n")
assert.equal(r.length, 3)
assert.equal(r[0], "http://foo")
assert.equal(r[1], "http://baz")
assert.equal(r[2], "http://bar")
})
it('should discard empty lines', () => {
var r = parseM3U("http://foo\n\nhttp://baz\nhttp://bar\n\n\n")
assert.equal(r.length, 3)
assert.equal(r[0], "http://foo")
assert.equal(r[1], "http://baz")
assert.equal(r[2], "http://bar")
})
})
describe('comments', () => {
it('comments should be ignored', () => {
var r = parseM3U("http://foo\n#asd")
assert.equal(r.length, 1)
assert.equal(r[0], "http://foo")
})
it('mid-line hash is not a comment', () => {
var r = parseM3U("http://foo#asd")
assert.equal(r.length, 1)
assert.equal(r[0], "http://foo#asd")
})
})
})