Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #31 from le717/unittests
Browse files Browse the repository at this point in the history
Add simple unit tests for SvgSize + more
  • Loading branch information
Triangle717 committed Apr 4, 2015
2 parents 985335e + 0b6113b commit 02d2e7f
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 27 deletions.
7 changes: 4 additions & 3 deletions .jscs.json
Expand Up @@ -46,8 +46,9 @@
},

"maximumLineLength": {
"value": 145,
"allowComments": true,
"allowRegex": true
"value": 125,
"allowRegex": true,
"allowComments": true,
"allowUrlComments": true
}
}
30 changes: 20 additions & 10 deletions Gruntfile.js
Expand Up @@ -3,7 +3,8 @@ module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
jsFiles: ["*.js", "src/*.js"],
i18nJsFiles: ["nls/*.js", "nls/**/*.js"],
jsFilesi18n: ["strings.js", "nls/*.js", "nls/**/*.js"],
jsFilesTests: ["unittests.js"],

htmlhint: {
html: {
Expand All @@ -25,27 +26,36 @@ module.exports = function (grunt) {
},

jshint: {
options: {
jshintrc: ".jshintrc"
},
src: {
options: {
jshintrc: ".jshintrc"
},
src: ["<%= jsFiles %>", "<%= i18nJsFiles %>"]
src: "<%= jsFiles %>"
},
i18n: {
src: "<%= jsFilesi18n %>"
},
test: {
src: "<%= jsFilesTests %>"
},
},

jscs: {
main: {
options: {
config: ".jscs.json"
},
src: {
src: "<%= jsFiles %>"
},
i18n: {
src: "<%= i18nJsFiles %>",
src: "<%= jsFilesi18n %>",
options: {
maximumLineLength: null
}
},
options: {
config: ".jscs.json"
}
test: {
src: "<%= jsFilesTests %>"
},
}
});

Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
@@ -1,7 +1,12 @@
# Changes #

## 1.4.2 ##
### ? April, 2015 ###
* Add simple unit tests for `src/SvgSize` module
* Fix regression in extracting values from SVG `enable-background` attribute

## 1.4.1 ##
### 3 April 2015 ###
### 3 April, 2015 ###
* Make `SvgSize.get()` return an object instead of array
* Relax SVG graphic size detection regexes
* Trim stray whitespace from extracted SVG size
Expand Down
4 changes: 2 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
# HTML Skeleton [![Build Status](https://travis-ci.org/le717/brackets-html-skeleton.svg)](https://travis-ci.org/le717/brackets-html-skeleton) #

> A [Brackets](http://brackets.io) extension that allows you to insert a variety of HTML elements into your document with ease.
> A [Brackets](http://brackets.io) extension that allows you to easily insert a variety of HTML elements into your document.
# Installation #
Method 1: Open the Brackets Extension Manager and search for "skeleton"
Expand All @@ -19,7 +19,7 @@ Method 2: Download a `.zip` directly from GitHub using either the [latest revisi
See [NEWS.md](NEWS.md) for all changes.

# License #
[MIT License](LICENSE.md)
[MIT License](LICENSE)

Created 2014-2015 [Triangle717](http://le717.github.io)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "le717.html-skeleton",
"version": "1.4.1",
"title": "HTML Skeleton",
"description": "Insert a variety of HTML elements into your document with ease.",
"description": "Easily insert a variety of HTML elements into your document.",
"homepage": "https://github.com/le717/brackets-html-skeleton",
"author": "Triangle717 (http://le717.github.io)",
"license": "MIT",
Expand Down
20 changes: 10 additions & 10 deletions src/SvgSize.js
Expand Up @@ -33,7 +33,7 @@ define(function (require, exports) {
* @return {Boolean} True if width and height are valid.
*/
function _isValid(width, height) {
return width !== null && height !== null;
return width && height;
}

/**
Expand All @@ -59,7 +59,7 @@ define(function (require, exports) {
width: widthRegex.test(content) ? content.match(widthRegex)[1] : null,
height: heightRegex.test(content) ? content.match(heightRegex)[1] : null,
viewBox: viewBoxRegex.test(content) ? content.match(viewBoxRegex)[1] : null,
enableBackground: enableBackgroundRegex.test(content) ? content.match(enableBackgroundRegex)[1] : null
enableBG: enableBackgroundRegex.test(content) ? content.match(enableBackgroundRegex)[1] : null
};

// The viewBox values are present, extract them
Expand All @@ -71,11 +71,11 @@ define(function (require, exports) {
}

// The enable-background values are present, extract them
if (results.enableBackground) {
var individualEB = results.enableBackground.split(" ");
results.enableBackgroundWidth = individualEB[3];
results.enableBackgroundHeight = individualEB[4];
delete results.enableBackground;
if (results.enableBG) {
var individualEB = results.enableBG.split(" ");
results.enableBGWidth = individualEB[3];
results.enableBGHeight = individualEB[4];
delete results.enableBG;
}

// Trim out any captured stray whitespace
Expand All @@ -102,9 +102,9 @@ define(function (require, exports) {
svgSize.height = results.viewBoxHeight;

// enable-background
} else if (_isValid(results.enableBackgroundWidth, results.enableBackgroundHeight)) {
svgSize.width = results.enableBackgroundWidth;
svgSize.height = results.enableBackgroundHeight;
} else if (_isValid(results.enableBGWidth, results.enableBGHeight)) {
svgSize.width = results.enableBGWidth;
svgSize.height = results.enableBGHeight;
}

// Resolve the promise
Expand Down
1 change: 1 addition & 0 deletions unittest-files/svg/toolbar-all-props.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions unittest-files/svg/toolbar-enable-background.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions unittest-files/svg/toolbar-viewBox.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions unittest-files/svg/toolbar-width-height.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions unittests.js
@@ -0,0 +1,72 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 2, maxerr: 50 */
/*global describe, it, define, runs, expect, waitsFor */

/*
* HTML Skeleton
* Created 2014-2015 Triangle717
* <http://le717.github.io/>
*
* Licensed under The MIT License
* <http://opensource.org/licenses/MIT/>
*/


define(function (require, exports, module) {
"use strict";

var FileUtils = brackets.getModule("file/FileUtils"),
SvgSize = require("src/SvgSize");

var extensionPath = FileUtils.getNativeModuleDirectoryPath(module);


describe("HTML Skeleton", function () {

describe("SVG graphic dimensions extraction", function () {
var testPath = extensionPath + "/unittest-files/svg/",
SvgEBack = testPath + "toolbar-enable-background.svg",
SvgViewBox = testPath + "toolbar-viewBox.svg",
SvgAllProps = testPath + "toolbar-all-props.svg",
SvgWidthHeight = testPath + "toolbar-width-height.svg";


function confirmDimensions(file, expectedSizes) {
var complete = false,
extracted = null;

SvgSize.get(file).then(function (obj) {
complete = true;
extracted = obj;
});

waitsFor(function () {
return complete;
}, "Expected dimensions did not resolve", 3000);

runs(function () {
expect(extracted).not.toBeNull();
expect(extracted.width).toBe(expectedSizes.width);
expect(extracted.height).toBe(expectedSizes.height);
});
}

it("should extract the width and height values from an SVG", function () {
confirmDimensions(SvgWidthHeight, {width: "24", height: "24"});
});

it("should extract the viewBox values from an SVG", function () {
confirmDimensions(SvgViewBox, {width: "24", height: "24"});
});

it("should extract the enable-background values from an SVG", function () {
confirmDimensions(SvgEBack, {width: "24", height: "24"});
});

it("should extract the width and height values from an SVG containing all supported properties", function () {
confirmDimensions(SvgAllProps, {width: "24", height: "24"});
});

});

});
});

0 comments on commit 02d2e7f

Please sign in to comment.