Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.1 parsing #166

Merged
merged 3 commits into from
Feb 14, 2020
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
2 changes: 1 addition & 1 deletion src/parser/LexerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const RParen = createToken({name: 'RParen', pattern: /\)/})
export const ProcedureName = createToken({name: 'ProcedureName', pattern: /(\.?[0-9A-Za-z\u00C0-\u02AF]+)+\(/})

/* terminals */
export const NumberLiteral = createToken({name: 'NumberLiteral', pattern: /\d+(\.\d+)?/})
export const NumberLiteral = createToken({name: 'NumberLiteral', pattern: /[\d]*[.]?[\d]+/ })

/* string literal */
export const StringLiteral = createToken({name: 'StringLiteral', pattern: /"([^"\\]*(\\.[^"\\]*)*)"/})
Expand Down
16 changes: 16 additions & 0 deletions test/parser/decimal.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {HyperFormula} from '../../src'
import {adr} from '../testUtils'

describe( 'decimal parsing', () => {
it('parsing decimal without leading zero', () => {
const engine = HyperFormula.buildFromArray([
['.1', '=.1'],
['-.1', '=-.1']
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add few more tests? To future proof our tests and be sure that decimal is parsed correctly within the functions and with operators:

      ['.1', '=.1'],
      ['-.1', '=-.1'],
      ['+.1', '=+.1'],
      ['+.1', '=+.1+.2'],
      ['=SUM(A1:A4, 0.3, .3)', '=SUM(B1:B4)'],
      ['.1.4', '=..1'],

Maybe you can add some more

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, didn't notice your comment here. I'll add it in some other commit.


expect(engine.getCellValue(adr('A1'))).toBe(0.1)
expect(engine.getCellValue(adr('B1'))).toBe(0.1)
expect(engine.getCellValue(adr('A2'))).toBe(-0.1)
expect(engine.getCellValue(adr('B2'))).toBe(-0.1)
})
})