parser-M3U.test.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const parseM3U = require("../radiomanifest.js").parsers.M3U;
  2. const chai = require("chai");
  3. chai.use(require("chai-as-promised"));
  4. const assert = chai.assert;
  5. const expect = chai.expect;
  6. describe("parseM3U parses basic M3U", () => {
  7. describe("empty M3U", () => {
  8. it("should return empty list", () => {
  9. var r = parseM3U("");
  10. assert.equal(r.length, 0);
  11. });
  12. it("should discard empty lines", () => {
  13. var r = parseM3U("\n\n\n");
  14. assert.equal(r.length, 0);
  15. });
  16. });
  17. describe("just some lines", () => {
  18. it("should return appropriate list", () => {
  19. var r = parseM3U("http://foo");
  20. assert.equal(r.length, 1);
  21. assert.equal(r[0], "http://foo");
  22. });
  23. it("should work with longer list", () => {
  24. var r = parseM3U("http://foo\nhttp://baz\nhttp://bar\n");
  25. assert.equal(r.length, 3);
  26. assert.equal(r[0], "http://foo");
  27. assert.equal(r[1], "http://baz");
  28. assert.equal(r[2], "http://bar");
  29. });
  30. it("should discard empty lines", () => {
  31. var r = parseM3U("http://foo\n\nhttp://baz\nhttp://bar\n\n\n");
  32. assert.equal(r.length, 3);
  33. assert.equal(r[0], "http://foo");
  34. assert.equal(r[1], "http://baz");
  35. assert.equal(r[2], "http://bar");
  36. });
  37. });
  38. describe("comments", () => {
  39. it("comments should be ignored", () => {
  40. var r = parseM3U("http://foo\n#asd");
  41. assert.equal(r.length, 1);
  42. assert.equal(r[0], "http://foo");
  43. });
  44. it("mid-line hash is not a comment", () => {
  45. var r = parseM3U("http://foo#asd");
  46. assert.equal(r.length, 1);
  47. assert.equal(r[0], "http://foo#asd");
  48. });
  49. });
  50. });