File: test/Debug.test.ts

Recommend this page to a friend!
  Packages of ikhsan   jQuery Calx   test/Debug.test.ts   Download  
File: test/Debug.test.ts
Role: Example script
Content type: text/plain
Description: Example script
Class: jQuery Calx
Calculate form input values based on formulas
Author: By
Last change:
Date: 3 months ago
Size: 1,269 bytes
 

Contents

Class file image Download
import { Calx } from '../src/Calx'; import { CalxInterpreter } from '../src/Calx/Parser/Chevrotain/Interpreter'; import { SharedContext } from '../src/Calx/Parser/SharedContext'; import * as Utility from '../src/Calx/Utility/Utility'; describe('Simple Debug', () => { test('parser should work with literals', () => { const context = new SharedContext({ utility: Utility }); const interpreter = new CalxInterpreter(); interpreter.setContext(context); const result = interpreter.parse('=5+3'); expect(result).toBe(8); }); test('should work with direct value', () => { const workbook = Calx.createWorkbook(); const sheet = workbook.createSheet('Test'); sheet.createCell('A1', { value: 10 }); sheet.createCell('A2', { formula: '=A1' }); workbook.build(); workbook.calculate(); expect(sheet.getCellValue('A2')).toBe(10); }); test('should work with simple arithmetic', () => { const workbook = Calx.createWorkbook(); const sheet = workbook.createSheet('Test'); sheet.createCell('A1', { formula: '=5+3' }); workbook.build(); workbook.calculate(); expect(sheet.getCellValue('A1')).toBe(8); }); });