From 926df59be392866c6f9f77a047fbe1b37b8dc823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radovan=20=C5=A0mitala?= Date: Wed, 26 Jun 2019 17:48:07 +0200 Subject: [PATCH] fix: add time value units (#87) --- lib/nodes/Numeric.js | 2 +- test/fixtures/numeric.js | 7 +- test/snapshots/numeric.test.js.md | 289 ++++++++++++++++++++++++++++ test/snapshots/numeric.test.js.snap | Bin 3194 -> 3745 bytes 4 files changed, 296 insertions(+), 2 deletions(-) diff --git a/lib/nodes/Numeric.js b/lib/nodes/Numeric.js index 5cf25a4..d64dbf2 100644 --- a/lib/nodes/Numeric.js +++ b/lib/nodes/Numeric.js @@ -14,7 +14,7 @@ const { registerWalker } = require('../walker'); const Node = require('./Node'); -const unitRegex = /%|ch|cm|em|ex|in|mm|pc|pt|px|q|rem|vh|vmax|vmin|vw$/i; +const unitRegex = /%|ch|cm|em|ex|in|mm|ms|pc|pt|px|s|q|rem|vh|vmax|vmin|vw$/i; class Numeric extends Node { constructor(options = {}) { diff --git a/test/fixtures/numeric.js b/test/fixtures/numeric.js index cbedc06..7bf99ae 100644 --- a/test/fixtures/numeric.js +++ b/test/fixtures/numeric.js @@ -31,7 +31,12 @@ module.exports = { '1E+10', '-.567800E-0012780em', '.1E-10', - '.1E+10' + '.1E+10', + '0.5s', + '500ms', + '0.5s + 0.5s', + '-.3s', + '-.3s + 0.5s' ], throws: ['+-2.', '.', '.rem', '.2.3rem'] }; diff --git a/test/snapshots/numeric.test.js.md b/test/snapshots/numeric.test.js.md index 75986bf..c898dbe 100644 --- a/test/snapshots/numeric.test.js.md +++ b/test/snapshots/numeric.test.js.md @@ -1051,3 +1051,292 @@ Generated by [AVA](https://ava.li). value: '5', }, ] + +## -.3s + +> Snapshot 1 + + '-.3s' + +> Snapshot 2 + + '-.3s' + +> Snapshot 3 + + [ + Numeric { + raws: { + after: '', + before: '', + }, + source: { + end: { + column: 1, + line: 1, + }, + input: Input { + css: '-.3s', + hasBOM: false, + id: '', + }, + start: { + column: 1, + line: 1, + }, + }, + type: 'numeric', + unit: 's', + value: '-.3', + }, + ] + +## -.3s + 0.5s + +> Snapshot 1 + + '-.3s' + +> Snapshot 2 + + '-.3s + 0.5s' + +> Snapshot 3 + + [ + Numeric { + raws: { + after: '', + before: '', + }, + source: { + end: { + column: 1, + line: 1, + }, + input: Input { + css: '-.3s + 0.5s', + hasBOM: false, + id: '', + }, + start: { + column: 1, + line: 1, + }, + }, + type: 'numeric', + unit: 's', + value: '-.3', + }, + Operator { + raws: { + after: '', + before: ' ', + }, + source: { + end: { + column: 6, + line: 1, + }, + input: Input { + css: '-.3s + 0.5s', + hasBOM: false, + id: '', + }, + start: { + column: 6, + line: 1, + }, + }, + type: 'operator', + value: '+', + }, + Numeric { + raws: { + after: '', + before: ' ', + }, + source: { + end: { + column: 8, + line: 1, + }, + input: Input { + css: '-.3s + 0.5s', + hasBOM: false, + id: '', + }, + start: { + column: 8, + line: 1, + }, + }, + type: 'numeric', + unit: 's', + value: '0.5', + }, + ] + +## 0.5s + +> Snapshot 1 + + '0.5s' + +> Snapshot 2 + + '0.5s' + +> Snapshot 3 + + [ + Numeric { + raws: { + after: '', + before: '', + }, + source: { + end: { + column: 1, + line: 1, + }, + input: Input { + css: '0.5s', + hasBOM: false, + id: '', + }, + start: { + column: 1, + line: 1, + }, + }, + type: 'numeric', + unit: 's', + value: '0.5', + }, + ] + +## 0.5s + 0.5s + +> Snapshot 1 + + '0.5s' + +> Snapshot 2 + + '0.5s + 0.5s' + +> Snapshot 3 + + [ + Numeric { + raws: { + after: '', + before: '', + }, + source: { + end: { + column: 1, + line: 1, + }, + input: Input { + css: '0.5s + 0.5s', + hasBOM: false, + id: '', + }, + start: { + column: 1, + line: 1, + }, + }, + type: 'numeric', + unit: 's', + value: '0.5', + }, + Operator { + raws: { + after: '', + before: ' ', + }, + source: { + end: { + column: 6, + line: 1, + }, + input: Input { + css: '0.5s + 0.5s', + hasBOM: false, + id: '', + }, + start: { + column: 6, + line: 1, + }, + }, + type: 'operator', + value: '+', + }, + Numeric { + raws: { + after: '', + before: ' ', + }, + source: { + end: { + column: 8, + line: 1, + }, + input: Input { + css: '0.5s + 0.5s', + hasBOM: false, + id: '', + }, + start: { + column: 8, + line: 1, + }, + }, + type: 'numeric', + unit: 's', + value: '0.5', + }, + ] + +## 500ms + +> Snapshot 1 + + '500ms' + +> Snapshot 2 + + '500ms' + +> Snapshot 3 + + [ + Numeric { + raws: { + after: '', + before: '', + }, + source: { + end: { + column: 1, + line: 1, + }, + input: Input { + css: '500ms', + hasBOM: false, + id: '', + }, + start: { + column: 1, + line: 1, + }, + }, + type: 'numeric', + unit: 'ms', + value: '500', + }, + ] diff --git a/test/snapshots/numeric.test.js.snap b/test/snapshots/numeric.test.js.snap index 26556f41b3e5a1b41595a2a2d677654c9d377199..1b85ca3f4ee26313f5030f5728c719f7507e2d8b 100644 GIT binary patch literal 3745 zcmV;S4qov=RzV(IxSb|a;^)sMC+E(bOy+;j zJu`Q%E$)58d9Z%?zuT$+7q^uqkh z(~}w<5M^r-WjRHNA|z$YhPhc$;iDZZcMh$yy6aj|w#HKKq>PCrWWd<@$F?*W^!m=b zdM?rBdG%KWXyZqy6!I4C++^*S8WSK*}9W*gp%3<-{{Md zw59jEnq@ScwoAV?ccUme=Ux@6R#|6Kh_l&$?J!zjBRCFEaeGbf#UIdVY3q3)YsoZaB8C|kd# zoTc=9j1Z?|--(F>(h@gEUKl&H|KP=<+e#^<9O^~Lgz|V%@hFuPSbHXsIY$ zPf)H>20j7Lr56SlnbVAMyRRMS@#@JRMAWVnzV@yR(+ zwpu9;%CdokoVxhZcfuRDZkm=58gAU!D@2s7rIg(i>mWjMTRKO%LK91id%b?7>4o1z zW|Fldr4Qv@Cn2kxlb4NK*!r`WpZ3(bvgU_wqHNtsIYLRzCS-Nl)Ux?gTfN#TR@Zp{ zkuM-w$=Z#QN%?*x^f`U{mYK2U;_fS18?unU~@Y$T+6L5?#oJ44W6hdl;8?aXk+#KaIG zQ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