From 42919e5571734cce91a098867ea2dd2fa9fe894b Mon Sep 17 00:00:00 2001 From: Dima Voytenko Date: Wed, 4 May 2016 17:53:18 -0700 Subject: [PATCH] Asolute length units support --- src/layout.js | 5 +++-- test/functional/test-layout.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/layout.js b/src/layout.js index 7c014740fe68..ad46534946db 100644 --- a/src/layout.js +++ b/src/layout.js @@ -152,7 +152,7 @@ export function parseLength(s) { if (!s) { return undefined; } - if (!/^\d+(\.\d+)?(px|em|rem|vh|vw|vmin|vmax)?$/.test(s)) { + if (!/^\d+(\.\d+)?(px|em|rem|vh|vw|vmin|vmax|cm|mm|q|in|pc|pt)?$/.test(s)) { return undefined; } if (/^\d+(\.\d+)?$/.test(s)) { @@ -169,7 +169,8 @@ export function parseLength(s) { * @return {!LengthDef} */ export function assertLength(length) { - user.assert(/^\d+(\.\d+)?(px|em|rem|vh|vw|vmin|vmax)$/.test(length), + user.assert( + /^\d+(\.\d+)?(px|em|rem|vh|vw|vmin|vmax|cm|mm|q|in|pc|pt)$/.test(length), 'Invalid length value: %s', length); return length; } diff --git a/test/functional/test-layout.js b/test/functional/test-layout.js index 1c59e0367998..e553bedabe70 100644 --- a/test/functional/test-layout.js +++ b/test/functional/test-layout.js @@ -46,6 +46,12 @@ describe('Layout', () => { expect(parseLength('10px')).to.equal('10px'); expect(parseLength('10em')).to.equal('10em'); expect(parseLength('10vmin')).to.equal('10vmin'); + expect(parseLength('10cm')).to.equal('10cm'); + expect(parseLength('10mm')).to.equal('10mm'); + expect(parseLength('10in')).to.equal('10in'); + expect(parseLength('10pt')).to.equal('10pt'); + expect(parseLength('10pc')).to.equal('10pc'); + expect(parseLength('10q')).to.equal('10q'); expect(parseLength(10.1)).to.equal('10.1px'); expect(parseLength('10.2')).to.equal('10.2px'); @@ -84,6 +90,12 @@ describe('Layout', () => { expect(assertLength('10px')).to.equal('10px'); expect(assertLength('10em')).to.equal('10em'); expect(assertLength('10vmin')).to.equal('10vmin'); + expect(assertLength('10cm')).to.equal('10cm'); + expect(assertLength('10mm')).to.equal('10mm'); + expect(assertLength('10in')).to.equal('10in'); + expect(assertLength('10pt')).to.equal('10pt'); + expect(assertLength('10pc')).to.equal('10pc'); + expect(assertLength('10q')).to.equal('10q'); expect(assertLength('10.1px')).to.equal('10.1px'); expect(assertLength('10.1em')).to.equal('10.1em');