Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Fixed
- Text with numbers is no longer right aligned ([#405](https://github.com/cucumber/react-components/pull/405))

### Added
- Include duration for each test step ([#396](https://github.com/cucumber/react-components/pull/396))
- Include pass rate in execution summary ([#397](https://github.com/cucumber/react-components/pull/397))
Expand Down
22 changes: 22 additions & 0 deletions src/components/gherkin/isNumber.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect } from 'chai'

import isNumber from './isNumber.js'

describe('isNumber is true', () => {
const numbers = ['1', '-1', '10', '1.0', '.0', '1,0', '1 000,00', '127.0.0.0', '10E-05', '10E+05']

numbers.forEach((value) => {
it(`${value}`, () => {
expect(isNumber(value)).to.be.true
})
})
})
describe('isNumber is false', () => {
const nonNumbers = ['hello', 'hello world', '-', '+', '1.', '1,', 'Ramayan 3392 A.D.', 'E+10']

nonNumbers.forEach((value) => {
it(`${value}`, () => {
expect(isNumber(value)).to.be.false
})
})
})
3 changes: 2 additions & 1 deletion src/components/gherkin/isNumber.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Lifted from cucumber-expressions/javascript/src/ParameterTypeRegistry#FLOAT_REGEXP
const numberPattern = /(?=.*\d.*)[-+]?\d*(?:\.(?=\d.*))?\d*(?:\d+[E][+-]?\d+)?/
// Modified to allow spaces, commas and periods as decimal- and/or as thousand-separators
const numberPattern = /^(?=.*\d.*)[-+]?\d*(?:[., ](?=\d.*)\d*)*(?:\d+E[+-]?\d+)?$/

export default function isNumber(s: string): boolean {
return !!s.match(numberPattern)
Expand Down