Skip to content

Commit

Permalink
Merge pull request #4 from kijowski/fromHex-fix
Browse files Browse the repository at this point in the history
fromHex fix
  • Loading branch information
williamngan authored Nov 3, 2017
2 parents 9b1e531 + 33d7165 commit baba0f2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/files/Color.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Color extends Pt {

if (hex[0] == "#") hex = hex.substr(1); // remove '#' if needed
if (hex.length <= 3) {
let fn = (i) => hex[1]||"F";
let fn = (i) => hex[i]||"F";
hex = `${fn(0)}${fn(0)}${fn(1)}${fn(1)}${fn(2)}${fn(2)}`;
}

Expand Down
39 changes: 39 additions & 0 deletions src/test/Color.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import chai = require('chai');
import mocha = require('mocha');
import {Pt, Group} from '../Pt';
import {Geom, Num} from '../Num';
import {Color} from '../Color';

var {assert} = chai;
var {describe, it} = mocha;

describe('Color: ', function() {

describe('fromHex: ', function() {
it('works with explicit hash in input string', function() {
const actual = Color.fromHex("#FFFF00");
const expected = [255, 255, 0];
assert.isTrue( actual.equals(expected));
// assert.equal( [actual.r,actual.g, actual.b], expected );
});

it('works without explicit hash in input string', function() {
const actual = Color.fromHex("FFFF00");
const expected = [255, 255, 0];
assert.isTrue( actual.equals(expected));
});

it('works with all character cases', function() {
const actual = Color.fromHex("FffF00");
const expected = [255, 255, 0];
assert.isTrue( actual.equals(expected));
});

it('works with short form', function() {
const actual = Color.fromHex("FF0");
const expected = [255, 255, 0];
assert.isTrue( actual.equals(expected));
});
});

});

0 comments on commit baba0f2

Please sign in to comment.