'use strict';

import {expect} from "chai"
import {MediaType, parseMediaType} from "../../../source/types/mediatype.mjs";

describe('Dataurl', function () {

    [
        ["*/*","*",'*'],
        ["text/*","text",'*'],
        ["*/test","*",'test'],
        ["image/png", "image", "png"],
        ["audio/mp3", "audio", "mp3"],
        ["video/mpeg", "video", "mpeg"],
        ["text/plain", "text", "plain"],
        ["text/html", "text", "html"],
        ["text/html;charset=US-ASCII", "text", "html"],
        ["text/html;charset=\"US-ASCII\"", "text", "html"],

    ].forEach(function (data) {

        let a = data.shift()
        let b = data.shift()
        let c = data.shift()


        it('parseMediaType(' + a + ')', function () {

            const d = parseMediaType(a);

            expect(d).is.instanceof(MediaType);
            expect(d.toString()).to.be.equal(a);
            expect(d.type).to.be.equal(b);
            expect(d.subtype).to.be.equal(c);
            expect(d.parameter).is.instanceof(Map)
        })

    });

    [
        ["video/"],
        ["text"],
        ["/mp3"],
        ["text/html;charsetUS-ASCII"],
        ["text/html;charset\"US-ASCII\""],

    ].forEach(function (data) {

        let a = data.shift()

        it('' + a + ' should throw exception', function () {

            expect(()=>{parseMediaType(a)}).throw(TypeError);
            
        })

    });


});