<commit_before>(function(window, jQuery) {
	if( window.HTMLPictureElement ){
		test( "Picture is natively supported", function() {
			ok( window.HTMLPictureElement );
		});

		return;
	}

	test("functional: The first matching `source` is selected.", function() {
		var pic = $( ".first-match" ),
				firstsource = pic.find( "source" ).eq( 0 ),
				img = pic.find( "img" );

		equal( img[ 0 ].getAttribute( "src" ), firstsource[ 0 ].getAttribute( "srcset" ) );
	});

	var pf, originalDprMethod, originalVideoShimMethod, originalMatchesMedia;

	pf = picturefill._;

	// reset stubbing
	module( "method", {
		setup: function() {
			originalDprMethod = pf.getDpr;
			originalVideoShimMethod = pf.removeVideoShim;
			originalMatchesMedia = pf.matchesMedia;
		},

		teardown: function() {
			pf.getDpr = originalDprMethod;
			pf.removeVideoShim = originalVideoShimMethod;
			pf.matchesMedia = originalMatchesMedia;
		}
	});

	test("getWidthFromLength", function() {
		equal(pf.getWidthFromLength('750px'), 750, "returns int value of width string");
	});

	test("findWidthFromSourceSize", function() {
		var sizes = "	 (max-width: 30em) 1000px,	 (max-width: 50em) 750px, 500px	 ";
		// mock match media
		var oldMatchesMedia = pf.matchesMedia;
		pf.matchesMedia = function(media) {
			return true;
		};
		var width = pf.findWidthFromSourceSize(sizes);
		equal(width, 1000, "returns 1000 when match media returns true");

		pf.matchesMedia = function(media) {
			return false;
		};
		var width = pf.findWidthFromSourceSize(sizes);
		equal(width, 500, "returns 500 when match media returns false");

		// restore `matchesMedia`
		pf.matchesMedia = oldMatchesMedia;
	});

    test("parseSize", function() {
        var size1 = "";
        var expected1 = {
            length: null,
            media: null
        };
        deepEqual(pf.parseSize(size1), expected1, "Length and Media are empty");
 
        var size2 = "( max-width: 50em ) 50%";
        var expected2 = {
            length: "50%",
            media: "( max-width: 50em )"
        };
        deepEqual(pf.parseSize(size2), expected2, "Length and Media are properly parsed");
        
        var size3 = "(min-width:30em) calc(30% - 15px)";
        var expected3 = {
            length: "calc(30% - 15px)",
            media: "(min-width:30em)"
        };
        deepEqual(pf.parseSize(size3), expected3, "Length and Media are properly parsed");
    });

	test("getCandidatesFromSourceSet", function() {
		// Basic test
		var candidate1 = "images/pic-medium.png";
		var expectedFormattedCandidates1 = [
			{
				resolution: 1,
				url: "images/pic-medium.png"
			}
		];
		deepEqual(pf.getCandidatesFromSourceSet(candidate1), expectedFormattedCandidates1, "Works!");

		var candidate1a = "images/pic-medium.png 1x";
		var expectedFormattedCandidates1a = [
			{
				resolution: 1,
				url: "images/pic-medium.png"
			}
		];
		deepEqual(pf.getCandidatesFromSourceSet(candidate1a), expectedFormattedCandidates1a, "Works!");

		var candidate2 = "images/pic-medium.png 1x, images/pic-medium-2x.png 2x";
		var expectedFormattedCandidates2 = [
			{
				resolution: 1,
				url: "images/pic-medium.png"
			},
			{
				resolution: 2,
				url: "images/pic-medium-2x.png"
			}
		];
		deepEqual(pf.getCandidatesFromSourceSet(candidate2), expectedFormattedCandidates2, "Works!");

		// Test with multiple spaces
		var candidate3 = "			images/pic-medium.png		 1x		,		 images/pic-medium-2x.png		 2x		";
		deepEqual(pf.getCandidatesFromSourceSet(candidate3), expectedFormattedCandidates2, "Works!")

		// Test with decimals<commit_msg>Ensure correct source is chosen when presented with explicit and implicit 1x with multiple resolution options in play.<commit_after>(function(window, jQuery) {
	if( window.HTMLPictureElement ){
		test( "Picture is natively supported", function() {
			ok( window.HTMLPictureElement );
		});

		return;
	}

	test("functional: The first matching `source` is selected.", function() {
		var pic = $( ".first-match" ),
				firstsource = pic.find( "source" ).eq( 0 ),
				img = pic.find( "img" );

		equal( img[ 0 ].getAttribute( "src" ), firstsource[ 0 ].getAttribute( "srcset" ) );
	});

	var pf, originalDprMethod, originalVideoShimMethod, originalMatchesMedia;

	pf = picturefill._;

	// reset stubbing
	module( "method", {
		setup: function() {
			originalDprMethod = pf.getDpr;
			originalVideoShimMethod = pf.removeVideoShim;
			originalMatchesMedia = pf.matchesMedia;
		},

		teardown: function() {
			pf.getDpr = originalDprMethod;
			pf.removeVideoShim = originalVideoShimMethod;
			pf.matchesMedia = originalMatchesMedia;
		}
	});

	test("getWidthFromLength", function() {
		equal(pf.getWidthFromLength('750px'), 750, "returns int value of width string");
	});

	test("findWidthFromSourceSize", function() {
		var sizes = "	 (max-width: 30em) 1000px,	 (max-width: 50em) 750px, 500px	 ";
		// mock match media
		var oldMatchesMedia = pf.matchesMedia;
		pf.matchesMedia = function(media) {
			return true;
		};
		var width = pf.findWidthFromSourceSize(sizes);
		equal(width, 1000, "returns 1000 when match media returns true");

		pf.matchesMedia = function(media) {
			return false;
		};
		var width = pf.findWidthFromSourceSize(sizes);
		equal(width, 500, "returns 500 when match media returns false");

		// restore `matchesMedia`
		pf.matchesMedia = oldMatchesMedia;
	});

    test("parseSize", function() {
        var size1 = "";
        var expected1 = {
            length: null,
            media: null
        };
        deepEqual(pf.parseSize(size1), expected1, "Length and Media are empty");
 
        var size2 = "( max-width: 50em ) 50%";
        var expected2 = {
            length: "50%",
            media: "( max-width: 50em )"
        };
        deepEqual(pf.parseSize(size2), expected2, "Length and Media are properly parsed");
        
        var size3 = "(min-width:30em) calc(30% - 15px)";
        var expected3 = {
            length: "calc(30% - 15px)",
            media: "(min-width:30em)"
        };
        deepEqual(pf.parseSize(size3), expected3, "Length and Media are properly parsed");
    });

	test("getCandidatesFromSourceSet", function() {
		// Basic test
		var candidate1 = "images/pic-medium.png";
		var expectedFormattedCandidates1 = [
			{
				resolution: 1,
				url: "images/pic-medium.png"
			}
		];
		deepEqual(pf.getCandidatesFromSourceSet(candidate1), expectedFormattedCandidates1, "Works!");

		var candidate1a = "images/pic-medium.png 1x";
		var expectedFormattedCandidates1a = [
			{
				resolution: 1,
				url: "images/pic-medium.png"
			}
		];
		deepEqual(pf.getCandidatesFromSourceSet(candidate1a), expectedFormattedCandidates1a, "Works!");

		var candidate2 = "images/pic-medium.png, images/pic-medium-2x.png 2x";
		var expectedFormattedCandidates2 = [
			{
				resolution: 1,
				url: "images/pic-medium.png"
			},
			{
				resolution: 2,
				url: "images/pic-medium-2x.png"
			}
		];
		deepEqual(pf.getCandidatesFromSourceSet(candidate2), expectedFormattedCandidates2, "Works!");

		var candidate2a = "images/pic-medium.png 1x, images/pic-medium-2x.png 2x";
		var expectedFormattedCandidates2a = [
			{
				resolution: 1,
				url: "images/pic-medium.png"
			},
			{
				resolution: 2,
				url: "images/pic-medium-2x.png"
			}
		];
		deepEqual(pf.getCandidatesFromSourceSet(candidate2a), expectedFormattedCandidates2a, "Works!");

		// Test with multiple spaces
		var candidate3 = "			images/pic-medium.png		 1x		,		 images/pic-medium-2x.png		 2x		";
		deepEqual(pf.getCandidatesFromSourceSet(candidate3), expectedFormattedCandidates2, "Works!")

		// Test with decimals
{'fraction_non_alphanumeric': 0.1341222879684418, 'fraction_numerical': 0.02656147271531887, 'mean_word_length': 3.2947487295313382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5725450', 'n_tokens_mistral': 2905, 'n_tokens_neox': 2459, 'n_words': 538}