'use strict';

import {expect} from "chai"
import {parseDataURL} from "../../../source/types/dataurl.mjs";

describe('Dataurl', function () {

    [
        [" data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E"],
        ["data:text/html;charset=US-ASCII,%3Ch1%3EHello!%3C%2Fh1%3E"],
        ["data:,A%20brief%20note", 'data:text/plain;charset=US-ASCII,A%20brief%20note'],
        ["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC"],
        [" data:,Hello%2C%20World!", 'data:text/plain;charset=US-ASCII,Hello%2C%20World!'],
        ["   data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIBAMAAAA2IaO4AAAAFVBMVEXk5OTn5+ft7e319fX29vb5+fn///++GUmVAAAALUlEQVQIHWNICnYLZnALTgpmMGYIFWYIZTA2ZFAzTTFlSDFVMwVyQhmAwsYMAKDaBy0axX/iAAAAAElFTkSuQmCC   "],
        [" data:,Hello World!", 'data:text/plain;charset=US-ASCII,Hello%20World!'],
        ["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIBAMAAAA2IaO4AAAAFVBMVEXk5OTn5+ft7e319fX29vb5+fn///++GUmVAAAALUlEQVQIHWNICnYLZnALTgpmMGYIFWYIZTA2ZFAzTTFlSDFVMwVyQhmAwsYMAKDaBy0axX/iAAAAAElFTkSuQmCC"],
        [" data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D"]


    ].forEach(function (data) {

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

        if (b === undefined) b = a.trim();


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

            expect(parseDataURL(a).toString()).to.be.equal(b);
        })

    });

    [
        ["dataxbase64"],
        ["data:HelloWorld"],
        ["data:text/html;charset=,%3Ch1%3EHello!%3C%2Fh1%3E"],
        ["data:text/html;charset,%3Ch1%3EHello!%3C%2Fh1%3E", "data:base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC"],
        [""],
        ["http://wikipedia.org"],
        ["base64"],
        ["iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC"]

    ].forEach(function (data) {

        let a = data.shift()


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

            expect(() => parseDataURL(a)).throw(TypeError)
        })

    });


});