|
- import test from 'ava';
-
- import {
- createMediaFragmentIdentifier,
- parseMediaFragmentIdentifier,
- } from './media-fragment-identifier.js';
-
- const creatorResultInputPairs = {
- 't=12.345,67.89': { start: 12.345, end: 67.89 },
- 't=,67.89': { end: 67.89 },
- 't=0,67.89': { start: 0, end: 67.89 },
- 't=12.345': { start: 12.345 },
- };
-
- const parserInputResultPairs = {
- 't=1,2': { start: 1, end: 2 },
- 't=npt:1,2': { start: 1, end: 2 },
- 't=,2': { start: 0, end: 2 },
- 't=1': { start: 1, end: undefined },
- 't=1.234': { start: 1.234, end: undefined },
- 't=1.234,5.678': { start: 1.234, end: 5.678 },
- 't=1:2': { start: 62, end: undefined },
- 't=1:2.5': { start: 62.5, end: undefined },
- 't=1:2:3.4': { start: 3723.4, end: undefined },
- 't=20,1:2:3.4': { start: 20, end: 3723.4 },
- 't=20.,1:2.': { start: 20, end: 62 },
- 'track=audio&t=10,20': { start: 10, end: 20 },
- 't=10,20&track=audio': { start: 10, end: 20 },
- 't=1,2&t=3': { start: 3, end: undefined },
- // Below are examples from the spec.
- 't=npt:10,20': { start: 10, end: 20 },
- 't=npt:,121.5': { start: 0, end: 121.5 },
- 't=0:02:00,121.5': { start: 120, end: 121.5 },
- 't=npt:120,0:02:01.5': { start: 120, end: 121.5 },
- '%74=10,20': { start: 10, end: 20 },
- 't=%31%30': { start: 10, end: undefined },
- 't=10%2C20': { start: 10, end: 20 },
- 't=%6ept:10': { start: 10, end: undefined },
- 't=npt%3a10': { start: 10, end: undefined },
- };
-
- // Test creating.
- for (const [expectedResult, input] of Object.entries(creatorResultInputPairs)) {
- test(`Correctly create fragment '${expectedResult}'`, t => {
- t.is(createMediaFragmentIdentifier(input), expectedResult);
- });
- }
-
- // Test parsing.
- for (const [input, expectedResult] of Object.entries(parserInputResultPairs)) {
- test(`Correctly parse input '${input}'`, t => {
- t.deepEqual(parseMediaFragmentIdentifier(input), expectedResult);
- });
- }
|