Skip to content

Commit

Permalink
fix: add time value units (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeno authored and shellscape committed Jun 26, 2019
1 parent b73b1d9 commit 926df59
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/nodes/Numeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
7 changes: 6 additions & 1 deletion test/fixtures/numeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
};
Expand Down
289 changes: 289 additions & 0 deletions test/snapshots/numeric.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<input css 26>',
},
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: '<input css 27>',
},
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: '<input css 27>',
},
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: '<input css 27>',
},
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: '<input css 23>',
},
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: '<input css 25>',
},
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: '<input css 25>',
},
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: '<input css 25>',
},
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: '<input css 24>',
},
start: {
column: 1,
line: 1,
},
},
type: 'numeric',
unit: 'ms',
value: '500',
},
]
Binary file modified test/snapshots/numeric.test.js.snap
Binary file not shown.

0 comments on commit 926df59

Please sign in to comment.