Skip to content

Commit

Permalink
Merge pull request #51 from vsmalladi/33-unrecognzied-symbols
Browse files Browse the repository at this point in the history
Updated regex to not get hung up in 2 in H2O units. #33
  • Loading branch information
gentooboontoo committed Oct 1, 2015
2 parents 6d72047 + 9f69260 commit 3a18ec8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions spec/quantitiesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ describe("js-quantities", function() {
expect(qty.denominator).toEqual(["<1>"]);
});

it("should create pressure units in term of height of water", function() {
var qty = Qty("1 inH2O");
expect(qty.scalar).toBe(1);
expect(qty.numerator).toEqual(["<inh2o>"]);

qty = Qty("1 cmH2O");
expect(qty.scalar).toBe(1);
expect(qty.numerator).toEqual(["<cmh2o>"]);
});

it("should create with denominator", function() {
var qty = Qty("1 m/s");
expect(qty.scalar).toBe(1);
Expand Down
4 changes: 2 additions & 2 deletions src/quantities.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var QTY_STRING = "(" + SIGNED_NUMBER + ")?" + "\\s*([^/]*)(?:\/(.+))?";
var QTY_STRING_REGEX = new RegExp("^" + QTY_STRING + "$");
var POWER_OP = "\\^|\\*{2}";
var TOP_REGEX = new RegExp ("([^ \\*]+?)(?:" + POWER_OP + ")?(-?\\d+)");
var BOTTOM_REGEX = new RegExp("([^ \\*]+?)(?:" + POWER_OP + ")?(\\d+)");
var TOP_REGEX = new RegExp ("([^ \\*]+?)(?:" + POWER_OP + ")?(-?\\d+(?![a-zA-Z]))");
var BOTTOM_REGEX = new RegExp("([^ \\*]+?)(?:" + POWER_OP + ")?(\\d+(?![a-zA-Z]))");

var SIGNATURE_VECTOR = ["length", "time", "temperature", "mass", "current", "substance", "luminosity", "currency", "information", "angle", "capacitance"];
var KINDS = {
Expand Down

0 comments on commit 3a18ec8

Please sign in to comment.