From 344b912bd2dc30911f2aae0fbab1c7f5fa7677cd Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Sat, 8 Feb 2025 11:37:23 +0000 Subject: [PATCH 01/11] v4.4.0-develop --- Spreadsheet.cfc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spreadsheet.cfc b/Spreadsheet.cfc index 24af418..31bd276 100644 --- a/Spreadsheet.cfc +++ b/Spreadsheet.cfc @@ -1,7 +1,7 @@ component accessors="true"{ //"static" - property name="version" default="4.4.0" setter="false"; + property name="version" default="4.4.0-develop" setter="false"; property name="osgiLibBundleVersion" default="5.4.0.0" setter="false"; //first 3 octets = POI version; increment 4th with other jar updates property name="osgiLibBundleSymbolicName" default="spreadsheet-cfml" setter="false"; property name="exceptionType" default="cfsimplicity.spreadsheet" setter="false"; From b8894ba107fc6d949f3e513b562ec9cad30d5e49 Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Sat, 8 Feb 2025 18:08:03 +0000 Subject: [PATCH 02/11] Fix typo (on unused method name) --- helpers/base.cfc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpers/base.cfc b/helpers/base.cfc index 61879ef..8cbd305 100644 --- a/helpers/base.cfc +++ b/helpers/base.cfc @@ -29,8 +29,8 @@ component{ return library().getColumnHelper(); } - any function getCommetHelper(){ - return library().getCommetHelper(); + any function getCommentHelper(){ + return library().getCommentHelper(); } any function getCsvHelper(){ From 8a5ded589ffa4b9cc3aaded4477d91fb7e7da2bf Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Sun, 9 Feb 2025 10:36:45 +0000 Subject: [PATCH 03/11] Improve readability of tests --- test/specs/addAutoFilter.cfm | 31 +- test/specs/addColumn.cfm | 140 ++++----- test/specs/addFreezePane.cfm | 40 +-- test/specs/addImage.cfm | 58 ++-- test/specs/addPageBreaks.cfm | 52 ++-- test/specs/addRow.cfm | 216 +++++++------- test/specs/addRows.cfm | 358 +++++++++++------------ test/specs/addSplitPane.cfm | 32 +-- test/specs/autoSizeColumn.cfm | 38 +-- test/specs/binaryFromQuery.cfm | 8 +- test/specs/cellComment.cfm | 54 ++-- test/specs/cellFormula.cfm | 56 ++-- test/specs/cellHyperLink.cfm | 132 ++++----- test/specs/cellRangeValue.cfm | 24 +- test/specs/cellStyle.cfm | 66 ++--- test/specs/cellValue.cfm | 214 +++++++------- test/specs/chaining.cfm | 60 ++-- test/specs/clearCell.cfm | 40 +-- test/specs/columnWidth.cfm | 20 +- test/specs/conditionalFormatting.cfm | 64 ++--- test/specs/createJavaObject.cfm | 8 +- test/specs/createSheet.cfm | 74 ++--- test/specs/csvToQuery.cfm | 172 +++++------ test/specs/dataValidation.cfm | 142 +++++----- test/specs/dateFormats.cfm | 34 +-- test/specs/deleteColumn.cfm | 38 +-- test/specs/deleteColumns.cfm | 38 +-- test/specs/deleteRow.cfm | 38 +-- test/specs/deleteRows.cfm | 38 +-- test/specs/formatCell.cfm | 350 +++++++++++------------ test/specs/formatCellRange.cfm | 36 +-- test/specs/formatColumn.cfm | 44 +-- test/specs/formatColumns.cfm | 50 ++-- test/specs/formatRow.cfm | 28 +- test/specs/formatRows.cfm | 50 ++-- test/specs/getCellAddress.cfm | 38 +-- test/specs/getCellType.cfm | 24 +- test/specs/getColumnCount.cfm | 60 ++-- test/specs/getEnvironment.cfm | 8 +- test/specs/getPresetColorNames.cfm | 8 +- test/specs/getRowCount.cfm | 72 ++--- test/specs/hideColumn.cfm | 24 +- test/specs/hideRow.cfm | 24 +- test/specs/info.cfm | 40 +-- test/specs/isSpreadsheetFile.cfm | 32 +-- test/specs/isSpreadsheetObject.cfm | 16 +- test/specs/isXmlOrBinaryFormat.cfm | 16 +- test/specs/javaClassLoading.cfm | 18 +- test/specs/mergeCells.cfm | 60 ++-- test/specs/moveSheet.cfm | 48 ++-- test/specs/new.cfm | 42 +-- test/specs/newXls.cfm | 12 +- test/specs/newXlsx.cfm | 12 +- test/specs/printGridLines.cfm | 32 +-- test/specs/queryToCsv.cfm | 50 ++-- test/specs/read.cfm | 360 ++++++++++++------------ test/specs/readBinary.cfm | 20 +- test/specs/readCsv.cfm | 90 +++--- test/specs/readLargeFile.cfm | 212 +++++++------- test/specs/removeSheet.cfm | 48 ++-- test/specs/removeSheetNumber.cfm | 38 +-- test/specs/renameSheet.cfm | 38 +-- test/specs/richText.cfm | 72 ++--- test/specs/setActiveCell.cfm | 28 +- test/specs/setActiveSheet.cfm | 56 ++-- test/specs/setActiveSheetNumber.cfm | 38 +-- test/specs/setFitToPage.cfm | 32 +-- test/specs/setFooter.cfm | 24 +- test/specs/setFooterImage.cfm | 38 +-- test/specs/setHeader.cfm | 24 +- test/specs/setHeaderImage.cfm | 38 +-- test/specs/setRepeatingColumns.cfm | 24 +- test/specs/setRepeatingRows.cfm | 24 +- test/specs/setRowHeight.cfm | 38 +-- test/specs/setSheetMargins.cfm | 62 ++-- test/specs/setSheetPrintOrientation.cfm | 64 ++--- test/specs/sheetInfo.cfm | 20 +- test/specs/shiftColumns.cfm | 32 +-- test/specs/shiftRows.cfm | 32 +-- test/specs/showColumn.cfm | 24 +- test/specs/showRow.cfm | 20 +- test/specs/workbookFromCsv.cfm | 24 +- test/specs/workbookFromQuery.cfm | 24 +- test/specs/write.cfm | 52 ++-- test/specs/writeCsv.cfm | 102 +++---- test/specs/writeFileFromQuery.cfm | 24 +- test/specs/writeToCsv.cfm | 62 ++-- 87 files changed, 2631 insertions(+), 2632 deletions(-) diff --git a/test/specs/addAutoFilter.cfm b/test/specs/addAutoFilter.cfm index e34847b..9ae6845 100644 --- a/test/specs/addAutoFilter.cfm +++ b/test/specs/addAutoFilter.cfm @@ -1,33 +1,32 @@ -describe( "addAutoFilter", function(){ +describe( "addAutoFilter", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var data = QueryNew( "Header1,Header2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var xls = s.workbookFromQuery( data ); var xlsx = s.workbookFromQuery( data=data, xmlformat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "Doesn't error when passing valid arguments", function() { - workbooks.Each( function( wb ){ + it( "Doesn't error when passing valid arguments", ()=>{ + workbooks.Each( ( wb )=>{ s.addAutoFilter( wb, "A1:B1" ) .addAutoFilter( wb )// default to all cols in first row if no row range passed .addAutoFilter( workbook=wb, row=2 );// allow row to be specified instead of range - }); - - }); + }) + }) - it( "Doesn't error when passing valid arguments with extra trailing/leading space", function() { - workbooks.Each( function( wb ){ + it( "Doesn't error when passing valid arguments with extra trailing/leading space", ()=>{ + workbooks.Each( ( wb )=>{ s.addAutoFilter( wb, " A1:B1 " ); - }); - }); + }) + }) - it( "Is chainable", function() { + it( "Is chainable", ()=>{ workbooks.Each( function( wb ){ s.newChainable( wb ).addAutoFilter( " A1:B1 " ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/addColumn.cfm b/test/specs/addColumn.cfm index ecbb769..c17278e 100644 --- a/test/specs/addColumn.cfm +++ b/test/specs/addColumn.cfm @@ -1,40 +1,40 @@ -describe( "addColumn", function(){ +describe( "addColumn", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.columnData = "a,b"; variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Adds a column with the minimum arguments", function(){ - workbooks.Each( function( wb ){ + it( "Adds a column with the minimum arguments", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, columnData ); var expected = QueryNew( "column1", "VarChar", [ [ "a" ], [ "b" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Adds a column with the minimum arguments using array data", function(){ - workbooks.Each( function( wb ){ + it( "Adds a column with the minimum arguments using array data", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, columnData.ListToArray() ); var expected = QueryNew( "column1", "VarChar", [ [ "a" ], [ "b" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Adds a column at a given NEW start row", function(){ - workbooks.Each( function( wb ){ + it( "Adds a column at a given NEW start row", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( workbook=wb, data=columnData, startRow=2 ); var expected = QueryNew( "column1", "VarChar", [ [ "" ], [ "a" ], [ "b" ] ] ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Adds a column at a given EXISTING start row", function(){ - workbooks.Each( function( wb ){ + it( "Adds a column at a given EXISTING start row", ()=>{ + workbooks.Each( ( wb )=>{ s.addRows( wb, [ [ "x" ], [ "y" ] ] ) .addColumn( workbook=wb, data=columnData, startRow=2 ); var expected = querySim( "column1,column2 @@ -44,43 +44,43 @@ describe( "addColumn", function(){ "); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Adds a column at a given column number", function(){ - workbooks.Each( function( wb ){ + it( "Adds a column at a given column number", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( workbook=wb, data=columnData, startColumn=2 ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "a" ], [ "", "b" ] ] ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Adds a column including commas with a custom delimiter", function(){ - workbooks.Each( function( wb ){ + it( "Adds a column including commas with a custom delimiter", ()=>{ + workbooks.Each( ( wb )=>{ var columnData = "a,b|c,d"; s.addColumn( workbook=wb, data=columnData, delimiter="|" ); var expected = QueryNew( "column1", "VarChar", [ [ "a,b" ], [ "c,d" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Allows the data type to be specified", function(){ + it( "Allows the data type to be specified", ()=>{ var columnData = [ 1.234 ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( workbook=wb, data=columnData, datatype="string" ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( "1.234" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - describe( "Insert behaviour", function(){ + describe( "Insert behaviour", ()=>{ - it( "Inserts column after existing columns by default", function(){ - workbooks.Each( function( wb ){ + it( "Inserts column after existing columns by default", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, columnData ) .addColumn( wb, [ "c", "d" ] ); var expected = querySim( "column1,column2 @@ -89,11 +89,11 @@ describe( "addColumn", function(){ "); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "By default, overwrites an existing column if 'startColumn' is specified", function(){ - workbooks.Each( function( wb ){ + it( "By default, overwrites an existing column if 'startColumn' is specified", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "a,b" ) .addColumn( workbook=wb, data="x,y", startColumn=1 ); var expected = QueryNew( "column1", "VarChar", [ [ "x" ], [ "y" ] ] ); @@ -107,11 +107,11 @@ describe( "addColumn", function(){ "); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Shifts columns to the right if startColumn is specified and column already exists and 'insert=true'", function(){ - workbooks.Each( function( wb ){ + it( "Shifts columns to the right if startColumn is specified and column already exists and 'insert=true'", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, [ "a", "b" ] ) .addColumn( wb, [ "c", "d" ] ) .addColumn( wb, [ "e", "f" ] ) @@ -122,33 +122,33 @@ describe( "addColumn", function(){ "); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - }); + }) - it( "Adds numeric values correctly", function(){ - workbooks.Each( function( wb ){ + it( "Adds numeric values correctly", ()=>{ + workbooks.Each( ( wb )=>{ var rowData = "1,1.1"; s.addColumn( wb, rowData ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( 1 ); expect( s.getCellValue( wb, 2, 1 ) ).toBe( 1.1 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 2, 1 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Adds boolean values as strings", function(){ - workbooks.Each( function( wb ){ + it( "Adds boolean values as strings", ()=>{ + workbooks.Each( ( wb )=>{ var rowData = true; s.addColumn( wb, rowData ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( true ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Adds date/time values correctly", function(){ - workbooks.Each( function( wb ){ + it( "Adds date/time values correctly", ()=>{ + workbooks.Each( ( wb )=>{ var dateValue = CreateDate( 2015, 04, 12 ); var timeValue = _CreateTime( 1, 0, 0 ); var dateTimeValue = CreateDateTime( 2015, 04, 12, 1, 0, 0 ); @@ -160,31 +160,31 @@ describe( "addColumn", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 2, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 3, 1 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Adds zeros as zeros, not booleans", function(){ - workbooks.Each( function( wb ){ + it( "Adds zeros as zeros, not booleans", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, 0 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Adds strings with leading zeros as strings not numbers", function(){ - workbooks.Each( function( wb ){ + it( "Adds strings with leading zeros as strings not numbers", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "01" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).addColumn( columnData ); var expected = QueryNew( "column1", "VarChar", [ [ "a" ], [ "b" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/addFreezePane.cfm b/test/specs/addFreezePane.cfm index 464e2ee..96cce33 100644 --- a/test/specs/addFreezePane.cfm +++ b/test/specs/addFreezePane.cfm @@ -1,15 +1,15 @@ -describe( "addFreezePane", function(){ +describe( "addFreezePane", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var data = QueryNew( "Header1,Header2,Header3", "VarChar,VarChar,Varchar", [ [ "a", "b", "c" ], [ "d", "e", "f" ], [ "g", "h", "i" ] ] ); var xls = s.workbookFromQuery( data ); var xlsx = s.workbookFromQuery( data=data, xmlformat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "Creates a freezepane split horizontally and/or vertically", function() { - workbooks.Each( function( wb ){ + it( "Creates a freezepane split horizontally and/or vertically", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getPaneInformation() ).toBeNull(); s.addFreezePane( wb, 0, 1 ); @@ -24,12 +24,12 @@ describe( "addFreezePane", function(){ expect( sheet.getPaneInformation().isFreezePane() ).toBeTrue(); expect( sheet.getPaneInformation().getVerticalSplitPosition() ).toBe( 1 ); expect( sheet.getPaneInformation().getHorizontalSplitPosition() ).toBe( 0 ); - }); + }) - }); + }) - it( "Can optionally set the visible left column in the right pane and/or top row in the bottom pane", function() { - workbooks.Each( function( wb ){ + it( "Can optionally set the visible left column in the right pane and/or top row in the bottom pane", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); s.addFreezePane( wb, 1, 1, 3 ); expect( sheet.getPaneInformation().isFreezePane() ).toBeTrue(); @@ -43,12 +43,12 @@ describe( "addFreezePane", function(){ expect( sheet.getPaneInformation().isFreezePane() ).toBeTrue(); expect( sheet.getPaneInformation().getVerticalSplitLeftColumn() ).toBe( 3 ); expect( sheet.getPaneInformation().getHorizontalSplitTopRow() ).toBe( 3 ); - }); + }) - }); + }) - it( "Can remove a freezepane by passing in zeros", function() { - workbooks.Each( function( wb ){ + it( "Can remove a freezepane by passing in zeros", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); s.addFreezePane( wb, 0, 1 ); expect( sheet.getPaneInformation().isFreezePane() ).toBeTrue(); @@ -56,20 +56,20 @@ describe( "addFreezePane", function(){ expect( sheet.getPaneInformation().getHorizontalSplitPosition() ).toBe( 1 ); s.addFreezePane( wb, 0, 0 ); expect( sheet.getPaneInformation() ).toBeNull(); - }); + }) - }); + }) - it( "Is chainable", function() { - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getPaneInformation() ).toBeNull(); s.newChainable( wb ).addFreezePane( 0, 1 ); expect( sheet.getPaneInformation().isFreezePane() ).toBeTrue(); expect( sheet.getPaneInformation().getVerticalSplitPosition() ).toBe( 0 ); expect( sheet.getPaneInformation().getHorizontalSplitPosition() ).toBe( 1 ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/addImage.cfm b/test/specs/addImage.cfm index 7d609b2..6a48dce 100644 --- a/test/specs/addImage.cfm +++ b/test/specs/addImage.cfm @@ -1,58 +1,58 @@ -describe( "addImage", function(){ +describe( "addImage", ()=>{ - it( "Doesn't error when adding an image to a spreadsheet", function(){ + it( "Doesn't error when adding an image to a spreadsheet", ()=>{ var imagePath = getTestFilePath( "test.png" ); var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ) { + workbooks.Each( ( wb )=>{ s.addImage( workbook=wb, filepath=imagePath, anchor="1,1,2,2" ); var imageData = ImageNew( "", 10, 10, "rgb", "blue" ); s.addImage( workbook=wb, imageData=imageData, imageType="png", anchor="1,2,2,3" ); expect( wb.getAllPictures() ).toHaveLength( 2 ); - }); - }); + }) + }) - it( "Is chainable", function(){ + it( "Is chainable", ()=>{ var imagePath = getTestFilePath( "test.png" ); var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ) { + workbooks.Each( ( wb )=>{ s.newChainable( wb ).addImage( filepath=imagePath, anchor="1,1,2,2" ); - }); - }); + }) + }) - describe( "throws an exception if", function(){ + describe( "throws an exception if", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "no image is provided", function(){ - workbooks.Each( function( wb ) { - expect( function(){ + it( "no image is provided", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addImage( workbook=wb, anchor="1,1,2,2" ); }).toThrow( type="cfsimplicity.spreadsheet.missingImageArgument" ); - }); - }); + }) + }) - it( "imageData is provided with no imageType", function(){ - workbooks.Each( function( wb ) { - expect( function(){ + it( "imageData is provided with no imageType", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var imageData = ImageRead( getTestFilePath( "test.png" ).Replace( "\", "/", "ALL" ) );//boxlang won't accept "\" https://ortussolutions.atlassian.net/browse/BL-878 s.addImage( workbook=wb, imageData=imageData, anchor="1,1,2,2" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArgumentCombination" ); - }); - }); + }) + }) - it( "imageData is not a coldfusion image object", function(){ - workbooks.Each( function( wb ) { - expect( function(){ + it( "imageData is not a coldfusion image object", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var imageData = {}; s.addImage( workbook=wb, imageData=imageData, imageType="png", anchor="1,1,2,2" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidImage" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/addPageBreaks.cfm b/test/specs/addPageBreaks.cfm index 11556de..455ea7b 100644 --- a/test/specs/addPageBreaks.cfm +++ b/test/specs/addPageBreaks.cfm @@ -1,51 +1,51 @@ -describe( "addPageBreaks", function(){ +describe( "addPageBreaks", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var columnData = [ "a", "b", "c" ]; var rowData = [ columnData, columnData, columnData ]; var data = QueryNew( "c1,c2,c3", "VarChar,VarChar,VarChar", rowData ); var xls = s.workbookFromQuery( data, false ); var xlsx = s.workbookFromQuery( data=data, addHeaderRow=false, xmlformat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "adds page breaks at the row and column numbers passed in as lists", function(){ - workbooks.Each( function( wb ) { + it( "adds page breaks at the row and column numbers passed in as lists", ()=>{ + workbooks.Each( ( wb )=>{ s.addPageBreaks( wb, "2,3", "1,2" ); expect( s.getSheetHelper().getActiveSheet( wb ).getRowBreaks() ).toBe( [ 1, 2 ] ); expect( s.getSheetHelper().getActiveSheet( wb ).getColumnBreaks() ).toBe( [ 0, 1 ] ); - }); - }); + }) + }) - it( "Doesn't error when passing valid arguments with extra trailing/leading space", function(){ - workbooks.Each( function( wb ) { + it( "Doesn't error when passing valid arguments with extra trailing/leading space", ()=>{ + workbooks.Each( ( wb )=>{ s.addPageBreaks( wb, " 2,3 ", "1,2 " ); - }); - }); + }) + }) - it( "Doesn't error when passing single numbers instead of lists", function(){ - workbooks.Each( function( wb ) { + it( "Doesn't error when passing single numbers instead of lists", ()=>{ + workbooks.Each( ( wb )=>{ s.addPageBreaks( wb, 1, 2 ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ) { + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).addPageBreaks( 1, 2 ); - }); - }); + }) + }) - it( "Throws a helpful exception if both arguments are missing or present but empty", function(){ - workbooks.Each( function( wb ) { - expect( function(){ + it( "Throws a helpful exception if both arguments are missing or present but empty", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addPageBreaks( wb ); }).toThrow( type="cfsimplicity.spreadsheet.missingRowOrColumnBreaksArgument" ); - expect( function(){ + expect( ()=>{ s.addPageBreaks( wb, "" ); }).toThrow( type="cfsimplicity.spreadsheet.missingRowOrColumnBreaksArgument" ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/addRow.cfm b/test/specs/addRow.cfm index 0fb3698..570c60b 100644 --- a/test/specs/addRow.cfm +++ b/test/specs/addRow.cfm @@ -1,128 +1,128 @@ -describe( "addRow", function(){ +describe( "addRow", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.data = "a,b"; variables.dataAsArray = [ "a", "b" ]; variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Appends a row with the minimum arguments", function(){ - workbooks.Each( function( wb ){ + it( "Appends a row with the minimum arguments", ()=>{ + workbooks.Each( ( wb )=>{ s.addRow( wb, data ) .addRow( wb, "c,d" );// should be inserted at row 2 var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Appends a row including commas with a custom delimiter", function(){ - workbooks.Each( function( wb ){ + it( "Appends a row including commas with a custom delimiter", ()=>{ + workbooks.Each( ( wb )=>{ s.addRow( workbook=wb, data="a,b|c,d", delimiter="|" ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a,b", "c,d" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Appends a row as an array with the minimum arguments", function(){ - workbooks.Each( function( wb ){ + it( "Appends a row as an array with the minimum arguments", ()=>{ + workbooks.Each( ( wb )=>{ s.addRow( wb, dataAsArray ) .addRow( wb, [ "c", "d" ] );// should be inserted at row 2 var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Inserts a row at a specifed position", function(){ + it( "Inserts a row at a specifed position", ()=>{ var expected = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "a", "b", "" ], [ "c", "d", "" ], [ "", "e", "f" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, data ) .addRow( wb, "e,f", 2, 2 ) .addRow( wb, "c,d", 2, 1 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); + }) //array data var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, dataAsArray ) .addRow( wb, [ "e", "f" ], 2, 2 ) .addRow( wb, [ "c", "d" ], 2, 1 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Replaces a row if insert is false", function(){ + it( "Replaces a row if insert is false", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, data ) .addRow( workbook=wb, data=data, row=1, insert=false ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); + }) var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ //array data s.addRow( wb, dataAsArray ) .addRow( workbook=wb, data=dataAsArray, row=1, insert=false ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Handles embedded commas in comma delimited list data", function(){ - workbooks.Each( function( wb ){ + it( "Handles embedded commas in comma delimited list data", ()=>{ + workbooks.Each( ( wb )=>{ s.addRow( workbook=wb, data="'a,b', 'c,d'" ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a,b", "c,d" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Adds numeric values correctly", function(){ - workbooks.Each( function( wb ){ + it( "Adds numeric values correctly", ()=>{ + workbooks.Each( ( wb )=>{ var data = "1,1.1"; s.addRow( wb, data ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( 1 ); expect( s.getCellValue( wb, 1, 2 ) ).toBe( 1.1 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); - }); + }) //array data var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var dataAsArray = [ 1, 1.1 ]; s.addRow( wb, dataAsArray ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( 1 ); expect( s.getCellValue( wb, 1, 2 ) ).toBe( 1.1 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Adds boolean values as strings", function(){ - workbooks.Each( function( wb ){ + it( "Adds boolean values as strings", ()=>{ + workbooks.Each( ( wb )=>{ var data = true; s.addRow( wb, data ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( true ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); + }) //array data var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var dataAsArray = [ true ]; s.addRow( wb, dataAsArray ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( true ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Adds date/time values correctly", function(){ - workbooks.Each( function( wb ){ + it( "Adds date/time values correctly", ()=>{ + workbooks.Each( ( wb )=>{ var dateValue = CreateDate( 2015, 04, 12 ); var timeValue = _CreateTime( 1, 0, 0 ); var dateTimeValue = CreateDateTime( 2015, 04, 12, 1, 0, 0 ); @@ -134,10 +134,10 @@ describe( "addRow", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 3 ) ).toBe( "numeric" ); - }); + }) //array data var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var dateValue = CreateDate( 2015, 04, 12 ); var timeValue = _CreateTime( 1, 0, 0 ); var dateTimeValue = CreateDateTime( 2015, 04, 12, 1, 0, 0 ); @@ -149,87 +149,87 @@ describe( "addRow", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 3 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Adds zeros as zeros, not booleans", function(){ - workbooks.Each( function( wb ){ + it( "Adds zeros as zeros, not booleans", ()=>{ + workbooks.Each( ( wb )=>{ s.addRow( wb, 0 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); - }); + }) //array data var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, [ 0 ] ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Adds strings with leading zeros as strings not numbers", function(){ - workbooks.Each( function( wb ){ + it( "Adds strings with leading zeros as strings not numbers", ()=>{ + workbooks.Each( ( wb )=>{ s.addRow( wb, "01" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); + }) //array data var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, [ "01" ] ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) it( title="Can insert more than 4009 rows containing dates without triggering an exception", - body=function(){ - workbooks.Each( function( wb ){ + body=()=>{ + workbooks.Each( ( wb )=>{ for( var i=1; i LTE 4010; i++ ){ variables.s.addRow( wb, "2016-07-14" ); } - }); + }) }, skip=s.getIsACF() ); - it( "Doesn't error if the workbook is SXSSF and autoSizeColumns is true", function(){ + it( "Doesn't error if the workbook is SXSSF and autoSizeColumns is true", ()=>{ var wb = s.newStreamingXlsx(); s.addRow( workbook=local.wb, data=data, autoSizeColumns=true ); - }); + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .addRow( data ) .addRow( "c,d" );// should be inserted at row 2 var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - describe( "addRow() data type overriding",function(){ + describe( "addRow() data type overriding",()=>{ - it( "throws an error if invalid types are specified in the datatype struct", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "throws an error if invalid types are specified in the datatype struct", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var data = [ "a", "b" ]; var datatypes = { numeric: [ 1 ], varchar: [ 2 ] }; s.addRow( workbook=wb, data=data, datatypes=datatypes ); }).toThrow( type="cfsimplicity.spreadsheet.invalidDatatype" ); - }); - }); + }) + }) - it( "throws an error if columns to override are not specified as arrays in the datatype struct", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "throws an error if columns to override are not specified as arrays in the datatype struct", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var data = [ "a", "b" ]; var datatypes = { numeric: "1", string: "2" }; s.addRow( workbook=wb, data=data, datatypes=datatypes ); }).toThrow( type="cfsimplicity.spreadsheet.invalidDatatype" ); - }); - }); + }) + }) - it( "Allows column data types to be overridden", function(){ - workbooks.Each( function( wb ){ + it( "Allows column data types to be overridden", ()=>{ + workbooks.Each( ( wb )=>{ var datatypes = { numeric: [ 1 ], string: [ 2 ] };// can't test dates: date strings are always converted correctly! var data = "01234,1234567890123456"; s.addRow( wb, data ); @@ -246,11 +246,11 @@ describe( "addRow", function(){ expect( s.getCellValue( wb, 3, 1 ) ).toBe( "1234" ); expect( s.getCellType( wb, 3, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 3, 2 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Values fall back to the autodetected type if they don't match the overridden type", function(){ - workbooks.Each( function( wb ){ + it( "Values fall back to the autodetected type if they don't match the overridden type", ()=>{ + workbooks.Each( ( wb )=>{ var datatypes = { numeric: [ 1, 2 ] }; var data = "01234,alpha"; s.addRow( workbook=wb, data=data, datatypes=datatypes ); @@ -264,38 +264,38 @@ describe( "addRow", function(){ expect( s.getCellType( wb, 2, 1 ) ).toBe( "numeric" ); expect( s.getCellValue( wb, 2, 2 ) ).toBe( "alpha" ); expect( s.getCellType( wb, 2, 2 ) ).toBe( "string" ); - }); - }); + }) + }) - }); + }) - describe( "addRow throws an exception if", function(){ + describe( "addRow throws an exception if", ()=>{ - it( "row is zero or less", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "row is zero or less", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRow( workbook=wb, data=data, row=0 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidRowArgument" ); - }); - }); + }) + }) - it( "column is zero or less", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "column is zero or less", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRow( workbook=wb, data=data, column=0 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidColumnArgument" ); - }); - }); + }) + }) - it( "insert is false and no row specified", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "insert is false and no row specified", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRow( workbook=wb, data=data, insert=false ); }).toThrow( type="cfsimplicity.spreadsheet.missingRowArgument" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/addRows.cfm b/test/specs/addRows.cfm index 159461a..65f304d 100644 --- a/test/specs/addRows.cfm +++ b/test/specs/addRows.cfm @@ -1,94 +1,94 @@ -describe( "addRows", function(){ +describe( "addRows", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); variables.dataAsArray = [ [ "a", "b" ], [ "c", "d" ] ]; variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Appends multiple rows from a query with the minimum arguments", function(){ + it( "Appends multiple rows from a query with the minimum arguments", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "x", "y" ], [ "a", "b" ], [ "c", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "x,y" ) .addRows( wb, data ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Is chainable", function(){ + it( "Is chainable", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "x", "y" ], [ "a", "b" ], [ "c", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .addRow( "x,y" ) .addRows( data ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Can accept data as an array instead of a query", function(){ + it( "Can accept data as an array instead of a query", ()=>{ var data = [ [ "x", "y" ], [ "a", "b" ], [ "c", "d" ] ]; var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "x", "y" ], [ "a", "b" ], [ "c", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Does nothing if array data is empty", function(){ + it( "Does nothing if array data is empty", ()=>{ var emptyData = []; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, emptyData ); var expected = QueryNew( "" ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Inserts multiple rows at a specifed position", function(){ + it( "Inserts multiple rows at a specifed position", ()=>{ var expected = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "", "a", "b" ], [ "", "c", "d" ], [ "e", "f", "" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "e,f" ) .addRows( wb, data, 1, 2 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); + }) //array data var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "e,f" ) .addRows( wb, dataAsArray, 1, 2 ); actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Replaces rows if insert is false", function(){ + it( "Replaces rows if insert is false", ()=>{ var expected = data; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "e,f" ) .addRow( wb, "g,h" ) .addRows( workbook=wb, data=data, row=1, insert=false ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); + }) var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "e,f" ) .addRow( wb, "g,h" ) .addRows( workbook=wb, data=dataAsArray, row=1, insert=false ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Adds numeric values correctly", function(){ + it( "Adds numeric values correctly", ()=>{ var data = QueryNew( "column1,column2,column3", "Integer,BigInt,Double", [ [ 1, 1, 1.1 ] ] ); var expected = data; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); @@ -98,10 +98,10 @@ describe( "addRows", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 3 ) ).toBe( "numeric" ); - }); + }) var dataAsArray = [ [ 1, 1, 1.1 ] ]; var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, dataAsArray ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); @@ -111,37 +111,37 @@ describe( "addRows", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 3 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Adds boolean values correctly", function(){ + it( "Adds boolean values correctly", ()=>{ var data = QueryNew( "column1", "Bit", [ [ true ] ] ); var expected = data; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); expect( IsBoolean( s.getCellValue( wb, 1, 1 ) ) ).toBeTrue(); expect( s.getCellType( wb, 1, 1 ) ).toBe( "boolean" ); - }); + }) var dataAsArray = [ [ true ] ]; var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, dataAsArray ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); expect( IsBoolean( s.getCellValue( wb, 1, 1 ) ) ).toBeTrue(); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" );// don't set the cell type as boolean from an array - }); - }); + }) + }) - it( "Adds date/time values correctly", function(){ + it( "Adds date/time values correctly", ()=>{ var dateValue = CreateDate( 2015, 04, 12 ); var timeValue = _CreateTime( 1, 0, 0 ); var dateTimeValue = createDateTime( 2015, 04, 12, 1, 0, 0 ); var data = QueryNew( "column1,column2,column3", "Date,Time,Timestamp", [ [ dateValue, timeValue, dateTimeValue ] ] ); var expected = QueryNew( "column1,column2,column3", "Date,Time,Timestamp", [ [ dateValue, "01:00:00", dateTimeValue ] ] );; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); @@ -151,14 +151,14 @@ describe( "addRows", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 3 ) ).toBe( "numeric" ); - }); + }) //array data var dateValue = CreateDate( 2015, 04, 12 ); var timeValue = _CreateTime( 1, 0, 0 ); var dateTimeValue = CreateDateTime( 2015, 04, 12, 1, 0, 0 ); var dataAsArray = [ [ dateValue, timeValue, dateTimeValue ] ]; var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, dataAsArray ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); @@ -168,10 +168,10 @@ describe( "addRows", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 3 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Formats time and timestamp values correctly when custom mask includes fractions of a second", function(){ + it( "Formats time and timestamp values correctly when custom mask includes fractions of a second", ()=>{ var dateFormats = { TIME: "hh:mm:ss.000" ,TIMESTAMP: "yyyy-mm-dd hh:mm:ss.000" @@ -188,45 +188,45 @@ describe( "addRows", function(){ var data = QueryNew( "column1,column2", "Time,Timestamp", [ [ timeValue, dateTimeValue ] ] ); var expectedTimeValue = data.column1[ 1 ].TimeFormat( "hh:nn:ss:l" ); var expectedDateTimeValue = data.column2[ 1 ].DateTimeFormat( "yyyy-mm-dd hh:nn:ss:l" ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var actual = s.getSheetHelper().sheetToQuery( wb ); var actualTimeValue = actual.column1[ 1 ]; var actualDateTimeValue = actual.column2[ 1 ]; - }); + }) var dataAsArray = [ [ timeValue, dateTimeValue ] ]; var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, dataAsArray ); expectedTimeValue = data.column1[ 1 ].TimeFormat( "hh:nn:ss:l" ); expectedDateTimeValue = data.column2[ 1 ].DateTimeFormat( "yyyy-mm-dd hh:nn:ss:l" ); actual = s.getSheetHelper().sheetToQuery( wb ); actualTimeValue = actual.column1[ 1 ]; actualDateTimeValue = actual.column2[ 1 ]; - }); - }); + }) + }) - it( "Adds zeros as zeros, not booleans", function(){ + it( "Adds zeros as zeros, not booleans", ()=>{ var data = QueryNew( "column1", "Integer", [ [ 0 ] ] ); var expected = data; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); + }) var dataAsArray = [ [ 0 ] ]; var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ //array data s.addRows( wb, dataAsArray ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Handles empty values correctly", function(){ + it( "Handles empty values correctly", ()=>{ var data = QueryNew( "column1,column2,column3,column4,column5", "Date,Time,Timestamp,Bit,Integer",[ [ "", "", "", "", "" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "blank" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "blank" ); @@ -234,116 +234,116 @@ describe( "addRows", function(){ expect( s.getCellType( wb, 1, 4 ) ).toBe( "blank" ); expect( s.getCellType( wb, 1, 5 ) ).toBe( "blank" ); //doesn't apply to array data which has no column types - }); - }); + }) + }) - it( "Can ignore query column types, so that each cell's type is auto-detected from its value", function(){ + it( "Can ignore query column types, so that each cell's type is auto-detected from its value", ()=>{ var dateValue = CreateDate( 2015, 04, 12 ); var data = QueryNew( "column1", "VarChar", [ [ 0 ], [ 1 ], [ 1.1 ], [ dateValue ], [ "hello" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, ignoreQueryColumnDataTypes=true ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 2, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 3, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 4, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 5, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Adds strings with leading zeros as strings not numbers", function(){ + it( "Adds strings with leading zeros as strings not numbers", ()=>{ var data = QueryNew( "column1", "VarChar", [ [ "01" ] ] ); var expected = data; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); + }) var dataAsArray = [ [ "01" ] ]; var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, dataAsArray ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Can include the query column names", function(){ + it( "Can include the query column names", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "column1", "column2" ], [ "a","b" ], [ "c", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, includeQueryColumnNames=true ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Includes query columns in the same case and order as the original query", function(){ + it( "Includes query columns in the same case and order as the original query", ()=>{ var data = QueryNew( "Header2,Header1", "VarChar,VarChar", [ [ "b","a" ], [ "d","c" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, includeQueryColumnNames=true ); expect( s.getCellValue( wb, 1, 1 ) ).toBeWithCase( "Header2" ); - }); - }); + }) + }) - it( "Can include the query column names starting at a specific row", function(){ + it( "Can include the query column names starting at a specific row", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "x", "y" ], [ "column1", "column2" ], [ "a", "b" ], [ "c", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "x,y" ) .addRows( workbook=wb, data=data, row=2, includeQueryColumnNames=true ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Can include the query column names starting at a specific column", function(){ + it( "Can include the query column names starting at a specific column", ()=>{ var expected = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "", "column1", "column2" ], [ "", "a", "b" ], [ "", "c", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, column=2, includeQueryColumnNames=true ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Can include the query column names starting at a specific row and column", function(){ + it( "Can include the query column names starting at a specific row and column", ()=>{ var expected = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "x", "y", "" ],[ "", "column1","column2" ], [ "", "a", "b" ], [ "", "c","d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "x,y" ) .addRows( workbook=wb, data=data, row=2, column=2, includeQueryColumnNames=true ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Doesn't error if the workbook is SXSSF and autoSizeColumns is true", function(){ + it( "Doesn't error if the workbook is SXSSF and autoSizeColumns is true", ()=>{ var wb = s.newStreamingXlsx(); s.addRows( workbook=local.wb, data=data, autoSizeColumns=true ); - }); + }) - describe( "addRows() data type overriding", function(){ + describe( "addRows() data type overriding", ()=>{ - it( "throws an error if invalid types are specified in the datatypes struct", function(){ + it( "throws an error if invalid types are specified in the datatypes struct", ()=>{ var data = [ [ "a", "b" ] ]; var datatypes = { numeric: [ 1 ], varchar: [ 2 ] }; - workbooks.Each( function( wb ){ - expect( function(){ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); }).toThrow( type="cfsimplicity.spreadsheet.invalidDatatype" ); - }); - }); + }) + }) - it( "throws an error if columns to override are not specified as arrays in the datatypes struct", function(){ + it( "throws an error if columns to override are not specified as arrays in the datatypes struct", ()=>{ var data = [ [ "a", "b" ] ]; var datatypes = { numeric: "1", string: "2" }; - workbooks.Each( function( wb ){ - expect( function(){ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); }).toThrow( type="cfsimplicity.spreadsheet.invalidDatatype" ); - }); - }); + }) + }) - it( "Allows column data types in data passed as an array to be overridden by column number", function(){ + it( "Allows column data types in data passed as an array to be overridden by column number", ()=>{ var data = [ [ "01234", 1234567890123456 ] ]; var datatypes = { numeric: [ 1 ], string: [ 2 ] };// can't test dates: date strings are always converted correctly! - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( "01234" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); @@ -352,11 +352,11 @@ describe( "addRows", function(){ expect( s.getCellValue( wb, 2, 1 ) ).toBe( "1234" ); expect( s.getCellType( wb, 2, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 2, 2 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Allows column data types in data passed as a query to be overridden by column name or number", function(){ - workbooks.Each( function( wb ){ + it( "Allows column data types in data passed as a query to be overridden by column name or number", ()=>{ + workbooks.Each( ( wb )=>{ var data = QueryNew( "Number,Date,String,Time,Boolean", "VarChar,VarChar,BigInt,VarChar,VarChar", [ [ "01234", "2020-08-24", 1234567890123456, "2020-08-24 09:15:00", "yes" ] ] ); s.addRows( wb, data ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( "01234" ); @@ -383,26 +383,26 @@ describe( "addRows", function(){ expect( s.getCellValue( wb, 3, 2 ) ).toBe( "1234" ); expect( s.getCellType( wb, 3, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 3, 2 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "check multiple datatypes of the same type", function(){ + it( "check multiple datatypes of the same type", ()=>{ var testUri = "https://w3c.org"; var data = QueryNew( "urls,urls2", "VarChar,VarChar", [ [ testUri, testUri ] ] ); var datatypes = { url: [ "urls", "urls2" ] }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( testUri ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( testUri ); expect( s.getCellHyperlink( wb, 1, 2 ) ).toBe( testUri ); expect( s.getCellValue( wb, 1, 2 ) ).toBe( testUri ); - }); - }); + }) + }) - it( "Values in array data fall back to the autodetected type if they don't match the overridden type", function(){ + it( "Values in array data fall back to the autodetected type if they don't match the overridden type", ()=>{ var data = [ [ "01234", "alpha", "alpha", "alpha", "alpha" ] ]; var datatypes = { numeric: [ 1, 2 ], date: [ 3 ], time: [ 4 ], boolean: [ 5 ] }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( 1234 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); @@ -414,13 +414,13 @@ describe( "addRows", function(){ expect( s.getCellType( wb, 1, 4 ) ).toBe( "string" ); expect( s.getCellValue( wb, 1, 5 ) ).toBe( "alpha" ); expect( s.getCellType( wb, 1, 5 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Values in query data fall back to the query column type if they don't match the overridden type", function(){ + it( "Values in query data fall back to the query column type if they don't match the overridden type", ()=>{ var data = QueryNew( "Number,String,Date,Time,Boolean", "VarChar,VarChar,VarChar,VarChar,VarChar", [ [ "01234", "alpha", "alpha", "alpha" , "alpha"] ] ); var datatypes = { numeric: [ 1, 2 ], date: [ 3 ], time: [ 4 ], boolean: [ 5 ] }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( 1234 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); @@ -432,23 +432,23 @@ describe( "addRows", function(){ expect( s.getCellType( wb, 1, 4 ) ).toBe( "string" ); expect( s.getCellValue( wb, 1, 5 ) ).toBe( "alpha" ); expect( s.getCellType( wb, 1, 5 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Query data values with NO type override, default to query column types", function(){ + it( "Query data values with NO type override, default to query column types", ()=>{ var data = QueryNew( "Number,String", "VarChar,VarChar", [ [ 1234, "01234" ] ] ); var datatypes = { numeric: [ 2 ] }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Values in query data fall back to the autodetected type if they don't match the overridden type and ignoreQueryColumnDataTypes is true", function(){ + it( "Values in query data fall back to the autodetected type if they don't match the overridden type and ignoreQueryColumnDataTypes is true", ()=>{ var data = QueryNew( "Number,String,Date,Time,Boolean", "VarChar,VarChar,VarChar,VarChar,VarChar", [ [ "01234", "alpha", "alpha", "alpha" , "alpha"] ] ); var datatypes = { numeric: [ 1, 2 ], date: [ 3 ], time: [ 4 ], boolean: [ 5 ] }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, ignoreQueryColumnDataTypes=true, datatypes=datatypes ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( 1234 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); @@ -460,28 +460,28 @@ describe( "addRows", function(){ expect( s.getCellType( wb, 1, 4 ) ).toBe( "string" ); expect( s.getCellValue( wb, 1, 5 ) ).toBe( "alpha" ); expect( s.getCellType( wb, 1, 5 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Query data values in columns with an override type of 'auto' will have their type auto-detected, regardless of the query column type", function(){ + it( "Query data values in columns with an override type of 'auto' will have their type auto-detected, regardless of the query column type", ()=>{ var data = QueryNew( "One,Two", "VarChar,VarChar", [ [ "2020-08-24", "2020-08-24" ], [ "3.1", "3.1" ] ] ); var datatypes = { auto: [ 1 ] }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 1, 2 ) ).toBe( "string" ); expect( s.getCellType( wb, 2, 1 ) ).toBe( "numeric" ); expect( s.getCellType( wb, 2, 2 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Supports url, email and file types, converting them to hyperlinks", function(){ + it( "Supports url, email and file types, converting them to hyperlinks", ()=>{ var testUri = "https://w3c.org"; var testEmail = "test@test.com"; var testFilePath = "test.xlsx"; var data = QueryNew( "urls,emails,files", "VarChar,VarChar,VarChar", [ [ testUri, testEmail, testFilePath ] ] ); var datatypes = { url: [ "urls" ], email: [ "emails" ], file: [ "files" ] }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( testUri ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( testUri ); @@ -491,31 +491,31 @@ describe( "addRows", function(){ expect( s.getCellHyperlink( wb, 1, 3 ) ).toBe( testFilePath ); expect( s.getCellValue( wb, 1, 3 ) ).toBe( testFilePath ); expect( s.getCellHelper().getCellAt( wb, 1, 3 ).getHyperLink().getType().name() ).toBe( "FILE" ); - }); - }); + }) + }) - it( "Adds invalid url and email values as strings", function(){ + it( "Adds invalid url and email values as strings", ()=>{ var invalidValue = "not a link"; var data = QueryNew( "Urls,emails", "VarChar,VarChar", [ [ invalidValue, invalidValue ] ] ); var datatypes = { url: [ "Urls" ], email: [ "Emails" ] }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( workbook=wb, data=data, datatypes=datatypes ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBeEmpty(); expect( s.getCellValue( wb, 1, 1 ) ).toBe( invalidValue ); expect( s.getCellHyperlink( wb, 1, 2 ) ).toBeEmpty(); expect( s.getCellValue( wb, 1, 2 ) ).toBe( invalidValue ); - }); - }); + }) + }) - }); + }) - describe( "addRows throws an exception if", function(){ + describe( "addRows throws an exception if", ()=>{ it( title="adding more than 65536 rows to a binary spreadsheet", - body=function(){ + body=()=>{ var xls = workbooks[ 1 ]; - expect( function(){ + expect( ()=>{ var rows = []; for( var i=1; i <= 65537; i++ ){ rows.append( [ i ] ); @@ -527,47 +527,47 @@ describe( "addRows", function(){ skip=!s.getIsLucee() ); - it( "row is zero or less", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "row is zero or less", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRows( workbook=wb, data=data, row=0 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidRowArgument" ); - }); - }); + }) + }) - it( "column is zero or less", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "column is zero or less", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRows( workbook=wb, data=data, column=0 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidColumnArgument" ); - }); - }); + }) + }) - it( "insert is false and no row specified", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "insert is false and no row specified", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRows( workbook=wb, data=data, insert=false ); }).toThrow( type="cfsimplicity.spreadsheet.missingRowArgument" ); - }); - }); + }) + }) - it( "the data is neither a query nor an array", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the data is neither a query nor an array", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRows( wb, "string,list" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidDataArgument" ); - }); - }); + }) + }) - it( "the data is an array which does not contain an array for each row", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the data is an array which does not contain an array for each row", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.addRows( wb, [ { col1: "a" }, { col2: "b" } ] );// array of structs }).toThrow( type="cfsimplicity.spreadsheet.invalidDataArgument" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/addSplitPane.cfm b/test/specs/addSplitPane.cfm index 35ab15e..b42d292 100644 --- a/test/specs/addSplitPane.cfm +++ b/test/specs/addSplitPane.cfm @@ -1,15 +1,15 @@ -describe( "addSplitPane", function(){ +describe( "addSplitPane", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var data = QueryNew( "Header1,Header2,Header3", "VarChar,VarChar,Varchar", [ [ "a", "b", "c" ], [ "d", "e", "f" ], [ "g", "h", "i" ] ] ); var xls = s.workbookFromQuery( data ); var xlsx = s.workbookFromQuery( data=data, xmlformat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "Splits a worksheet into 4 separate panes", function(){ - workbooks.Each( function( wb ){ + it( "Splits a worksheet into 4 separate panes", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getPaneInformation() ).toBeNull(); s.addSplitPane( wb, 1000, 2000, 3, 2 ); @@ -18,21 +18,21 @@ describe( "addSplitPane", function(){ expect( sheet.getPaneInformation().getHorizontalSplitPosition() ).toBe( 2000 ); expect( sheet.getPaneInformation().getVerticalSplitLeftColumn() ).toBe( 3 ); expect( sheet.getPaneInformation().getHorizontalSplitTopRow() ).toBe( 2 ); - }); - }); + }) + }) /* TODO: this seems to fail with XSSF sheet.getPaneInformation().getActivePane() returns the expected byte value minus one, and a NPE if the value is 0 */ - /* it( "The active pane defaults to UPPER_LEFT", function(){ - workbooks.Each( function( wb ){ + /* it( "The active pane defaults to UPPER_LEFT", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getPaneInformation() ).toBeNull(); s.addSplitPane( wb, 1000, 2000, 1, 1 ); expect( sheet.getPaneInformation().getActivePane() ).toBe( sheet[ "PANE_UPPER_LEFT" ] ); - }); - }); */ + }) + }) */ - it( "Is chainable", function() { - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getPaneInformation() ).toBeNull(); s.newChainable( wb ).addSplitPane( 1000, 2000, 3, 2 ); @@ -41,8 +41,8 @@ describe( "addSplitPane", function(){ expect( sheet.getPaneInformation().getHorizontalSplitPosition() ).toBe( 2000 ); expect( sheet.getPaneInformation().getVerticalSplitLeftColumn() ).toBe( 3 ); expect( sheet.getPaneInformation().getHorizontalSplitTopRow() ).toBe( 2 ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/autoSizeColumn.cfm b/test/specs/autoSizeColumn.cfm index 941dac6..5cd45c8 100644 --- a/test/specs/autoSizeColumn.cfm +++ b/test/specs/autoSizeColumn.cfm @@ -1,39 +1,39 @@ -describe( "autoSizeColumn", function(){ +describe( "autoSizeColumn", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var data = QueryNew( "First,Last", "VarChar,VarChar", [ [ "a", "abracadabraabracadabra" ] ] ); var xls = s.workbookFromQuery( data ); var xlsx = s.workbookFromQuery( data=data, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "Doesn't error when passing valid arguments", function(){ - workbooks.Each( function( wb ){ + it( "Doesn't error when passing valid arguments", ()=>{ + workbooks.Each( ( wb )=>{ s.autoSizeColumn( wb, 2 ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).autoSizeColumn( 2 ); - }); - }); + }) + }) - it( "Doesn't error if the workbook is SXSSF", function(){ + it( "Doesn't error if the workbook is SXSSF", ()=>{ var data = QueryNew( "First,Last", "VarChar,VarChar", [ [ "a", "abracadabraabracadabra" ] ] ); var workbook = s.newStreamingXlsx(); s.addRows( local.workbook, data ) .autoSizeColumn( local.workbook, 2 ); - }); + }) - it( "Throws a helpful exception if column argument is invalid", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "Throws a helpful exception if column argument is invalid", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.autoSizeColumn( wb, -1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidColumnArgument" ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/binaryFromQuery.cfm b/test/specs/binaryFromQuery.cfm index 70e666e..161a12b 100644 --- a/test/specs/binaryFromQuery.cfm +++ b/test/specs/binaryFromQuery.cfm @@ -1,11 +1,11 @@ -describe( "binaryFromQuery", function(){ +describe( "binaryFromQuery", ()=>{ - it( "Returns a binary object", function() { + it( "Returns a binary object", ()=>{ var data = QueryNew( "Header1,Header2", "VarChar,VarChar", [ [ "a","b" ], [ "c","d" ] ] ); expect( IsBinary( s.binaryFromQuery( data ) ) ).toBeTrue(); expect( IsBinary( s.binaryFromQuery( data=data, xmlFormat=true ) ) ).toBeTrue(); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/cellComment.cfm b/test/specs/cellComment.cfm index a37ce99..c188dd9 100644 --- a/test/specs/cellComment.cfm +++ b/test/specs/cellComment.cfm @@ -1,28 +1,28 @@ -describe( "cellComment", function(){ +describe( "cellComment", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Can set and get a comment from the specified cell", function() { + it( "Can set and get a comment from the specified cell", ()=>{ var theComment = { author: "cfsimplicity" ,comment: "This is the comment in row 1 column 1" }; var expected = Duplicate( theComment ).Append( { column: 1, row: 1 } ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "1" ) .setCellComment( wb, theComment, 1, 1 ); var actual = s.getCellComment( wb, 1, 1 ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "getCellComment, getCellComments and setCellComment are chainable", function() { + it( "getCellComment, getCellComments and setCellComment are chainable", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var dataAsArray = [ [ "a", "b" ], [ "c", "d" ] ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var comments = []; comments.Append( { author: "cfsimplicity", comment: "This is the comment in row 1 column 1", column: 1, row: 1 } ); @@ -33,13 +33,13 @@ describe( "cellComment", function(){ expect( wbChainable.getCellComment() ).toBe( comments ); expect( wbChainable.getCellComments() ).toBe( comments ); expect( wbChainable.getCellComment( 1, 1 ) ).toBe( comments[ 1 ] ); - }); - }); + }) + }) - it( "Can get all comments in the current sheet", function() { + it( "Can get all comments in the current sheet", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var dataAsArray = [ [ "a", "b" ], [ "c", "d" ] ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var comments = []; comments.Append( { author: "cfsimplicity", comment: "This is the comment in row 1 column 1", column: 1, row: 1 } ); @@ -52,11 +52,11 @@ describe( "cellComment", function(){ //alias getCellComments actual = s.getCellComments( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "can set comment styles without erroring", function(){ - workbooks.Each( function( wb ){ + it( "can set comment styles without erroring", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "1" ); var theComment = { anchor: "1,2,3,4" @@ -78,21 +78,21 @@ describe( "cellComment", function(){ ,verticalalignment: "center" }; s.setCellComment( wb, theComment, 1, 1 ); - }); - }); + }) + }) - describe( "cellComment throws an exception if", function(){ + describe( "cellComment throws an exception if", ()=>{ - it( "column specified but not row, or vice versa", function() { - workbooks.Each( function( wb ){ - expect( function(){ + it( "column specified but not row, or vice versa", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.getCellComment( workbook=wb, row=1 ); s.getCellComment( workbook=wb, column=1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArgumentCombination" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/cellFormula.cfm b/test/specs/cellFormula.cfm index 34cc62b..c7f519c 100644 --- a/test/specs/cellFormula.cfm +++ b/test/specs/cellFormula.cfm @@ -1,34 +1,34 @@ -describe( "cellFormula", function(){ +describe( "cellFormula", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "1,1" ); - }); + }) variables.theFormula = "SUM(A1:A2)"; - }); + }) - it( "Sets and gets the specified formula for the specified cell", function(){ - workbooks.Each( function( wb ){ + it( "Sets and gets the specified formula for the specified cell", ()=>{ + workbooks.Each( ( wb )=>{ s.setCellFormula( wb, theFormula, 3, 1 ); expect( s.getCellFormula( wb, 3, 1 ) ).toBe( theFormula ); expect( s.getCellValue( wb, 3, 1 ) ).toBe( 2 ); - }); - }); + }) + }) - it( "setCellFormula and getCellFormula are chainable", function(){ - workbooks.Each( function( wb ){ + it( "setCellFormula and getCellFormula are chainable", ()=>{ + workbooks.Each( ( wb )=>{ var actual = s.newChainable( wb ) .setCellFormula( theFormula, 3, 1 ) .getCellFormula( 3, 1 ); expect( actual ).toBe( theFormula ); expect( s.getCellValue( wb, 3, 1 ) ).toBe( 2 ); - }); - }); + }) + }) - it( "Gets all formulas from the workbook", function(){ - workbooks.Each( function( wb ){ + it( "Gets all formulas from the workbook", ()=>{ + workbooks.Each( ( wb )=>{ s.setCellFormula( wb, theFormula, 3, 1 ); var expected = [{ formula: theFormula @@ -37,35 +37,35 @@ describe( "cellFormula", function(){ }]; var actual = s.getCellFormula( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Returns an empty string if the specified cell doesn't exist", function(){ - workbooks.Each( function( wb ){ + it( "Returns an empty string if the specified cell doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ var actual = s.getCellFormula( wb, 100, 100 ); expect( actual ).toBeEmpty(); - }); - }); + }) + }) - describe( "recalculation", function(){ + describe( "recalculation", ()=>{ - it( "can set a flag for all formulas to be recalculated in the workbook the next time the file is opened", function(){ + it( "can set a flag for all formulas to be recalculated in the workbook the next time the file is opened", ()=>{ // only xlsx seems to reflect the flag status var wb = s.newXlsx(); expect( wb.getForceFormulaRecalculation() ).toBeFalse(); s.setRecalculateFormulasOnNextOpen( wb ); expect( wb.getForceFormulaRecalculation() ).toBeTrue(); - }); + }) - it( "getForceFormulaRecalculation is chainable", function(){ + it( "getForceFormulaRecalculation is chainable", ()=>{ // only xlsx seems to reflect the flag status var wb = s.newXlsx(); expect( wb.getForceFormulaRecalculation() ).toBeFalse(); s.newChainable( wb ).setRecalculateFormulasOnNextOpen(); expect( wb.getForceFormulaRecalculation() ).toBeTrue(); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/cellHyperLink.cfm b/test/specs/cellHyperLink.cfm index 7dce7bd..392b2da 100644 --- a/test/specs/cellHyperLink.cfm +++ b/test/specs/cellHyperLink.cfm @@ -1,66 +1,66 @@ -describe( "cellHyperLinks", function(){ +describe( "cellHyperLinks", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; variables.uri = "https://w3c.org"; - }); + }) - it( "setCellHyperLink and getCellHyperLink are chainable", function(){ - workbooks.Each( function( wb ){ + it( "setCellHyperLink and getCellHyperLink are chainable", ()=>{ + workbooks.Each( ( wb )=>{ var actual = s.newChainable( wb ) .setCellHyperlink( uri, 1, 1 ) .getCellHyperlink( 1, 1 ); expect( actual ).toBe( uri ); - }); - }); + }) + }) - describe( "getCellHyperlink", function(){ + describe( "getCellHyperlink", ()=>{ - it( "returns the address/URL of a cell's hyperlink", function(){ - workbooks.Each( function( wb ){ + it( "returns the address/URL of a cell's hyperlink", ()=>{ + workbooks.Each( ( wb )=>{ s.setCellHyperlink( wb, uri, 1, 1 ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( uri ); - }); - }); + }) + }) - it( "returns an empty string if the cell contains no hyperlink", function(){ - workbooks.Each( function( wb ){ + it( "returns an empty string if the cell contains no hyperlink", ()=>{ + workbooks.Each( ( wb )=>{ expect( s.getCellHyperlink( wb, 1, 1 ) ).toBeEmpty(); - }); - }); + }) + }) - }); + }) - describe( "setHyperlink", function(){ + describe( "setHyperlink", ()=>{ - it( "adds a hyperlink to a cell", function(){ - workbooks.Each( function( wb ){ + it( "adds a hyperlink to a cell", ()=>{ + workbooks.Each( ( wb )=>{ s.setCellHyperlink( wb, uri, 1, 1 ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( uri ); - }); - }); + }) + }) - it( "Allows the cell value to be specified", function(){ - workbooks.Each( function( wb ){ + it( "Allows the cell value to be specified", ()=>{ + workbooks.Each( ( wb )=>{ var value = "W3C"; s.setCellHyperlink( workbook=wb, row=1, column=1, link=uri, cellValue=value ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( uri ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( value ); - }); - }); + }) + }) - it( "formats the hyperlink as blue/underlined by default", function(){ - workbooks.Each( function( wb ){ + it( "formats the hyperlink as blue/underlined by default", ()=>{ + workbooks.Each( ( wb )=>{ s.setCellHyperlink( wb, uri, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "single" ); expect( cellFormat.color ).toBe( "0,0,255" ); - }); - }); + }) + }) - it( "by default re-uses the default hyperlink cell style across multiple calls", function(){ - workbooks.Each( function( wb ){ + it( "by default re-uses the default hyperlink cell style across multiple calls", ()=>{ + workbooks.Each( ( wb )=>{ //baseline var expectedNumberOfStyles = s.isXmlFormat( wb )? 1: 21; expect( s.getWorkbookCellStylesTotal( wb ) ).toBe( expectedNumberOfStyles ); @@ -71,11 +71,11 @@ describe( "cellHyperLinks", function(){ // second call s.setCellHyperlink( wb, uri, 1, 2 ); expect( s.getWorkbookCellStylesTotal( wb ) ).toBe( expectedNumberOfStyles ); - }); - }); + }) + }) - it( "allows hyperlink formatting to be overridden", function(){ - workbooks.Each( function( wb ){ + it( "allows hyperlink formatting to be overridden", ()=>{ + workbooks.Each( ( wb )=>{ var format = { color: "RED", underline: false }; s.setCellHyperlink( workbook=wb, row=1, column=1, link=uri, format=format ); var cellFormat = s.getCellFormat( wb, 1, 1 ); @@ -85,72 +85,72 @@ describe( "cellHyperLinks", function(){ s.setCellHyperlink( workbook=wb, row=1, column=2, link=uri, format={} ); var cellFormat = s.getCellFormat( wb, 1, 2 ); expect( cellFormat.underline ).toBe( "none" ); - }); - }); + }) + }) - it( "allows hyperlink formatting to be overridden using a re-usable cellStyle", function(){ - workbooks.Each( function( wb ){ + it( "allows hyperlink formatting to be overridden using a re-usable cellStyle", ()=>{ + workbooks.Each( ( wb )=>{ var format = { color: "RED", underline: false }; var cellStyle = s.createCellStyle( wb, format ); s.setCellHyperlink( workbook=wb, row=1, column=1, link=uri, format=cellStyle ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "none" ); expect( cellFormat.color ).toBe( "255,0,0" ); - }); - }); + }) + }) - it( "Allows email links to be added", function(){ - workbooks.Each( function( wb ){ + it( "Allows email links to be added", ()=>{ + workbooks.Each( ( wb )=>{ var email = "mailto:test@example.com"; s.setCellHyperlink( workbook=wb, row=1, column=1, link=email, type="email" ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( email ); expect( s.getCellHelper().getCellAt( wb, 1, 1 ).getHyperLink().getType().name() ).toBe( "EMAIL" ); - }); - }); + }) + }) - it( "Allows file links to be added", function(){ - workbooks.Each( function( wb ){ + it( "Allows file links to be added", ()=>{ + workbooks.Each( ( wb )=>{ var file = "linked.xlsx"; s.setCellHyperlink( workbook=wb, row=1, column=1, link=file, type="file" ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( file ); expect( s.getCellHelper().getCellAt( wb, 1, 1 ).getHyperLink().getType().name() ).toBe( "FILE" ); - }); - }); + }) + }) - it( "Allows internal links to be added", function(){ - workbooks.Each( function( wb ){ + it( "Allows internal links to be added", ()=>{ + workbooks.Each( ( wb )=>{ var link = "'Target Sheet'!A1"; s.setCellHyperlink( workbook=wb, row=1, column=1, link=link, type="document" ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( link ); expect( s.getCellHelper().getCellAt( wb, 1, 1 ).getHyperLink().getType().name() ).toBe( "DOCUMENT" ); - }); - }); + }) + }) - it( "Allows xlsx sheet hyperlink tooltips to be set", function(){ + it( "Allows xlsx sheet hyperlink tooltips to be set", ()=>{ var wb = s.newXlsx(); var tooltip = "I'm a tooltip"; s.setCellHyperlink( workbook=wb, row=1, column=1, link=uri, tooltip=tooltip ); expect( s.getCellHyperlink( wb, 1, 1 ) ).toBe( uri ); expect( s.getCellHelper().getCellAt( wb, 1, 1 ).getHyperLink().getTooltip() ).toBe( tooltip ); - }); + }) - describe( "setCellHyperlink throws an exception if", function(){ + describe( "setCellHyperlink throws an exception if", ()=>{ - it( "an invalid type value is specified", function(){ - expect( function(){ + it( "an invalid type value is specified", ()=>{ + expect( ()=>{ s.setCellHyperlink( workbook=variables.workbooks[ 1 ], row=1, column=1, link="https://w3c.org", type="blah" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidTypeArgument" ); - }); + }) - it( "the workbook is XLS and a tooltip is specified", function(){ - expect( function(){ + it( "the workbook is XLS and a tooltip is specified", ()=>{ + expect( ()=>{ s.setCellHyperlink( workbook=variables.workbooks[ 1 ], row=1, column=1, link=uri, tooltip="whatever" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSpreadsheetType" ); - }); + }) - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/cellRangeValue.cfm b/test/specs/cellRangeValue.cfm index 0d37241..e1f43b4 100644 --- a/test/specs/cellRangeValue.cfm +++ b/test/specs/cellRangeValue.cfm @@ -1,30 +1,30 @@ -describe( "setCellRangeValue", function(){ +describe( "setCellRangeValue", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.value = "a"; variables.expected = querySim( "column1,column2 a|a a|a"); variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Sets the specified range of cells to the specified value", function(){ - workbooks.Each( function( wb ){ + it( "Sets the specified range of cells to the specified value", ()=>{ + workbooks.Each( ( wb )=>{ s.setCellRangeValue( wb, value, 1, 2, 1, 2 ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).setCellRangeValue( value, 1, 2, 1, 2 ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/cellStyle.cfm b/test/specs/cellStyle.cfm index 3fdd81a..2c4f2eb 100644 --- a/test/specs/cellStyle.cfm +++ b/test/specs/cellStyle.cfm @@ -1,27 +1,27 @@ -describe( "cellStyle", function(){ +describe( "cellStyle", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; variables.format = { bold: true }; variables.data = [ [ "x", "y" ] ]; - }); + }) - it( "can create a valid POI CellStyle object from a given format", function(){ - workbooks.Each( function( wb ){ + it( "can create a valid POI CellStyle object from a given format", ()=>{ + workbooks.Each( ( wb )=>{ expect( s.getFormatHelper().isValidCellStyleObject( wb, s.createCellStyle( wb, format ) ) ).toBeTrue(); - }); - }); + }) + }) - it( "createCellStyle is chainable", function(){ - workbooks.Each( function( wb ){ + it( "createCellStyle is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var style = s.newChainable( wb ).createCellStyle( format ); expect( s.getFormatHelper().isValidCellStyleObject( wb, style ) ).toBeTrue(); - }); - }); + }) + }) - it( "allows a single common cellStyle to be applied across multiple formatting calls and sheets", function(){ - workbooks.Each( function( wb ){ + it( "allows a single common cellStyle to be applied across multiple formatting calls and sheets", ()=>{ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var expected = s.isXmlFormat( wb )? 1: 21; expect( s.getWorkbookCellStylesTotal( wb ) ).toBe( expected ); @@ -35,50 +35,50 @@ describe( "cellStyle", function(){ .formatCell( workbook=wb, format=style, row=1, column=2 ); expected = s.isXmlFormat( wb )? 2: 22; expect( s.getWorkbookCellStylesTotal( wb ) ).toBe( expected ); - }); - }); + }) + }) - describe( "cellStyle utilities", function(){ + describe( "cellStyle utilities", ()=>{ - it( "can return the total number of registered workbook cell styles", function(){ - workbooks.Each( function( wb ){ + it( "can return the total number of registered workbook cell styles", ()=>{ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var expected = s.isXmlFormat( wb )? 1: 21; expect( s.getWorkbookCellStylesTotal( wb ) ).toBe( expected ); s.formatColumns( wb, format, 1 ); expected = s.isXmlFormat( wb )? 2: 22; expect( s.getWorkbookCellStylesTotal( wb ) ).toBe( expected ); - }); - }); + }) + }) - it( "can clear the cellStyle object cache", function(){ + it( "can clear the cellStyle object cache", ()=>{ s.clearCellStyleCache(); expect( s.getCellStyleCache().xls ).toBeEmpty(); expect( s.getCellStyleCache().xlsx ).toBeEmpty(); - spreadsheetTypes.Each( function( type ){ + spreadsheetTypes.Each( ( type )=>{ s.newChainable( type ) .addRows( data ) .formatRow( { bold: true }, 1 ); expect( s.getCellStyleCache()[ type ] ).notToBeEmpty(); - }); + }) s.clearCellStyleCache(); expect( s.getCellStyleCache().xls ).toBeEmpty(); expect( s.getCellStyleCache().xlsx ).toBeEmpty(); - }); + }) - }); + }) - describe( "format functions throw an exception if", function(){ + describe( "format functions throw an exception if", ()=>{ - it( "the cellStyle argument is present but invalid", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the cellStyle argument is present but invalid", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.formatCell( workbook=wb, format="not a cellStyle object", row=1, column=1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidCellStyleArgument" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/cellValue.cfm b/test/specs/cellValue.cfm index f11c82c..d48ac52 100644 --- a/test/specs/cellValue.cfm +++ b/test/specs/cellValue.cfm @@ -1,94 +1,94 @@ -describe( "cellValue", function(){ +describe( "cellValue", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Gets the value from the specified cell", function(){ + it( "Gets the value from the specified cell", ()=>{ var data = [ [ "a", "b" ], [ "c", "d" ] ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); expect( s.getCellValue( wb, 2, 2 ) ).toBe( "d" ); - }); - }); + }) + }) - it( "Sets the specified cell to the specified string value", function(){ + it( "Sets the specified cell to the specified string value", ()=>{ var value = "test"; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Sets the specified cell to the specified numeric value", function(){ + it( "Sets the specified cell to the specified numeric value", ()=>{ var value = 1; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Sets the specified cell to the specified date value", function(){ + it( "Sets the specified cell to the specified date value", ()=>{ var value = CreateDate( 2015, 04, 12 ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); var expected = DateFormat( value, "yyyy-mm-dd" ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( expected ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Sets the specified cell to the specified boolean value with a data type of string by default", function(){ + it( "Sets the specified cell to the specified boolean value with a data type of string by default", ()=>{ var value = true; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "Sets zeros as zeros, not booleans", function(){ + it( "Sets zeros as zeros, not booleans", ()=>{ var value = 0; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "Sets the specified range of cells to the specified value", function(){ + it( "Sets the specified range of cells to the specified value", ()=>{ var value = "a"; var expected = querySim( "column1,column2 a|a a|a"); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellRangeValue( wb, value, 1, 2, 1, 2 ); actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "handles numbers with leading zeros correctly", function(){ + it( "handles numbers with leading zeros correctly", ()=>{ var value = "0162220494"; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "handles non-date values correctly that Lucee parses as partial dates far in the future", function(){ - workbooks.Each( function( wb ){ + it( "handles non-date values correctly that Lucee parses as partial dates far in the future", ()=>{ + workbooks.Each( ( wb )=>{ var value = "01-23112"; s.setCellValue( wb, value, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); @@ -99,50 +99,50 @@ describe( "cellValue", function(){ actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "does not accept '9a' or '9p' or '9 a' as valid dates, correcting ACF", function(){ + it( "does not accept '9a' or '9p' or '9 a' as valid dates, correcting ACF", ()=>{ values = [ "9a", "9p", "9 a", "9 p", "9A" ]; - values.Each( function( value ){ - workbooks.Each( function( wb ){ + values.Each( ( value )=>{ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); - }); + }) + }) + }) it( title="but does accept date strings with AM or PM", - body=function(){ - workbooks.Each( function( wb ){ + body=()=>{ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, "22/8/2020 10:34 AM", 1, 1 ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( "2020-08-22 10:34:00" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); s.setCellValue( wb, "12:53 pm", 1, 1 ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( "12:53:00" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); - }); + }) }, skip=s.getIsBoxlang() ); - it( "getCellValue and setCellValue are chainable", function(){ + it( "getCellValue and setCellValue are chainable", ()=>{ var value = "test"; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var actual = s.newChainable( wb ) .setCellValue(value, 1, 1 ) .getCellValue( 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "returns the visible/formatted value by default", function(){ + it( "returns the visible/formatted value by default", ()=>{ var value = 0.000011; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); s.formatCell( wb, { dataformat: "0.00000" }, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); @@ -150,12 +150,12 @@ describe( "cellValue", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); var decimalHasBeenOutputInScientificNotation = ( Trim( actual ).FindNoCase( "E" ) > 0 ); expect( decimalHasBeenOutputInScientificNotation ).toBeFalse(); - }); - }); + }) + }) - it( "can return the raw (unformatted) value", function(){ + it( "can return the raw (unformatted) value", ()=>{ var value = 0.000011; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); s.formatCell( wb, { dataformat: "0.00000" }, 1, 1 ); var actual = s.getCellValue( wb, 1, 1, false ); @@ -164,132 +164,132 @@ describe( "cellValue", function(){ // chainable var actual = s.newChainable( wb ).getCellValue( 1, 1, false ); expect( actual ).toBe( value ); - }); - }); + }) + }) - describe( "allows the auto data type detection to be overridden", function(){ + describe( "allows the auto data type detection to be overridden", ()=>{ - it( "allows forcing values to be added as strings", function(){ + it( "allows forcing values to be added as strings", ()=>{ var value = 1.234; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1, "string" ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( "1.234" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - it( "allows forcing values to be added as numbers", function(){ + it( "allows forcing values to be added as numbers", ()=>{ var value = "0123"; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1, "numeric" ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( 123 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" ); - }); - }); + }) + }) - it( "allows forcing values to be added as dates", function(){ + it( "allows forcing values to be added as dates", ()=>{ var value = "01.1990"; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1, "date" ); var actual = s.getCellValue( wb, 1, 1 ); expect( DateFormat( actual, "yyyy-mm-dd" ) ).toBe( "1990-01-01" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" );// dates are numeric in Excel - }); - }); + }) + }) - it( "allows forcing values to be added as times (without a date)", function(){ + it( "allows forcing values to be added as times (without a date)", ()=>{ var value = "08:21:30"; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1, "time" ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( value ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "numeric" );// dates are numeric in Excel - }); - }); + }) + }) - it( "allows forcing values to be added as booleans", function(){ + it( "allows forcing values to be added as booleans", ()=>{ var values = [ "true", true, 1, "1", "yes", 10 ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ for( var value in values ){ s.setCellValue( wb, value, 1, 1, "boolean" ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBeTrue(); expect( s.getCellType( wb, 1, 1 ) ).toBe( "boolean" ); } - }); - }); + }) + }) - it( "allows forcing values to be added as blanks", function(){ + it( "allows forcing values to be added as blanks", ()=>{ var values = [ "", "blah" ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ for( var value in values ){ s.setCellValue( wb, value, 1, 1, "blank" ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBeEmpty(); expect( s.getCellType( wb, 1, 1 ) ).toBe( "blank" ); } - }); - }); + }) + }) - it( "support legacy 'type' argument name", function(){ + it( "support legacy 'type' argument name", ()=>{ var value = 1.234; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( workbook=wb, value=value, row=1, column=1, type="string" ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( "1.234" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - workbooks.Each( function( wb ){ + }) + workbooks.Each( ( wb )=>{ var actual = s.newChainable( wb ) .setCellValue( value=value, row=1, column=1, type="string" ) .getCellValue( 1, 1 ); expect( actual ).toBe( "1.234" ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); - }); - }); + }) + }) - }); + }) describe( title="Lucee only timezone tests", - body=function(){ + body=()=>{ - it( "Knows if Lucee timezone matches POI", function(){ + it( "Knows if Lucee timezone matches POI", ()=>{ s.getDateHelper().matchPoiTimeZoneToEngine(); expect( s.getDateHelper().getPoiTimeZone() ).toBe( GetTimeZone() ); - }); + }) - it( "Sets the specified cell to the specified date value even if the Lucee timezone doesn't match the system", function(){ + it( "Sets the specified cell to the specified date value even if the Lucee timezone doesn't match the system", ()=>{ variables.currentTZ = GetTimeZone(); //Needs manually adjusting if the test Lucee instance TZ is in Central European Time, i.e. same as London e.g. Lisbon variables.tempTZ = ( currentTZ == "Europe/London" )? "Europe/Paris": "Europe/London"; SetTimeZone( tempTZ ); var value = CreateDate( 2015, 04, 12 ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, value, 1, 1 ); s.formatCell( wb, { dataformat: "0.0" }, 1, 1 ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( 42106.0 );// whole number = date, no time - }); + }) SetTimeZone( currentTZ ); - }); + }) }, skip=!s.getIsLucee() ); - describe( "setCellValue throws an exception if", function(){ + describe( "setCellValue throws an exception if", ()=>{ - it( "the data type is invalid", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the data type is invalid", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.setCellValue( wb, "test", 1, 1, "blah" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidDatatype" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/chaining.cfm b/test/specs/chaining.cfm index 6714bc8..7b213b0 100644 --- a/test/specs/chaining.cfm +++ b/test/specs/chaining.cfm @@ -1,25 +1,25 @@ -describe( "chaining", function(){ +describe( "chaining", ()=>{ - it( "Allows void methods to be chained", function() { + it( "Allows void methods to be chained", ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; var theComment = { author: "cfsimplicity" ,comment: "This is the comment in row 1 column 1" }; var expected = Duplicate( theComment ).Append( { column: 1, row: 1 } ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "1" ).setCellComment( wb, theComment, 1, 1 ); var actual = s.getCellComment( wb, 1, 1 ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - describe( "newChainable", function(){ + describe( "newChainable", ()=>{ - describe( "initialisation", function() { + describe( "initialisation", ()=>{ - it( "allows a new workbook of the specified type to be created inside a chainable object", function(){ + it( "allows a new workbook of the specified type to be created inside a chainable object", ()=>{ o = s.newChainable( "xls" ); expect( s.isBinaryFormat( o.getWorkbook() ) ).toBeTrue(); o = s.newChainable( "xlsx" ); @@ -28,62 +28,62 @@ describe( "chaining", function(){ expect( s.isStreamingXmlFormat( o.getWorkbook() ) ).toBeTrue(); o = s.newChainable( "streamingXlsx" ); expect( s.isStreamingXmlFormat( o.getWorkbook() ) ).toBeTrue(); - }); + }) - it( "allows an existing wookbook to be passed to a chainable object", function(){ + it( "allows an existing wookbook to be passed to a chainable object", ()=>{ xls = s.newXls(); o = s.newChainable( xls ); expect( s.isBinaryFormat( o.getWorkbook() ) ).toBeTrue(); - }); + }) - it( "Allows the workbook to be read post initialisation", function(){ + it( "Allows the workbook to be read post initialisation", ()=>{ wb = s.newChainable().read( getTestFilePath( "test.xlsx" ) ).getWorkbook(); expect( s.isXmlFormat( wb ) ).toBeTrue(); - }); + }) - it( "Allows the workbook to be generated from a CSV file", function(){ + it( "Allows the workbook to be generated from a CSV file", ()=>{ var csv = 'column1,column2#newline#"Frumpo McNugget",12345'; wb = s.newChainable().fromCsv( csv=csv, firstRowIsHeader=true ).getWorkbook(); expect( s.getCellValue( wb, 2, 2 ) ).toBe( "12345" ); - }); + }) - it( "Allows the workbook to be generated from a query", function(){ + it( "Allows the workbook to be generated from a query", ()=>{ var query = QueryNew( "Header1,Header2", "VarChar,VarChar",[ [ "a", "b" ],[ "c", "d" ] ] ); wb = s.newChainable().fromQuery( query ).getWorkbook(); actual = s.getSheetHelper().sheetToQuery( workbook=wb, headerRow=1 ); expect( actual ).toBe( query ); - }); + }) - }); + }) - it( "Allows multiple operations on a single workbook object to be chained", function(){ + it( "Allows multiple operations on a single workbook object to be chained", ()=>{ wb = s.newChainable( "xlsx" ) .addRow( [ "a", "b", "c" ] ) .formatCell( { bold=true }, 1, 1 ) .getWorkbook(); expect( s.getCellValue( wb, 1, 1 ) ).toBe( "a" ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); - }); + }) - describe( "a chained call throws an exception if", function(){ + describe( "a chained call throws an exception if", ()=>{ - it( "no workbook has been passed in, read or initialised", function(){ - expect( function(){ + it( "no workbook has been passed in, read or initialised", ()=>{ + expect( ()=>{ s.newChainable().addRow( [ "a", "b", "c" ] ); }).toThrow( type="cfsimplicity.spreadsheet.missingWorkbook" ); - }); + }) - it( "the workbook is not a invalid object", function(){ - expect( function(){ + it( "the workbook is not a invalid object", ()=>{ + expect( ()=>{ var invalidWorkbookObject = QueryNew( "" ); s.newChainable( invalidWorkbookObject ) .addRow( [ "a", "b", "c" ] ); }).toThrow( type="cfsimplicity.spreadsheet.invalidWorkbook" ); - }); + }) - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/clearCell.cfm b/test/specs/clearCell.cfm index 96e4d86..3726964 100644 --- a/test/specs/clearCell.cfm +++ b/test/specs/clearCell.cfm @@ -1,55 +1,55 @@ -describe( "clearCell", function(){ +describe( "clearCell", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Clears the specified cell", function(){ + it( "Clears the specified cell", ()=>{ var expected = ""; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, "test", 1, 1 ) .clearCell( wb, 1, 1 ); var actual = s.getCellValue( wb, 1, 1 ); expect( actual ).toBe( expected ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "BLANK" ); - }); - }); + }) + }) - it( "Clears the specified range of cells", function(){ + it( "Clears the specified range of cells", ()=>{ var data = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "a","b","c" ], [ "d","e","f" ], [ "g","h","i" ] ] ); var expected = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "a","b","c" ], [ "d","","" ], [ "g","","" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ) .clearCellRange( wb, 2, 2, 3, 3 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "clearCell is chainable", function(){ + it( "clearCell is chainable", ()=>{ var expected = ""; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var actual = s.newChainable( wb ) .setCellValue( "test", 1, 1 ) .clearCell( 1, 1 ) .getCellValue( 1, 1 ); expect( actual ).toBe( expected ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "BLANK" ); - }); - }); + }) + }) - it( "clearCellRange is chainable", function(){ + it( "clearCellRange is chainable", ()=>{ var data = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "a","b","c" ], [ "d","e","f" ], [ "g","h","i" ] ] ); var expected = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "a","b","c" ], [ "d","","" ], [ "g","","" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .addRows( data ) .clearCellRange( 2, 2, 3, 3 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/columnWidth.cfm b/test/specs/columnWidth.cfm index 4a47f35..135864b 100644 --- a/test/specs/columnWidth.cfm +++ b/test/specs/columnWidth.cfm @@ -1,26 +1,26 @@ -describe( "columnWidth", function(){ +describe( "columnWidth", ()=>{ - it( "can set and get column width", function(){ + it( "can set and get column width", ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "a" ) .setColumnWidth( wb, 1, 10 ); expect( s.getColumnWidth( wb, 1 ) ).toBe( 10 ); expect( Round( s.getColumnWidthInPixels( wb, 1 ) ) ).toBe( 70 ); - }); - }); + }) + }) - it( "getColumnWidth and setColumnWidth are chainable", function(){ + it( "getColumnWidth and setColumnWidth are chainable", ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var actual = s.newChainable( wb ) .addRow( "a" ) .setColumnWidth( 1, 10 ) .getColumnWidth( 1 ); expect( actual ).toBe( 10 ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/conditionalFormatting.cfm b/test/specs/conditionalFormatting.cfm index 8bf75b6..691306f 100644 --- a/test/specs/conditionalFormatting.cfm +++ b/test/specs/conditionalFormatting.cfm @@ -1,21 +1,21 @@ -describe( "conditionalFormatting", function(){ +describe( "conditionalFormatting", ()=>{ - it( "can apply a format to cells only when a custom formula evaluates to true", function(){ + it( "can apply a format to cells only when a custom formula evaluates to true", ()=>{ var formatting = s.newConditionalFormatting() .onCells( "A1:B1" ) .when( "$A1<0" ) .setFormat( { fontColor:"RED" } ); - spreadsheetTypes.Each( function( type ){ + spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ).addConditionalFormatting( formatting ); var appliedRules = formatting.rulesAppliedToCell( "B1" ); expect( appliedRules ).toBeEmpty(); chainable.setCellValue( -1, 1, 1 ); //set A1 to -1 appliedColor = formatting.getFormatAppliedToCell( "B1" ).fontColor; expect( appliedColor ).toBe( "255,0,0" ); //RED - }); + }) //alternate direct syntax - spreadsheetTypes.Each( function( type ){ + spreadsheetTypes.Each( ( type )=>{ //A1 value starts as 0. Rule will make A1 and B1 red if A1 is below zero. var wb = ( type == "xls" )? s.newXls(): s.newXlsx(); s.addRow( wb, [ 0, 0 ] ); @@ -25,11 +25,11 @@ describe( "conditionalFormatting", function(){ s.setCellValue( wb, -1, 1, 1 ); //set A1 to -1 appliedColor = formatting.getFormatAppliedToCell( "B1" ).fontColor; expect( appliedColor ).toBe( "255,0,0" ); //RED - }); - }); + }) + }) - it( "can apply a format to cells only when the cell value meets a condition", function(){ - spreadsheetTypes.Each( function( type ){ + it( "can apply a format to cells only when the cell value meets a condition", ()=>{ + spreadsheetTypes.Each( ( type )=>{ //A1 and B1 values start as 0. Rule will make A1 red if A1 is LT zero. var wb = s.newChainable( type ).addRow( [ 0, 0 ] ).getWorkBook(); var formatting = s.newConditionalFormatting() @@ -87,16 +87,16 @@ describe( "conditionalFormatting", function(){ s.setCellValue( wb, 1, 1, 1 ); //set A1 to 1 appliedRules = formatting.rulesAppliedToCell( "A1" ); expect( appliedRules ).toHaveLength( 1 ); - }); - }); + }) + }) - it( "can target a specific sheet name", function(){ + it( "can target a specific sheet name", ()=>{ var formatting = s.newConditionalFormatting() .onCells( "A1:B1" ) .onSheetName( "testSheet" ) .when( "$A1<0" ) .setFormat( { fontColor:"RED" } ); - spreadsheetTypes.Each( function( type ){ + spreadsheetTypes.Each( ( type )=>{ //A1 value starts as 0. Rule will make A1 and B1 red if A1 is below zero. var chainable = s.newChainable( type ) .createSheet( "testSheet" ) @@ -108,16 +108,16 @@ describe( "conditionalFormatting", function(){ chainable.setCellValue( -1, 1, 1 ); //set A1 to -1 appliedColor = formatting.getFormatAppliedToCell( "B1" ).fontColor; expect( appliedColor ).toBe( "255,0,0" ); //RED - }); - }); + }) + }) - it( "can target a specific sheet number", function(){ + it( "can target a specific sheet number", ()=>{ var formatting = s.newConditionalFormatting() .onCells( "A1:B1" ) .onSheetNumber( 2 ) .when( "$A1<0" ) .setFormat( { fontColor:"RED" } ); - spreadsheetTypes.Each( function( type ){ + spreadsheetTypes.Each( ( type )=>{ //A1 value starts as 0. Rule will make A1 and B1 red if A1 is below zero. var chainable = s.newChainable( type ) .createSheet( "testSheet" ) @@ -129,10 +129,10 @@ describe( "conditionalFormatting", function(){ chainable.setCellValue( -1, 1, 1 ); //set A1 to -1 appliedColor = formatting.getFormatAppliedToCell( "B1" ).fontColor; expect( appliedColor ).toBe( "255,0,0" ); //RED - }); - }); + }) + }) - it( "supports a range of font, border and fill pattern formats", function(){ + it( "supports a range of font, border and fill pattern formats", ()=>{ var format = { fontColor:"RED" ,fontSize: 12 @@ -173,36 +173,36 @@ describe( "conditionalFormatting", function(){ ,foregroundFillColor: "255,0,0"//red ,fillPattern: "diamonds" }; - spreadsheetTypes.Each( function( type ){ + spreadsheetTypes.Each( ( type )=>{ s.newChainable( type ).addRow( [ 0 ] ).addConditionalFormatting( formatting ); var actual = formatting.getFormatAppliedToCell( "A1" ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - describe( "throws an exception if", function(){ + describe( "throws an exception if", ()=>{ - it( "the comparison operator is invalid", function(){ - expect( function(){ + it( "the comparison operator is invalid", ()=>{ + expect( ()=>{ s.newConditionalFormatting() .onCells( "A1" ) .whenCellValueIs( "INVALID OPERATOR", 0 ) .setFormat( { color:"RED" } ) .addToWorkbook( s.new() ); }).toThrow( type="cfsimplicity.spreadsheet.invalidOperatorArgument" ); - }); + }) - it( "a BETWEEN operator is used and formula2 is not supplied", function(){ - expect( function(){ + it( "a BETWEEN operator is used and formula2 is not supplied", ()=>{ + expect( ()=>{ s.newConditionalFormatting() .onCells( "A1" ) .whenCellValueIs( "BETWEEN", 0 ) .setFormat( { color:"RED" } ) .addToWorkbook( s.new() ); }).toThrow( type="cfsimplicity.spreadsheet.missingSecondFormulaArgument" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/createJavaObject.cfm b/test/specs/createJavaObject.cfm index 91022f2..0e60199 100644 --- a/test/specs/createJavaObject.cfm +++ b/test/specs/createJavaObject.cfm @@ -1,11 +1,11 @@ -describe( "createJavaObject", function(){ +describe( "createJavaObject", ()=>{ - it( "creates a java object from the bundled library jars", function() { + it( "creates a java object from the bundled library jars", ()=>{ var className = "org.apache.poi.Version"; var object = s.createJavaObject( className ); expect( object.getClass().getCanonicalName() ).toBe( className ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/createSheet.cfm b/test/specs/createSheet.cfm index 87e1f90..a75f583 100644 --- a/test/specs/createSheet.cfm +++ b/test/specs/createSheet.cfm @@ -1,68 +1,68 @@ -describe( "createSheet", function(){ +describe( "createSheet", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Creates a new sheet with a unique name if name not specified", function(){ - workbooks.Each( function( wb ){ + it( "Creates a new sheet with a unique name if name not specified", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb ); expect( wb.getNumberOfSheets() ).toBe( 2 ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).createSheet(); expect( wb.getNumberOfSheets() ).toBe( 2 ); - }); - }); + }) + }) - it( "Creates a new sheet with the specified name", function(){ - workbooks.Each( function( wb ){ + it( "Creates a new sheet with the specified name", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb,"test" ); expect( s.getSheetHelper().sheetExists( workbook=wb, sheetName="test" ) ).toBeTrue(); - }); - }); + }) + }) - it( "Overwrites an existing sheet with the same name if overwrite is true", function(){ - workbooks.Each( function( wb ){ + it( "Overwrites an existing sheet with the same name if overwrite is true", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .createSheet( wb, "test", true ); expect( wb.getNumberOfSheets() ).toBe( 2 ); - }); - }); + }) + }) - describe( "createSheet throws an exception if", function(){ + describe( "createSheet throws an exception if", ()=>{ - it( "the sheet name contains more than 31 characters", function(){ + it( "the sheet name contains more than 31 characters", ()=>{ var filename = repeatString( "a", 32 ); - workbooks.Each( function( wb ){ - expect( function(){ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.createSheet( wb, filename ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); - }); + }) + }) - it( "the sheet name contains invalid characters", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet name contains invalid characters", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.createSheet( wb, "[]?*\/:" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidCharacters" ); - }); - }); + }) + }) - it( "a sheet exists with the specified name and overwrite is false", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "a sheet exists with the specified name and overwrite is false", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.createSheet( wb, "test" ) .createSheet( wb, "test" ); }).toThrow( type="cfsimplicity.spreadsheet.sheetNameAlreadyExists" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/csvToQuery.cfm b/test/specs/csvToQuery.cfm index 1627bd2..4de9761 100644 --- a/test/specs/csvToQuery.cfm +++ b/test/specs/csvToQuery.cfm @@ -1,17 +1,17 @@ -describe( "csvToQuery", function(){ +describe( "csvToQuery", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.basicExpectedQuery = QueryNew( "column1,column2", "", [ [ "Frumpo McNugget", "12345" ] ] ); - }); + }) - it( "converts a basic comma delimited, double quote qualified csv string to a query", function(){ + it( "converts a basic comma delimited, double quote qualified csv string to a query", ()=>{ var csv = '"Frumpo McNugget",12345'; var actual = s.csvToQuery( csv ); expect( actual ).toBe( basicExpectedQuery ); - }); + }) - it( "can read the csv from a file", function(){ + it( "can read the csv from a file", ()=>{ var path = getTestFilePath( "test.csv" ); //named args var actual = s.csvToQuery( filepath=path ); @@ -19,9 +19,9 @@ describe( "csvToQuery", function(){ //positional args var actual = s.csvToQuery( "", path ); expect( actual ).toBe( basicExpectedQuery ); - }); + }) - it( "can read the csv from a VFS file", function(){ + it( "can read the csv from a VFS file", ()=>{ var path = "ram:///test.csv"; if( !DirectoryExists( GetDirectoryFromPath( path ) ) ) //Skip when there's an issue with the ram drive return; @@ -30,57 +30,57 @@ describe( "csvToQuery", function(){ expect( actual ).toBe( basicExpectedQuery ); if( FileExists( path ) ) FileDelete( path ); - }); + }) - it( "can read the csv from a text file with an .xls extension", function(){ + it( "can read the csv from a text file with an .xls extension", ()=>{ var path = getTestFilePath( "csv.xls" ); var actual = s.csvToQuery( filepath=path ); expect( actual ).toBe( basicExpectedQuery ); - }); + }) - it( "can handle an embedded delimiter", function(){ + it( "can handle an embedded delimiter", ()=>{ var csv = '"McNugget,Frumpo",12345'; var expected = QueryNew( "column1,column2", "", [ [ "McNugget,Frumpo", "12345" ] ] ); var actual = s.csvToQuery( csv ); expect( actual ).toBe( expected ); - }); + }) - it( "can handle an embedded double-quote", function(){ + it( "can handle an embedded double-quote", ()=>{ var csv = '"Frumpo ""Frumpie"" McNugget",12345'; var expected = QueryNew( "column1,column2", "", [ [ "Frumpo ""Frumpie"" McNugget", "12345" ] ] ); var actual = s.csvToQuery( csv ); expect( actual ).toBe( expected ); - }); + }) - it( "can handle an embedded line break", function(){ + it( "can handle an embedded line break", ()=>{ var csv = '"A line#Chr( 10 )#break",12345'; var expected = QueryNew( "column1,column2", "", [ [ "A line#Chr( 10 )#break", "12345" ] ] ); var actual = s.csvToQuery( csv ); expect( actual ).toBe( expected ); - }); + }) - it( "can handle an embedded line break when there are surrounding spaces", function(){ + it( "can handle an embedded line break when there are surrounding spaces", ()=>{ var csv = 'A space precedes the next field value, "A line#Chr( 10 )#break"'; var expected = QueryNew( "column1,column2", "", [ [ "A space precedes the next field value", "A line#Chr( 10 )#break" ] ] ); var actual = s.csvToQuery( csv ); expect( actual ).toBe( expected ); - }); + }) - it( "can handle empty cells", function(){ + it( "can handle empty cells", ()=>{ var csv = 'Frumpo,McNugget#newline#Susi#newline#Susi,#newline#,Sorglos#newline# '; var expected = QueryNew( "column1,column2", "", [ [ "Frumpo", "McNugget" ], [ "Susi", "" ], [ "Susi", "" ], [ "", "Sorglos" ] ] ); var actual = s.csvToQuery( csv ); expect( actual ).toBe( expected ); - }); + }) - it( "can treat the first line as the column names", function(){ + it( "can treat the first line as the column names", ()=>{ var csv = 'Name,Phone#newline#Frumpo,12345'; var expected = QueryNew( "Name,Phone", "", [ [ "Frumpo", "12345" ] ] ); var actual = s.csvToQuery( csv=csv, firstRowIsHeader=true ); expect( actual ).toBe( expected ); - }); + }) - it( "can handle spaces in header/column names", function(){ + it( "can handle spaces in header/column names", ()=>{ var csv = 'Name,Phone Number#newline#Frumpo,12345'; if( s.getIsACF() ){ //ACF won't allow spaces in column names when creating queries programmatically. Use setColumnNames() to override: @@ -91,9 +91,9 @@ describe( "csvToQuery", function(){ var expected = QueryNew( "Name,Phone Number", "", [ [ "Frumpo", "12345" ] ] ); var actual = s.csvToQuery( csv=csv, firstRowIsHeader=true ); expect( actual ).toBe( expected ); - }); + }) - it( "will preserve the case of header/column names", function(){ + it( "will preserve the case of header/column names", ()=>{ var csv = 'Name,Phone#newline#Frumpo McNugget,12345'; var actual = s.csvToQuery( csv=csv, firstRowIsHeader=true ); expect( actual.getColumnNames()[ 1 ] ).toBeWithCase( "Name" ); @@ -101,48 +101,48 @@ describe( "csvToQuery", function(){ csv = '1st Name,Phone#newline#Frumpo McNugget,12345'; actual = s.csvToQuery( csv=csv, firstRowIsHeader=true ); expect( actual.getColumnNames()[ 1 ] ).toBeWithCase( "1st Name" ); - }); + }) - describe( "trimming", function(){ + describe( "trimming", ()=>{ - it( "will trim the csv string by default", function(){ + it( "will trim the csv string by default", ()=>{ var csv = newline & '"Frumpo McNugget",12345' & newline; var actual = s.csvToQuery( csv ); expect( actual ).toBe( basicExpectedQuery ); - }); + }) - it( "will trim the csv file by default", function(){ + it( "will trim the csv file by default", ()=>{ var csv = newline & '"Frumpo McNugget",12345' & newline; FileWrite( tempCsvPath, csv ); var actual = s.csvToQuery( filepath: tempCsvPath ); expect( actual ).toBe( basicExpectedQuery ); - }); + }) - it( "can preserve a string's leading/trailing space", function(){ + it( "can preserve a string's leading/trailing space", ()=>{ var csv = newline & '"Frumpo McNugget",12345' & newline; var actual = s.csvToQuery( csv: csv, trim: false ); expected = QueryNew( "column1,column2", "", [ [ "", "" ], [ "Frumpo McNugget", "12345" ] ] ); expect( actual ).toBe( expected ); - }); + }) - it( "can preserve a file's leading/trailing space", function(){ + it( "can preserve a file's leading/trailing space", ()=>{ var csv = newline & '"Frumpo McNugget",12345' & newline; FileWrite( tempCsvPath, csv ); var actual = s.csvToQuery( filepath: tempCsvPath, trim: false ); expected = QueryNew( "column1,column2", "", [ [ "", "" ], [ "Frumpo McNugget", "12345" ] ] ); expect( actual ).toBe( expected ); - }); + }) - afterEach( function(){ + afterEach( ()=>{ if( FileExists( tempCsvPath ) ) FileDelete( tempCsvPath ); - }); + }) - }); + }) - describe( "delimiter handling", function(){ + describe( "delimiter handling", ()=>{ - it( "can accept an alternative delimiter", function(){ + it( "can accept an alternative delimiter", ()=>{ var csv = '"Frumpo McNugget"|12345'; //named args var actual = s.csvToQuery( csv=csv, delimiter="|" ); @@ -150,48 +150,48 @@ describe( "csvToQuery", function(){ //positional var actual = s.csvToQuery( csv, "", false, true, "|" ); expect( actual ).toBe( basicExpectedQuery ); - }); + }) - it( "has special handling for tab delimited data", function(){ + it( "has special handling for tab delimited data", ()=>{ var csv = '"Frumpo McNugget"#Chr( 9 )#12345'; var validTabValues = [ "#Chr( 9 )#", "\t", "tab", "TAB" ]; for( var value in validTabValues ){ var actual = s.csvToQuery( csv=csv, delimiter="#value#" ); expect( actual ).toBe( basicExpectedQuery ); } - }); + }) - }); + }) - describe( "query column name setting", function(){ + describe( "query column name setting", ()=>{ - it( "Allows column names to be specified as an array when reading a csv into a query", function(){ + it( "Allows column names to be specified as an array when reading a csv into a query", ()=>{ var csv = '"Frumpo McNugget",12345'; var columnNames = [ "name", "phone number" ]; var q = s.csvToQuery( csv=csv, queryColumnNames=columnNames, firstRowIsHeader=true ); expect( q.getColumnNames()[ 1 ] ).toBe( columnNames[ 1 ] ); expect( q.getColumnNames()[ 2 ] ).toBe( columnNames[ 2 ] ); - }); + }) - it( "ColumnNames argument overrides firstRowIsHeader: none of the header row values will be used", function(){ + it( "ColumnNames argument overrides firstRowIsHeader: none of the header row values will be used", ()=>{ var csv = 'header1,header2#newline#"Frumpo McNugget",12345'; var columnNames = [ "name", "phone number" ]; var q = s.csvToQuery( csv=csv, queryColumnNames=columnNames ); expect( q.getColumnNames()[ 1 ] ).toBe( columnNames[ 1 ] ); expect( q.getColumnNames()[ 2 ] ).toBe( columnNames[ 2 ] ); - }); + }) - it( "Allows csv header names to be made safe for query column names", function(){ + it( "Allows csv header names to be made safe for query column names", ()=>{ var csv = 'id,id,"A B","x/?y","(a)"," A","##1","1a"#newline#1,2,3,4,5,6,7,8'; var q = s.csvToQuery( csv=csv, firstRowIsHeader=true, makeColumnNamesSafe=true ); expect( q.getColumnNames() ).toBe( [ "id", "id2", "A_B", "x_y", "_a_", "A", "Number1", "_a" ] ); - }); + }) - }); + }) - describe( "query column type setting", function(){ + describe( "query column type setting", ()=>{ - it( "allows the query column types to be manually set using a list", function(){ + it( "allows the query column types to be manually set using a list", ()=>{ var csv = '1,1.1,"string",#_CreateTime( 1, 0, 0 )#'; var q = s.csvToQuery( csv=csv, queryColumnTypes="Integer,Double,VarChar,Time" ); var columns = GetMetaData( q ); @@ -199,9 +199,9 @@ describe( "csvToQuery", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be manually set where the column order isn't known, but the header row values are", function(){ + it( "allows the query column types to be manually set where the column order isn't known, but the header row values are", ()=>{ var csv = 'integer,double,"string column",time#newline#1,1.1,string,12:00'; var columnTypes = { "string column": "VARCHAR", "integer": "INTEGER", "time": "TIME", "double": "DOUBLE" };//not in order var q = s.csvToQuery( csv=csv, queryColumnTypes="Integer,Double,VarChar,Time", firstRowIsHeader=true ); @@ -210,9 +210,9 @@ describe( "csvToQuery", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be manually set where the column order isn't known, but the column names are", function(){ + it( "allows the query column types to be manually set where the column order isn't known, but the column names are", ()=>{ var csv = '1,1.1,"string",#_CreateTime( 1, 0, 0 )#'; var columnNames = [ "integer", "double", "string column", "time" ]; var columnTypes = { "string": "VARCHAR", "integer": "INTEGER", "time": "TIME", "double": "DOUBLE" };//not in order @@ -222,9 +222,9 @@ describe( "csvToQuery", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be automatically set", function(){ + it( "allows the query column types to be automatically set", ()=>{ var csv = '1,1.1,"string",2021-03-10 12:00:00'; var q = s.csvToQuery( csv=csv, queryColumnTypes="auto" ); var columns = GetMetaData( q ); @@ -232,9 +232,9 @@ describe( "csvToQuery", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIMESTAMP" ); - }); + }) - it( "automatic detecting of query column types ignores blank cells", function(){ + it( "automatic detecting of query column types ignores blank cells", ()=>{ var csv = ',,,#newline#,2,test,2021-03-10 12:00:00#newline#1,1.1,string,2021-03-10 12:00:00#newline#1,,,'; var q = s.csvToQuery( csv=csv, queryColumnTypes="auto" ); var columns = GetMetaData( q ); @@ -242,9 +242,9 @@ describe( "csvToQuery", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIMESTAMP" ); - }); + }) - it( "allows a default type to be set for all query columns", function(){ + it( "allows a default type to be set for all query columns", ()=>{ var csv = '1,1.1,"string",#_CreateTime( 1, 0, 0 )#'; var q = s.csvToQuery( csv=csv, queryColumnTypes="VARCHAR" ); var columns = GetMetaData( q ); @@ -252,49 +252,49 @@ describe( "csvToQuery", function(){ expect( columns[ 2 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "VARCHAR" ); - }); + }) - }); + }) - describe( "csvToQuery throws an exception if", function(){ + describe( "csvToQuery throws an exception if", ()=>{ - it( "neither 'csv' nor 'filepath' are passed", function(){ - expect( function(){ + it( "neither 'csv' nor 'filepath' are passed", ()=>{ + expect( ()=>{ s.csvToQuery(); }).toThrow( type="cfsimplicity.spreadsheet.missingRequiredArgument" ); - }); + }) - it( "both 'csv' and 'filepath' are passed", function(){ - expect( function(){ + it( "both 'csv' and 'filepath' are passed", ()=>{ + expect( ()=>{ s.csvToQuery( csv="x", filepath="x" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArgumentCombination" ); - expect( function(){ + expect( ()=>{ s.csvToQuery( "x", "x" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArgumentCombination" ); - }); + }) - it( "a non-existent file is passed", function(){ - expect( function(){ + it( "a non-existent file is passed", ()=>{ + expect( ()=>{ s.csvToQuery( filepath=ExpandPath( "missing.csv" ) ); }).toThrow( type="cfsimplicity.spreadsheet.nonExistentFile" ); - }); + }) - it( "a non text/csv file is passed", function(){ + it( "a non text/csv file is passed", ()=>{ var path = getTestFilePath( "test.xls" ); - expect( function(){ + expect( ()=>{ s.csvToQuery( filepath=path ); }).toThrow( type="cfsimplicity.spreadsheet.invalidCsvFile" ); - }); + }) - it( "queryColumnTypes is specified as a 'columnName/type' struct, but firstRowIsHeader is not set to true AND columnNames are not provided", function(){ - expect( function(){ + it( "queryColumnTypes is specified as a 'columnName/type' struct, but firstRowIsHeader is not set to true AND columnNames are not provided", ()=>{ + expect( ()=>{ // using 'var' keyword here causes ACF2021 to throw exception local.columnTypes = { col1: "Integer" }; local.q = s.csvToQuery( csv="1", queryColumnTypes=columnTypes ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArgumentCombination" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/dataValidation.cfm b/test/specs/dataValidation.cfm index 8e9654f..227d010 100644 --- a/test/specs/dataValidation.cfm +++ b/test/specs/dataValidation.cfm @@ -1,26 +1,26 @@ -describe( "dataValidation", function(){ +describe( "dataValidation", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.cellRange = "A1:B1"; variables.validValues = [ "London", "Paris", "New York" ]; variables.minDate = CreateDate( 2020, 1, 1 ); variables.maxDate = CreateDate( 2020, 12, 31 ); - }); + }) - describe( "drop-downs", function(){ + describe( "drop-downs", ()=>{ - it( "can create a validation drop-down using an array of values", function() { + it( "can create a validation drop-down using an array of values", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withValues( validValues ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); expect( dv.validValueArrayAppliedToSheet() ).toBe( validValues ); expect( dv.targetCellRangeAppliedToSheet() ).toBe( cellRange ); - }); + }) //alternate direct syntax - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var wb = ( type == "xls" )? s.newXls(): s.newXlsx(); var dv = s.newDataValidation() .onCells( cellRange ) @@ -28,28 +28,28 @@ describe( "dataValidation", function(){ .addToWorkbook( wb ); expect( dv.targetCellRangeAppliedToSheet() ).toBe( cellRange ); expect( dv.validValueArrayAppliedToSheet() ).toBe( validValues ); - }); - }); + }) + }) - it( "can create a validation drop-down from values in other cells in the same sheet", function() { + it( "can create a validation drop-down from values in other cells in the same sheet", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withValuesFromCells( "C1:C3" ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ) .addColumn( data=validValues, startColumn=3 ) .addDataValidation( dv ); expect( dv.targetCellRangeAppliedToSheet() ).toBe( cellRange ); expect( dv.sourceCellsReferenceAppliedToSheet() ).toBe( "Sheet1!$C$1:$C$3" ); - }); - }); + }) + }) - it( "can create a validation drop-down from values in other cells in a different sheet", function() { + it( "can create a validation drop-down from values in other cells in a different sheet", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withValuesFromSheetName( "cities" ) .withValuesFromCells( "A1:A3" ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ) .createSheet( "cities" ) .setActiveSheetNumber( 2 ) @@ -58,15 +58,15 @@ describe( "dataValidation", function(){ .addDataValidation( dv ); expect( dv.targetCellRangeAppliedToSheet() ).toBe( cellRange ); expect( dv.sourceCellsReferenceAppliedToSheet() ).toBe( "cities!$A$1:$A$3" ); - }); - }); + }) + }) - it( "can create a validation drop-down from values in other cells in a different sheet the name of which includes a space", function() { + it( "can create a validation drop-down from values in other cells in a different sheet the name of which includes a space", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withValuesFromSheetName( "towns and cities" ) .withValuesFromCells( "A1:A3" ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ) .createSheet( "towns and cities" ) .setActiveSheetNumber( 2 ) @@ -75,66 +75,66 @@ describe( "dataValidation", function(){ .addDataValidation( dv ); expect( dv.targetCellRangeAppliedToSheet() ).toBe( cellRange ); expect( dv.sourceCellsReferenceAppliedToSheet() ).toBe( "'towns and cities'!$A$1:$A$3" ); - }); - }); + }) + }) - it( "the drop-down arrow can be suppressed for a passed array of data", function() { + it( "the drop-down arrow can be suppressed for a passed array of data", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withValues( validValues ) .withNoDropdownArrow(); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); var falseForXlsxTrueForXls = ( type != "xlsx" );// XLSX requires the OPPOSITE explicit boolean setting (WTF!) expect( dv.suppressDropdownSettingArrowAppliedToSheet() ).toBe( falseForXlsxTrueForXls ); - }); - }); + }) + }) - }); + }) - describe( "date constraints", function(){ + describe( "date constraints", ()=>{ - it( "can constrain input to a date range", function(){ + it( "can constrain input to a date range", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withMinDate( minDate ) .withMaxDate( maxDate ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); expect( dv.getConstraintType() ).toBe( "date" ); expect( dv.getConstraintOperator() ).toBe( "BETWEEN" ); - }); - }); + }) + }) - }); + }) - describe( "integer constraints", function(){ + describe( "integer constraints", ()=>{ - it( "can constrain input to an integer range", function(){ + it( "can constrain input to an integer range", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withMinInteger( 0 ) .withMaxInteger( 100 ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); expect( dv.getConstraintType() ).toBe( "integer" ); expect( dv.getConstraintOperator() ).toBe( "BETWEEN" ); - }); - }); + }) + }) - }); + }) - it( "knows its constraint type", function(){ + it( "knows its constraint type", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withValues( validValues ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); expect( dv.getConstraintType() ).toBe( "list" ); - }); - }); + }) + }) - it( "allows the validation error message to be customised", function() { + it( "allows the validation error message to be customised", ()=>{ var errorTitle = "Wrong"; var errorMessage = "Think again, dude."; var dv = s.newDataValidation() @@ -142,69 +142,69 @@ describe( "dataValidation", function(){ .withValues( validValues ) .withErrorTitle( errorTitle ) .withErrorMessage( errorMessage ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); expect( dv.errorTitleAppliedToSheet() ).toBe( errorTitle ); expect( dv.errorMessageAppliedToSheet() ).toBe( errorMessage ); - }); - }); + }) + }) - describe( "throws an exception if", function(){ + describe( "throws an exception if", ()=>{ - it( "the specified source sheet doesn't exist", function(){ + it( "the specified source sheet doesn't exist", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withValuesFromSheetName( "nonexistant" ) .withValuesFromCells( "A1:A3" ); - variables.spreadsheetTypes.Each( function( type ){ - expect( function(){ + variables.spreadsheetTypes.Each( ( type )=>{ + expect( ()=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); + }) - }); + }) - it( "a minDate is specified but no maxDate or vice versa", function(){ + it( "a minDate is specified but no maxDate or vice versa", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withMinDate( minDate ); - variables.spreadsheetTypes.Each( function( type ){ - expect( function(){ + variables.spreadsheetTypes.Each( ( type )=>{ + expect( ()=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); }).toThrow( type="cfsimplicity.spreadsheet.invalidValidationConstraint" ); - }); + }) dv = s.newDataValidation() .onCells( cellRange ) .withMaxDate( maxDate ); - variables.spreadsheetTypes.Each( function( type ){ - expect( function(){ + variables.spreadsheetTypes.Each( ( type )=>{ + expect( ()=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); }).toThrow( type="cfsimplicity.spreadsheet.invalidValidationConstraint" ); - }); + }) - }); + }) - it( "a minInteger is specified but no maxInteger or vice versa", function(){ + it( "a minInteger is specified but no maxInteger or vice versa", ()=>{ var dv = s.newDataValidation() .onCells( cellRange ) .withMinInteger( 0 ); - variables.spreadsheetTypes.Each( function( type ){ - expect( function(){ + variables.spreadsheetTypes.Each( ( type )=>{ + expect( ()=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); }).toThrow( type="cfsimplicity.spreadsheet.invalidValidationConstraint" ); - }); + }) dv = s.newDataValidation() .onCells( cellRange ) .withMaxInteger( 100 ); - variables.spreadsheetTypes.Each( function( type ){ - expect( function(){ + variables.spreadsheetTypes.Each( ( type )=>{ + expect( ()=>{ var chainable = s.newChainable( type ).addDataValidation( dv ); }).toThrow( type="cfsimplicity.spreadsheet.invalidValidationConstraint" ); - }); + }) - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/dateFormats.cfm b/test/specs/dateFormats.cfm index 930cd32..eb02c87 100644 --- a/test/specs/dateFormats.cfm +++ b/test/specs/dateFormats.cfm @@ -1,7 +1,7 @@ -describe( "dateFormats customisability",function(){ +describe( "dateFormats customisability", ()=>{ - it( "the default dateFormats can be overridden individually on init", function() { + it( "the default dateFormats can be overridden individually on init", ()=>{ local.s = newSpreadsheetInstance(); var expected = { DATE: "yyyy-mm-dd" @@ -20,9 +20,9 @@ describe( "dateFormats customisability",function(){ }; actual = local.s.getDateFormats(); expect( actual ).toBe( expected ); - }); + }) - it( "the dateFormats can be set post-init", function() { + it( "the dateFormats can be set post-init", ()=>{ local.s = newSpreadsheetInstance(); var expected = { DATE: "yyyy-mm-dd" @@ -41,15 +41,15 @@ describe( "dateFormats customisability",function(){ ,TIMESTAMP: "yyyy-mm-dd hh:mm:ss" }; expect( local.s.getDateFormats() ).toBe( expected ); - }); + }) - it( "allows the format of date and time values to be customised", function() { + it( "allows the format of date and time values to be customised", ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; //Dates var dateValue = CreateDate( 2019, 04, 12 ); var timeValue = _CreateTime( 1, 5, 5 ); var timestampValue = CreateDateTime( 2019, 04, 12, 1, 5, 5 ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, dateValue, 1, 1 ); var expected = DateFormat( dateValue, "yyyy-mm-dd" ); var actual = s.getCellValue( wb, 1, 1 ); @@ -81,10 +81,10 @@ describe( "dateFormats customisability",function(){ s.setCellValue( wb, timestampValue, 1, 1 ); expected = DateTimeFormat( timestampValue, "mm/dd/yyyy h:n:s" ); actual = s.getCellValue( wb, 1, 1 ); - }); - }); + }) + }) - it( "Uses the overridden DATETIME format mask when generating CSV and HTML",function() { + it( "Uses the overridden DATETIME format mask when generating CSV and HTML",()=>{ local.s = newSpreadsheetInstance( dateFormats={ DATETIME="mm/dd/yyyy h:n:s" } ); var path = getTestFilePath( "test.xls" ); var actual = s.read( src=path, format="html" ); @@ -93,17 +93,17 @@ describe( "dateFormats customisability",function(){ expected = 'a,b#newline#1,04/01/2015 12:0:0#newline#04/01/2015 1:1:1,2#newline#'; actual = s.read( src=path, format="csv" ); expect( actual ).toBe( expected ); - }); + }) - describe( "dateFormats: throws an exception if",function(){ + describe( "dateFormats: throws an exception if",()=>{ - it( "a passed format key is invalid",function() { - expect( function(){ + it( "a passed format key is invalid",()=>{ + expect( ()=>{ local.s = newSpreadsheetInstance( dateFormats={ DAT="mm/dd/yyyy" } ); }).toThrow( type="cfsimplicity.spreadsheet.invalidDateFormatKey" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/deleteColumn.cfm b/test/specs/deleteColumn.cfm index dd5e82c..c58939f 100644 --- a/test/specs/deleteColumn.cfm +++ b/test/specs/deleteColumn.cfm @@ -1,44 +1,44 @@ -describe( "deleteColumn", function(){ +describe( "deleteColumn", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Deletes the data in a specified column", function(){ + it( "Deletes the data in a specified column", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "c" ], [ "", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "a,b" ) .addColumn( wb, "c,d" ) .deleteColumn( wb, 1 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Is chainable", function(){ + it( "Is chainable", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "c" ], [ "", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .addColumn( "a,b" ) .addColumn( "c,d" ) .deleteColumn( 1 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - describe( "deleteColumn throws an exception if" , function(){ + describe( "deleteColumn throws an exception if" , ()=>{ - it( "column is zero or less", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "column is zero or less", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.deleteColumn( workbook=wb, column=0 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidColumnArgument" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/deleteColumns.cfm b/test/specs/deleteColumns.cfm index 2bd6af5..ef52cb2 100644 --- a/test/specs/deleteColumns.cfm +++ b/test/specs/deleteColumns.cfm @@ -1,15 +1,15 @@ -describe( "deleteColumns", function(){ +describe( "deleteColumns", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Deletes the data in a specified range of columns", function(){ + it( "Deletes the data in a specified range of columns", ()=>{ var expected = querySim("column1,column2,column3,column4,column5 ||e||i ||f||j"); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "a,b" ) .addColumn( wb, "c,d" ) .addColumn( wb, "e,f" ) @@ -18,14 +18,14 @@ describe( "deleteColumns", function(){ .deleteColumns( wb, "1-2,4" ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Is chainable", function(){ + it( "Is chainable", ()=>{ var expected = querySim("column1,column2,column3,column4,column5 ||e||i ||f||j"); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .addColumn( "a,b" ) .addColumn( "c,d" ) @@ -35,20 +35,20 @@ describe( "deleteColumns", function(){ .deleteColumns( "1-2,4" ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - describe( "deleteColumns throws an exception if", function(){ + describe( "deleteColumns throws an exception if", ()=>{ - it( "the range is invalid", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the range is invalid", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.deleteColumns( wb, "a-b" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidRange" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/deleteRow.cfm b/test/specs/deleteRow.cfm index be904ec..872238c 100644 --- a/test/specs/deleteRow.cfm +++ b/test/specs/deleteRow.cfm @@ -1,44 +1,44 @@ -describe( "deleteRow", function(){ +describe( "deleteRow", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Deletes the data in a specified row", function(){ + it( "Deletes the data in a specified row", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "" ], [ "c", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, "a,b" ) .addRow( wb, "c,d" ) .deleteRow( wb, 1 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Is chainable", function(){ + it( "Is chainable", ()=>{ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "" ], [ "c", "d" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .addRow( "a,b" ) .addRow( "c,d" ) .deleteRow( 1 ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - describe( "deleteRow throws an exception if", function(){ + describe( "deleteRow throws an exception if", ()=>{ - it( "row is zero or less", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "row is zero or less", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.deleteRow( workbook=wb, row=0 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidRowArgument" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/deleteRows.cfm b/test/specs/deleteRows.cfm index 546b722..6e65c93 100644 --- a/test/specs/deleteRows.cfm +++ b/test/specs/deleteRows.cfm @@ -1,44 +1,44 @@ -describe( "deleteRows", function(){ +describe( "deleteRows", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Deletes the data in a specified range of rows", function(){ + it( "Deletes the data in a specified range of rows", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ], [ "d", "e" ], [ "f", "g" ], [ "h", "i" ] ] ); var expected = QueryNew( "column1,column2","VarChar,VarChar", [ [ "", "" ], [ "", "" ], [ "d", "e" ], [ "", "" ], [ "h", "i" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ) .deleteRows( wb, "1-2,4" ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Is chainable", function(){ + it( "Is chainable", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ], [ "d", "e" ], [ "f", "g" ], [ "h", "i" ] ] ); var expected = QueryNew( "column1,column2","VarChar,VarChar", [ [ "", "" ], [ "", "" ], [ "d", "e" ], [ "", "" ], [ "h", "i" ] ] ); - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .addRows( data ) .deleteRows( "1-2,4" ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - describe( "deleteRows throws an exception if", function(){ + describe( "deleteRows throws an exception if", ()=>{ - it( "the range is invalid", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the range is invalid", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.deleteRows( wb, "a-b" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidRange" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/formatCell.cfm b/test/specs/formatCell.cfm index 548fe6f..77c63aa 100644 --- a/test/specs/formatCell.cfm +++ b/test/specs/formatCell.cfm @@ -1,247 +1,247 @@ -describe( "formatCell", function(){ +describe( "formatCell", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ s.clearCellStyleCache(); variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( wb, [ "a1", "a2" ] ); - }); - }); + }) + }) setAndGetFormat = function( wb, format, overwriteCurrentStyle=true ){ s.formatCell( workbook=wb, format=format, row=1, column=1, overwriteCurrentStyle=overwriteCurrentStyle ); return s.getCellFormat( wb, 1, 1 ); }; - it( "can get the format of an unformatted cell", function(){ - workbooks.Each( function( wb ){ + it( "can get the format of an unformatted cell", ()=>{ + workbooks.Each( ( wb )=>{ expect( s.getCellFormat( wb, 1, 1 ) ).toBeTypeOf( "struct" ); - }); - }); + }) + }) - it( "formatCell and getCellFormat are chainable", function(){ + it( "formatCell and getCellFormat are chainable", ()=>{ var format = { bold: true }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = s.newChainable( wb ) .formatCell( format, 1, 1 ) .getCellFormat( 1, 1 ); expect( cellFormat.bold ).toBeTrue(); - }); - }); + }) + }) - it( "can set bold", function(){ + it( "can set bold", ()=>{ var format = { bold: true }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.bold ).toBeTrue(); - }); - }); + }) + }) - it( "can set the horizontal alignment", function(){ + it( "can set the horizontal alignment", ()=>{ var format = { alignment: "CENTER" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.alignment ).toBe( "CENTER" ); - }); - }); + }) + }) - it( "can set the bottomborder", function(){ + it( "can set the bottomborder", ()=>{ var format = { bottomborder: "THICK" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.bottomborder ).toBe( "THICK" ); - }); - }); + }) + }) - it( "can set the bottombordercolor", function(){ + it( "can set the bottombordercolor", ()=>{ var format = { bottombordercolor: "RED" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.bottombordercolor ).toBe( "255,0,0" ); - }); - }); + }) + }) - it( "can set the color", function(){ + it( "can set the color", ()=>{ var format = { color: "BLUE" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.color ).toBe( "0,0,255" ); - }); - }); + }) + }) - it( "can set the dataformat", function(){ + it( "can set the dataformat", ()=>{ var format = { dataformat: "@" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.dataformat ).toBe( "@" ); - }); - }); + }) + }) - it( "can set the fgcolor", function(){ + it( "can set the fgcolor", ()=>{ var format = { fgcolor: "GREEN" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.fgcolor ).toBe( "0,128,0" ); - }); - }); + }) + }) - it( "will ensure a fillpattern is specified when setting the fgcolor", function(){ + it( "will ensure a fillpattern is specified when setting the fgcolor", ()=>{ var format = { fgcolor: "GREEN" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.fgcolor ).toBe( "0,128,0" ); expect( cellFormat.fillpattern ).toBe( "SOLID_FOREGROUND" ); - }); - }); + }) + }) - it( "can set the fillpattern", function(){ + it( "can set the fillpattern", ()=>{ var format = { fillpattern: "BRICKS" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.fillpattern ).toBe( "BRICKS" ); - }); - }); + }) + }) - it( "can set the font", function(){ + it( "can set the font", ()=>{ var format = { font: "Helvetica" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.font ).toBe( "Helvetica" ); - }); - }); + }) + }) - it( "can set the fontsize", function(){ + it( "can set the fontsize", ()=>{ var format = { fontsize: 24 }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.fontsize ).toBe( 24 ); - }); - }); + }) + }) - it( "can set an indent of 15", function(){ + it( "can set an indent of 15", ()=>{ var format = { indent: 15 }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.indent ).toBe( 15 ); - }); - }); + }) + }) - it( "can set an indent of 15+ on XLSX", function(){ + it( "can set an indent of 15+ on XLSX", ()=>{ var format = { indent: 17 }; var xlsx = workbooks[ 2 ]; var cellFormat = setAndGetFormat( xlsx, format ); expect( cellFormat.indent ).toBe( 17 ); - }); + }) - it( "treats indents of 15+ as the maximum 15 on XLS", function(){ + it( "treats indents of 15+ as the maximum 15 on XLS", ()=>{ var format = { indent: 17 }; var xls = workbooks[ 1 ]; var cellFormat = setAndGetFormat( xls, format ); expect( cellFormat.indent ).toBe( 15 ); - }); + }) - it( "can set italic", function(){ + it( "can set italic", ()=>{ var format = { italic: true }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.italic ).toBeTrue(); - }); - }); + }) + }) - it( "can set the leftborder", function(){ + it( "can set the leftborder", ()=>{ var format = { leftborder: "THICK" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.leftborder ).toBe( "THICK" ); - }); - }); + }) + }) - it( "can set the leftbordercolor", function(){ + it( "can set the leftbordercolor", ()=>{ var format = { leftbordercolor: "RED" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.leftbordercolor ).toBe( "255,0,0" ); - }); - }); + }) + }) - it( "can set quoteprefixed", function(){ + it( "can set quoteprefixed", ()=>{ var formulaLikeString = "SUM(A2:A3)"; var format = { quoteprefixed: true }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, formulaLikeString, 1, 1 ); var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.quoteprefixed ).toBeTrue(); expect( s.getCellValue( wb, 1, 1 ) ).toBe( formulaLikeString ); - }); - }); + }) + }) - it( "can set the rightborder", function(){ + it( "can set the rightborder", ()=>{ var format = { rightborder: "THICK" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.rightborder ).toBe( "THICK" ); - }); - }); + }) + }) - it( "can set the rightbordercolor", function(){ + it( "can set the rightbordercolor", ()=>{ var format = { rightbordercolor: "RED" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.rightbordercolor ).toBe( "255,0,0" ); - }); - }); + }) + }) - it( "can set the rotation", function(){ + it( "can set the rotation", ()=>{ var format = { rotation: 90 }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.rotation ).toBe( 90 ); - }); - }); + }) + }) - it( "can set strikeout", function(){ + it( "can set strikeout", ()=>{ var format = { strikeout: true }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.strikeout ).toBeTrue(); - }); - }); + }) + }) - it( "can set textwrap", function(){ + it( "can set textwrap", ()=>{ var format = { textwrap: true }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.textwrap ).toBeTrue(); - }); - }); + }) + }) - it( "can set the topborder", function(){ + it( "can set the topborder", ()=>{ var format = { topborder: "THICK" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.topborder ).toBe( "THICK" ); - }); - }); + }) + }) - it( "can set the topbordercolor", function(){ + it( "can set the topbordercolor", ()=>{ var format = { topbordercolor: "RED" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.topbordercolor ).toBe( "255,0,0" ); - }); - }); + }) + }) - it( "can set the vertical alignment", function(){ + it( "can set the vertical alignment", ()=>{ var format = { verticalalignment: "CENTER" }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.verticalalignment ).toBe( "CENTER" ); - }); - }); + }) + }) - it( "can set underline as boolean", function(){ - workbooks.Each( function( wb ){ + it( "can set underline as boolean", ()=>{ + workbooks.Each( ( wb )=>{ s.formatCell( wb, { underline: true }, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "single" ); @@ -249,11 +249,11 @@ describe( "formatCell", function(){ s.formatCell( wb, { underline: false }, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "none" ); - }); - }); + }) + }) - it( "can set underline as 'single' or 'none'", function(){ - workbooks.Each( function( wb ){ + it( "can set underline as 'single' or 'none'", ()=>{ + workbooks.Each( ( wb )=>{ s.formatCell( wb, { underline: "single" }, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "single" ); @@ -261,53 +261,53 @@ describe( "formatCell", function(){ s.formatCell( wb, { underline: "none" }, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "none" ); - }); - }); + }) + }) - it( "can set underline as 'double'", function(){ - workbooks.Each( function( wb ){ + it( "can set underline as 'double'", ()=>{ + workbooks.Each( ( wb )=>{ s.formatCell( wb, { underline: "double" }, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "double" ); - }); - }); + }) + }) - it( "can set underline as 'single accounting'", function(){ - workbooks.Each( function( wb ){ + it( "can set underline as 'single accounting'", ()=>{ + workbooks.Each( ( wb )=>{ s.formatCell( wb, { underline: "single accounting" }, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "single accounting" ); - }); - }); + }) + }) - it( "can set underline as 'double accounting'", function(){ - workbooks.Each( function( wb ){ + it( "can set underline as 'double accounting'", ()=>{ + workbooks.Each( ( wb )=>{ s.formatCell( wb, { underline: "double accounting" }, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "double accounting" ); - }); - }); + }) + }) - it( "ignores an invalid underline value", function(){ - workbooks.Each( function( wb ){ + it( "ignores an invalid underline value", ()=>{ + workbooks.Each( ( wb )=>{ s.formatCell( wb, { underline: "blah" }, 1, 1 ); var cellFormat = s.getCellFormat( wb, 1, 1 ); expect( cellFormat.underline ).toBe( "none" ); - }); - }); + }) + }) - it( "will map 9 deprecated colour names ending in 1 to the corresponding valid value", function(){ - workbooks.Each( function( wb ){ + it( "will map 9 deprecated colour names ending in 1 to the corresponding valid value", ()=>{ + workbooks.Each( ( wb )=>{ // include numbers either side of 127 which might throw ACF var deprecatedName = "RED1"; var format = { color: deprecatedName, bottombordercolor: deprecatedName }; var cellFormat = setAndGetFormat( wb, format ); expect( cellFormat.color ).toBe( "255,0,0" ); //font color expect( cellFormat.bottombordercolor ).toBe( "255,0,0" ); //style color - }); - }); + }) + }) - it( "can set a non preset RGB triplet color on an XLSX workbook cell", function(){ + it( "can set a non preset RGB triplet color on an XLSX workbook cell", ()=>{ var xlsx = workbooks[ 2 ]; // include numbers either side of 127 which might throw ACF var triplet = "64,255,128"; @@ -315,9 +315,9 @@ describe( "formatCell", function(){ var cellFormat = setAndGetFormat( xlsx, format ); expect( cellFormat.color ).toBe( triplet ); //font color expect( cellFormat.bottombordercolor ).toBe( triplet ); //style color - }); + }) - it( "can set a non preset Hex color value on an XLSX workbook cell", function(){ + it( "can set a non preset Hex color value on an XLSX workbook cell", ()=>{ var xlsx = workbooks[ 2 ]; var hex = "FFFFFF"; var triplet = "255,255,255"; @@ -332,10 +332,10 @@ describe( "formatCell", function(){ var cellFormat = setAndGetFormat( xlsx, format ); expect( cellFormat.color ).toBe( triplet ); //font color expect( cellFormat.bottombordercolor ).toBe( triplet ); //style color - }); + }) - it( "can preserve the existing font properties and not affect other cells", function(){ - workbooks.Each( function( wb ){ + it( "can preserve the existing font properties and not affect other cells", ()=>{ + workbooks.Each( ( wb )=>{ var cellA2originalFormat = s.getCellFormat( wb, 2, 1 ); var format = { font: "Helvetica" }; setAndGetFormat( wb, format, false ); @@ -362,11 +362,11 @@ describe( "formatCell", function(){ cellFormat = setAndGetFormat( wb, format, false ); expect( cellFormat.font ).toBe( "Courier New" ); expect( cellFormat.fontsize ).toBe( 24 ); - }); - }); + }) + }) - it( "allows styles to be set using a pre-built cellStyle object", function(){ - workbooks.Each( function( wb ){ + it( "allows styles to be set using a pre-built cellStyle object", ()=>{ + workbooks.Each( ( wb )=>{ expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeFalse(); var cellStyle = s.createCellStyle( wb, { bold: true } ); // format argument may be a cellStyle object instead of a struct @@ -376,13 +376,13 @@ describe( "formatCell", function(){ expect( s.getCellFormat( wb, 2, 1 ).bold ).toBeFalse(); s.formatCell( workbook=wb, row=2, column=1, cellStyle=cellStyle ); expect( s.getCellFormat( wb, 2, 1 ).bold ).toBeTrue(); - }); - }); + }) + }) - it( "caches and re-uses indentical formats passed as a struct over the life of the library to avoid cell style duplication", function(){ + it( "caches and re-uses indentical formats passed as a struct over the life of the library to avoid cell style duplication", ()=>{ variables.data = [ [ "x", "y" ] ]; variables.format = { bold: true }; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); var expected = s.isXmlFormat( wb )? 1: 21; expect( s.getWorkbookCellStylesTotal( wb ) ).toBe( expected ); @@ -391,39 +391,39 @@ describe( "formatCell", function(){ } expected = s.isXmlFormat( wb )? 2: 22; expect( s.getWorkbookCellStylesTotal( wb ) ).toBe( expected ); - }); - }); + }) + }) - describe( "formatCell throws an exception if", function(){ + describe( "formatCell throws an exception if", ()=>{ - it( "neither a format struct nor a cellStyle are passed", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "neither a format struct nor a cellStyle are passed", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.formatCell( workbook=wb, row=1, column=1 ); }).toThrow( type="cfsimplicity.spreadsheet.missingRequiredArgument" ); - }); - }); + }) + }) - it( "an invalid hex value is passed", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "an invalid hex value is passed", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var hex = "GGHHII"; var format = { color: hex, bottombordercolor: hex }; var cellFormat = setAndGetFormat( wb, format ); }).toThrow( type="cfsimplicity.spreadsheet.invalidColor" ); - }); - }); + }) + }) - it( "a cellStyle object is passed with the overwriteCurrentStyle flag set to false", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "a cellStyle object is passed with the overwriteCurrentStyle flag set to false", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var cellStyle = s.createCellStyle( wb, { bold: true } ); s.formatCell( workbook=wb, format=cellStyle, row=1, column=1, overwriteCurrentStyle=false ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArgumentCombination" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/formatCellRange.cfm b/test/specs/formatCellRange.cfm index 72d8b25..2243147 100644 --- a/test/specs/formatCellRange.cfm +++ b/test/specs/formatCellRange.cfm @@ -1,16 +1,16 @@ -describe( "formatCellRange", function(){ +describe( "formatCellRange", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ s.clearCellStyleCache(); variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, [ [ "a1", "b1" ], [ "a2", "b2" ] ] ); - }); - }); + }) + }) - it( "can preserve the existing format properties other than the one(s) being changed", function(){ - workbooks.Each( function( wb ){ + it( "can preserve the existing format properties other than the one(s) being changed", ()=>{ + workbooks.Each( ( wb )=>{ s.formatCellRange( wb, { italic: true }, 1, 2, 1, 2 ); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); s.formatCellRange( wb, { bold: true }, 1, 2, 1, 2 ); //overwrites current style style by default @@ -19,11 +19,11 @@ describe( "formatCellRange", function(){ .formatCellRange( workbook=wb, format={ bold: true }, startRow=1, endRow=2, startColumn=1, endColumn=2, overwriteCurrentStyle=false ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); - }); - }); + }) + }) - it( "allows styles to be set using a pre-built cellStyle object", function(){ - workbooks.Each( function( wb ){ + it( "allows styles to be set using a pre-built cellStyle object", ()=>{ + workbooks.Each( ( wb )=>{ expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeFalse(); var cellStyle = s.createCellStyle( wb, { bold: true } ); s.formatCellRange( wb, cellStyle, 1, 2, 1, 2 ); @@ -33,17 +33,17 @@ describe( "formatCellRange", function(){ expect( s.getCellFormat( wb, 2, 1 ).italic ).toBeFalse(); s.formatCellRange( workbook=wb, startRow=1, endRow=2, startColumn=1, endColumn=2, cellStyle=cellStyle ); expect( s.getCellFormat( wb, 2, 1 ).italic ).toBeTrue(); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .formatCellRange( { bold: true }, 1, 2, 1, 2 ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 2, 2 ).bold ).toBeTrue(); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/formatColumn.cfm b/test/specs/formatColumn.cfm index 5ca17cf..5226f40 100644 --- a/test/specs/formatColumn.cfm +++ b/test/specs/formatColumn.cfm @@ -1,17 +1,17 @@ -describe( "formatColumn", function(){ +describe( "formatColumn", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ s.clearCellStyleCache(); variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( wb, [ "a1", "a2" ] ); - }); - }); + }) + }) it( title="can format a column containing more than 4009 rows", - body=function(){ + body=()=>{ var path = getTestFilePath( "4010-rows.xls" ); var workbook = s.read( src=path ); var format = { italic: "true" }; @@ -20,8 +20,8 @@ describe( "formatColumn", function(){ skip=s.getIsACF() ); - it( "can preserve the existing format properties other than the one(s) being changed", function(){ - workbooks.Each( function( wb ){ + it( "can preserve the existing format properties other than the one(s) being changed", ()=>{ + workbooks.Each( ( wb )=>{ s.formatColumn( wb, { italic: true }, 1 ); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); s.formatColumn( wb, { bold: true }, 1 ); //overwrites current style style by default @@ -30,31 +30,31 @@ describe( "formatColumn", function(){ .formatColumn( workbook=wb, format={ bold: true }, column=1, overwriteCurrentStyle=false ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .formatColumn( { bold: true }, 1 ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 2, 1 ).bold ).toBeTrue(); - }); - }); + }) + }) - describe( "formatColumn throws an exception if", function(){ + describe( "formatColumn throws an exception if", ()=>{ - it( "the column is 0 or below", function(){ + it( "the column is 0 or below", ()=>{ var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ - expect( function(){ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var format = { italic="true" }; s.formatColumn( wb, format,0 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidColumnArgument" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/formatColumns.cfm b/test/specs/formatColumns.cfm index b2a0068..65aa0fd 100644 --- a/test/specs/formatColumns.cfm +++ b/test/specs/formatColumns.cfm @@ -1,13 +1,13 @@ -describe( "formatColumns", function(){ +describe( "formatColumns", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ s.clearCellStyleCache(); variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, [ [ "a1", "b1" ], [ "a2", "b2" ] ] ); - }); - }); + }) + }) it( title="can format columns in a spreadsheet containing more than 4009 rows", @@ -20,8 +20,8 @@ describe( "formatColumns", function(){ skip=s.getIsACF() ); - it( "can preserve the existing format properties other than the one(s) being changed", function(){ - workbooks.Each( function( wb ){ + it( "can preserve the existing format properties other than the one(s) being changed", ()=>{ + workbooks.Each( ( wb )=>{ s.formatColumns( wb, { italic: true }, "1-2" ); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); s.formatColumns( wb, { bold: true }, "1-2" ); //overwrites current style style by default @@ -30,38 +30,38 @@ describe( "formatColumns", function(){ .formatColumns( workbook=wb, format={ bold: true }, range="1-2", overwriteCurrentStyle=false ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .formatColumns( { bold: true }, "1-2" ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 1, 2 ).bold ).toBeTrue(); - }); - }); + }) + }) - it( "works when the range is just a single column", function(){ - workbooks.Each( function( wb ){ + it( "works when the range is just a single column", ()=>{ + workbooks.Each( ( wb )=>{ s.formatColumns( wb, { italic: true }, "2" ); expect( s.getCellFormat( wb, 2, 2 ).italic ).toBeTrue(); - }); - }); + }) + }) - describe( "formatColumns throws an exception if ", function(){ + describe( "formatColumns throws an exception if ", ()=>{ - it( "the range is invalid", function(){ + it( "the range is invalid", ()=>{ var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ - expect( function(){ + workbooks.Each( ( wb )=>{ + expect( ()=>{ format = { font: "Courier" }; s.formatColumns( wb, format, "a-b" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidRange" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/formatRow.cfm b/test/specs/formatRow.cfm index 53311df..466c649 100644 --- a/test/specs/formatRow.cfm +++ b/test/specs/formatRow.cfm @@ -1,16 +1,16 @@ -describe( "formatRow", function(){ +describe( "formatRow", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ s.clearCellStyleCache(); variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, [ "a1", "b1" ] ); - }); - }); + }) + }) - it( "can preserve the existing format properties other than the one(s) being changed", function(){ - workbooks.Each( function( wb ){ + it( "can preserve the existing format properties other than the one(s) being changed", ()=>{ + workbooks.Each( ( wb )=>{ s.formatRow( wb, { italic: true }, 1 ); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); s.formatRow( wb, { bold: true }, 1 ); //overwrites current style style by default @@ -19,17 +19,17 @@ describe( "formatRow", function(){ .formatRow( workbook=wb, format={ bold: true }, row=1, overwriteCurrentStyle=false ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); - }); - }); + }) + }) - it( "is chainable", function() { - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .formatRow( { bold: true }, 1 ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 1, 2 ).bold ).toBeTrue(); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/formatRows.cfm b/test/specs/formatRows.cfm index bca2c09..67ded8b 100644 --- a/test/specs/formatRows.cfm +++ b/test/specs/formatRows.cfm @@ -1,16 +1,16 @@ -describe( "formatRows", function(){ +describe( "formatRows", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ s.clearCellStyleCache(); variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, [ [ "a1", "b1" ], [ "a2", "b2" ] ] ); - }); - }); + }) + }) - it( "can preserve the existing format properties other than the one(s) being changed", function(){ - workbooks.Each( function( wb ){ + it( "can preserve the existing format properties other than the one(s) being changed", ()=>{ + workbooks.Each( ( wb )=>{ s.formatRows( wb, { italic: true }, "1-2" ); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); s.formatRows( wb, { bold: true }, "1-2" ); //overwrites current style style by default @@ -19,38 +19,38 @@ describe( "formatRows", function(){ .formatRows( workbook=wb, format={ bold: true }, range="1-2", overwriteCurrentStyle=false ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 1, 1 ).italic ).toBeTrue(); - }); - }); + }) + }) - it( "is chainable", function() { - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .formatRows( { bold: true }, "1-2" ); expect( s.getCellFormat( wb, 1, 1 ).bold ).toBeTrue(); expect( s.getCellFormat( wb, 2, 2 ).bold ).toBeTrue(); - }); - }); + }) + }) - it( "works when the range is just a single row", function(){ - workbooks.Each( function( wb ){ + it( "works when the range is just a single row", ()=>{ + workbooks.Each( ( wb )=>{ s.formatRows( wb, { italic: true }, "2" ); expect( s.getCellFormat( wb, 2, 2 ).italic ).toBeTrue(); - }); - }); + }) + }) - describe( "formatRows throws an exception if", function(){ + describe( "formatRows throws an exception if", ()=>{ - it( "the range is invalid", function(){ + it( "the range is invalid", ()=>{ var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ - expect( function(){ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var format = { font: "Courier" }; s.formatRows( wb, format, "a-b" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidRange" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/getCellAddress.cfm b/test/specs/getCellAddress.cfm index ffd41b0..f809642 100644 --- a/test/specs/getCellAddress.cfm +++ b/test/specs/getCellAddress.cfm @@ -1,37 +1,37 @@ -describe( "getCellAddress", function(){ +describe( "getCellAddress", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Gets the alphanumeric address reference of a given cell", function(){ - workbooks.Each( function( wb ){ + it( "Gets the alphanumeric address reference of a given cell", ()=>{ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, "test", 1, 1 ); expect( s.getCellAddress( wb, 1, 1 ) ).toBe( "A1" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var result = s.newChainable( wb ) .setCellValue( "test", 1, 1 ) .getCellAddress( 1, 1 ); expect( result ).toBe( "A1" ); - }); - }); + }) + }) - describe( "getCellAddress throws an exception if", function(){ + describe( "getCellAddress throws an exception if", ()=>{ - it( "the cell doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the cell doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var result = s.getCellAddress( wb, 1, 1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidCell" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/getCellType.cfm b/test/specs/getCellType.cfm index e57cacc..e8f3eac 100644 --- a/test/specs/getCellType.cfm +++ b/test/specs/getCellType.cfm @@ -1,12 +1,12 @@ -describe( "getCellType", function(){ +describe( "getCellType", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Gets the Excel data type of a cell in the active sheet", function(){ - workbooks.Each( function( wb ){ + it( "Gets the Excel data type of a cell in the active sheet", ()=>{ + workbooks.Each( ( wb )=>{ s.setCellValue( wb, "test", 1, 1 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "string" ); s.setCellValue( wb, 1, 1, 1 ); @@ -19,17 +19,17 @@ describe( "getCellType", function(){ expect( s.getCellType( wb, 1, 1 ) ).toBe( "blank" ); s.setCellFormula( wb, "SUM(A1:A2)", 1, 1 ); expect( s.getCellType( wb, 1, 1 ) ).toBe( "formula" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var type = s.newChainable( wb ) .setCellValue( "true", 1, 1, "boolean" ) .getCellType( 1, 1 ); expect( type ).toBe( "boolean" ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/getColumnCount.cfm b/test/specs/getColumnCount.cfm index 08a8b6e..ec88a02 100644 --- a/test/specs/getColumnCount.cfm +++ b/test/specs/getColumnCount.cfm @@ -1,30 +1,30 @@ -describe( "getColumnCount", function(){ +describe( "getColumnCount", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Can get the maximum number of columns in the first sheet", function(){ - workbooks.Each( function( wb ){ + it( "Can get the maximum number of columns in the first sheet", ()=>{ + workbooks.Each( ( wb )=>{ s.addRow( wb, "1a,1b" ) .addRow( wb, "2a,2b,2c" ) .addRow( wb, "3a" ); expect( s.getColumnCount( wb ) ).toBe( 3 ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var count = s.newChainable( wb ) .addRow( [ "a", "b", "c" ] ) .getColumnCount(); expect( count ).toBe( 3 ); - }); - }); + }) + }) - it( "Can get the maximum number of columns of a sheet specified by number", function(){ - workbooks.Each( function( wb ){ + it( "Can get the maximum number of columns of a sheet specified by number", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb )//add a second sheet and switch to it .setActiveSheetNumber( wb, 2 ) .addRow( wb, "1a,1b" ) @@ -33,11 +33,11 @@ describe( "getColumnCount", function(){ .setActiveSheetNumber( wb, 1 );//switch back to sheet 1 expect( s.getColumnCount( wb ) ).toBe( 0 ); expect( s.getColumnCount( wb, 2 ) ).toBe( 3 ); - }); - }); + }) + }) - it( "Can get the maximum number of columns of a sheet specified by name", function(){ - workbooks.Each( function( wb ){ + it( "Can get the maximum number of columns of a sheet specified by name", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .setActiveSheetNumber( wb, 2 ) .addRow( wb, "1a,1b" ) @@ -46,25 +46,25 @@ describe( "getColumnCount", function(){ .setActiveSheetNumber( wb, 1 ); expect( s.getColumnCount( wb ) ).toBe( 0 ); expect( s.getColumnCount( wb, "test" ) ).toBe( 3 ); - }); - }); + }) + }) - describe( "getColumnCount throws an exception if", function(){ + describe( "getColumnCount throws an exception if", ()=>{ - it( "the sheet name or number doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet name or number doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var result=s.getColumnCount( wb, 2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - }); - workbooks.Each( function( wb ){ - expect( function(){ + }) + workbooks.Each( ( wb )=>{ + expect( ()=>{ var result=s.getColumnCount( wb, "test" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/getEnvironment.cfm b/test/specs/getEnvironment.cfm index e71a3c3..b694048 100644 --- a/test/specs/getEnvironment.cfm +++ b/test/specs/getEnvironment.cfm @@ -1,7 +1,7 @@ -describe( "getEnvironment", function(){ +describe( "getEnvironment", ()=>{ - it( "returns a struct with the expected keys", function() { + it( "returns a struct with the expected keys", ()=>{ var expectedKeys = [ "dateFormats" ,"engine" @@ -18,7 +18,7 @@ describe( "getEnvironment", function(){ for( var key in expectedKeys ){ expect( actual ).toHaveKey( key ); } - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/getPresetColorNames.cfm b/test/specs/getPresetColorNames.cfm index ee1f2eb..7a3b7a8 100644 --- a/test/specs/getPresetColorNames.cfm +++ b/test/specs/getPresetColorNames.cfm @@ -1,11 +1,11 @@ -describe( "getPresetColorNames", function(){ +describe( "getPresetColorNames", ()=>{ - it( "returns an alphabetical array of preset color names available for use in color formatting options", function(){ + it( "returns an alphabetical array of preset color names available for use in color formatting options", ()=>{ expect( s.getPresetColorNames() ).toHaveLength( 48 ); expect( s.getPresetColorNames()[ 1 ] ).toBe( "AQUA" ); expect( s.getPresetColorNames()[ 48 ] ).toBe( "YELLOW" ); - }); + }) -}); +}); \ No newline at end of file diff --git a/test/specs/getRowCount.cfm b/test/specs/getRowCount.cfm index 19aaba3..bd1866f 100644 --- a/test/specs/getRowCount.cfm +++ b/test/specs/getRowCount.cfm @@ -1,13 +1,13 @@ -describe( "getRowCount/getLastRowNumber", function(){ +describe( "getRowCount/getLastRowNumber", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; variables.rowData = QueryNew( "column1,", "VarChar", [ [ "a" ], [ "c" ] ] ); - }); + }) - it( "Can get the number of rows in the first sheet", function(){ - workbooks.Each( function( wb ){ + it( "Can get the number of rows in the first sheet", ()=>{ + workbooks.Each( ( wb )=>{ expect( s.getRowCount( wb ) ).toBe( 0 );// empty expect( s.getLastRowNumber( wb ) ).toBe( 0 );// empty s.addRow( wb, "A1" ); @@ -16,33 +16,33 @@ describe( "getRowCount/getLastRowNumber", function(){ s.addRow( wb, "B1" ); expect( s.getRowCount( wb ) ).toBe( 2 ); expect( s.getLastRowNumber( wb ) ).toBe( 2 ); - }); - }); + }) + }) - it( "Are chainable", function(){ - workbooks.Each( function( wb ){ + it( "Are chainable", ()=>{ + workbooks.Each( ( wb )=>{ var count = s.newChainable( wb ) .addRow( "A1" ) .getRowCount(); expect( count ).toBe( 1 ); var lastRowNum = s.newChainable( wb ).getLastRowNumber(); expect( lastRowNum ).toBe( 1 ); - }); - }); + }) + }) - it( "Will include empty/blank rows", function(){ - workbooks.Each( function( wb ){ + it( "Will include empty/blank rows", ()=>{ + workbooks.Each( ( wb )=>{ s.addRow( wb, "B1", 2 ); expect( s.getRowCount( wb ) ).toBe( 2 ); expect( s.getLastRowNumber( wb ) ).toBe( 2 ); s.addRow( wb, "" ); expect( s.getRowCount( wb ) ).toBe( 3 ); expect( s.getLastRowNumber( wb ) ).toBe( 3 ); - }); - }); + }) + }) - it( "Can get the number of rows of a sheet specified by number", function(){ - workbooks.Each( function( wb ){ + it( "Can get the number of rows of a sheet specified by number", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb )//add a second sheet and switch to it .setActiveSheetNumber( wb, 2 ) .addRow( wb, "S2A1" ) @@ -53,11 +53,11 @@ describe( "getRowCount/getLastRowNumber", function(){ expect( s.getLastRowNumber( wb ) ).toBe( 1 ); expect( s.getRowCount( wb, 2 ) ).toBe( 2 ); expect( s.getLastRowNumber( wb, 2 ) ).toBe( 2 ); - }); - }); + }) + }) - it( "Can get the number of rows of a sheet specified by name", function(){ - workbooks.Each( function( wb ){ + it( "Can get the number of rows of a sheet specified by name", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" )//add a second sheet and switch to it .setActiveSheetNumber( wb, 2 ) .addRow( wb, "S2A1" ) @@ -68,32 +68,32 @@ describe( "getRowCount/getLastRowNumber", function(){ expect( s.getLastRowNumber( wb ) ).toBe( 1 ); expect( s.getRowCount( wb, "test" ) ).toBe( 2 ); expect( s.getLastRowNumber( wb, "test" ) ).toBe( 2 ); - }); - }); + }) + }) - describe( "getRowCount throws an exception if", function(){ + describe( "getRowCount throws an exception if", ()=>{ - it( "the sheet name or number doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet name or number doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ var result = s.getRowCount( wb, 2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - expect( function(){ + expect( ()=>{ var result = s.getLastRowNumber( wb, 2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - }); - workbooks.Each( function( wb ){ - expect( function(){ + }) + workbooks.Each( ( wb )=>{ + expect( ()=>{ var result = s.getRowCount( wb, "test" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - expect( function(){ + expect( ()=>{ var result = s.getLastRowNumber( wb, "test" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/hideColumn.cfm b/test/specs/hideColumn.cfm index f729e0a..267e27c 100644 --- a/test/specs/hideColumn.cfm +++ b/test/specs/hideColumn.cfm @@ -1,26 +1,26 @@ -describe( "hideColumn", function(){ +describe( "hideColumn", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var query = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var xls = s.workbookFromQuery( query ); var xlsx = s.workbookFromQuery( data=query, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "can hide a column", function(){ - workbooks.Each( function( wb ){ + it( "can hide a column", ()=>{ + workbooks.Each( ( wb )=>{ s.hideColumn( wb, 1 ); expect( s.isColumnHidden( wb, 1 ) ).toBeTrue(); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).hideColumn( 1 ); expect( s.isColumnHidden( wb, 1 ) ).toBeTrue(); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/hideRow.cfm b/test/specs/hideRow.cfm index 4d9987f..3cf98f1 100644 --- a/test/specs/hideRow.cfm +++ b/test/specs/hideRow.cfm @@ -1,26 +1,26 @@ -describe( "hideRow", function(){ +describe( "hideRow", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var query = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var xls = s.workbookFromQuery( query ); var xlsx = s.workbookFromQuery( data=query, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "can hide a row", function(){ - workbooks.Each( function( wb ){ + it( "can hide a row", ()=>{ + workbooks.Each( ( wb )=>{ s.hideRow( wb, 1 ); expect( s.isRowHidden( wb, 1 ) ).toBeTrue(); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).hideRow( 1 ); expect( s.isRowHidden( wb, 1 ) ).toBeTrue(); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/info.cfm b/test/specs/info.cfm index fd4ce6f..f64d156 100644 --- a/test/specs/info.cfm +++ b/test/specs/info.cfm @@ -1,7 +1,7 @@ -describe( "info", function(){ +describe( "info", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.infoToAdd = { author: "Bob" ,category: "Testing" @@ -24,10 +24,10 @@ describe( "info", function(){ variables.infoToBeReturned = Duplicate( infoToAdd ); StructAppend( infoToBeReturned, additional ); variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Adds and can get back info", function(){ - workbooks.Each( function( wb ){ + it( "Adds and can get back info", ()=>{ + workbooks.Each( ( wb )=>{ s.addInfo( wb, infoToAdd ); if( s.isXmlFormat( wb ) ) infoToBeReturned.spreadSheetType = "Excel (2007)"; @@ -35,10 +35,10 @@ describe( "info", function(){ var actual = s.info( wb ); actual.creationDate = DateFormat( Now(), "yyyymmdd" );// Doesn't return this value so mock expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Handles missing lastAuthor value in an xlsx", function(){ + it( "Handles missing lastAuthor value in an xlsx", ()=>{ infoToAdd.delete( "lastAuthor" ); infoToBeReturned.delete( "lastAuthor" ); var workbook = workbooks[ 2 ]; @@ -48,10 +48,10 @@ describe( "info", function(){ var actual = s.info( workbook ); actual.creationDate = DateFormat( actual.creationDate, "yyyymmdd" ); // Doesn't return this value so mock expect( actual ).toBe( expected ); - }); + }) - it( "Can accept a file path instead of a workbook", function(){ - workbooks.Each( function( wb ){ + it( "Can accept a file path instead of a workbook", ()=>{ + workbooks.Each( ( wb )=>{ if( s.isXmlFormat( wb ) ) infoToBeReturned.spreadSheetType = "Excel (2007)"; var tempPath = s.isXmlFormat( wb )? tempXlsxPath: tempXlsPath; @@ -61,11 +61,11 @@ describe( "info", function(){ var actual = s.info( tempPath ); actual.creationDate = DateFormat( Now(), "yyyymmdd" );// Doesn't return this value so mock expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "addInfo and info are chainable", function(){ - workbooks.Each( function( wb ){ + it( "addInfo and info are chainable", ()=>{ + workbooks.Each( ( wb )=>{ var actual = s.newChainable( wb ) .addInfo( infoToAdd ) .info(); @@ -74,15 +74,15 @@ describe( "info", function(){ var expected = infoToBeReturned; actual.creationDate = DateFormat( Now(), "yyyymmdd" );// Doesn't return this value so mock expect( actual ).toBe( expected ); - }); - }); + }) + }) - afterEach( function(){ + afterEach( ()=>{ if( FileExists( variables.tempXlsPath ) ) FileDelete( variables.tempXlsPath ); if( FileExists( variables.tempXlsxPath ) ) FileDelete( variables.tempXlsxPath ); - }); + }) -}); +}) diff --git a/test/specs/isSpreadsheetFile.cfm b/test/specs/isSpreadsheetFile.cfm index 649b852..8376ac4 100644 --- a/test/specs/isSpreadsheetFile.cfm +++ b/test/specs/isSpreadsheetFile.cfm @@ -1,38 +1,38 @@ -describe( "isSpreadsheetFile", function(){ +describe( "isSpreadsheetFile", ()=>{ - it( "reports false for a non-spreadsheet file", function(){ + it( "reports false for a non-spreadsheet file", ()=>{ var path = getTestFilePath( "notaspreadsheet.txt" ); expect( s.isSpreadsheetFile( path ) ).toBeFalse(); - }); + }) - it( "reports true for a binary spreadsheet file", function(){ + it( "reports true for a binary spreadsheet file", ()=>{ var path = getTestFilePath( "test.xls" ); expect( s.isSpreadsheetFile( path ) ).toBeTrue(); - }); + }) - it( "reports true for an xml spreadsheet file", function(){ + it( "reports true for an xml spreadsheet file", ()=>{ var path = getTestFilePath( "test.xlsx" ); expect( s.isSpreadsheetFile( path ) ).toBeTrue(); - }); + }) - describe( "isSpreadsheetFile throws an exception if", function(){ + describe( "isSpreadsheetFile throws an exception if", ()=>{ - it( "the file doesn't exist", function(){ - expect( function(){ + it( "the file doesn't exist", ()=>{ + expect( ()=>{ var path = getTestFilePath( "nonexistent.xls" ); s.isSpreadsheetFile( path ); }).toThrow( type="cfsimplicity.spreadsheet.nonExistentFile" ); - }); + }) - it( "the source file is in an old format not supported by POI", function(){ - expect( function(){ + it( "the source file is in an old format not supported by POI", ()=>{ + expect( ()=>{ var path = getTestFilePath( "oldformat.xls" ); s.isSpreadsheetFile( path ); }).toThrow( type="cfsimplicity.spreadsheet.oldExcelFormatException" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/isSpreadsheetObject.cfm b/test/specs/isSpreadsheetObject.cfm index 1e58c04..e8f55df 100644 --- a/test/specs/isSpreadsheetObject.cfm +++ b/test/specs/isSpreadsheetObject.cfm @@ -1,22 +1,22 @@ -describe( "isSpreadsheetObject", function(){ +describe( "isSpreadsheetObject", ()=>{ - it( "reports false for a variable which is not a spreadsheet object", function(){ + it( "reports false for a variable which is not a spreadsheet object", ()=>{ var objectToTest = "a string"; expect( s.isSpreadsheetObject( objectToTest ) ).toBeFalse(); - }); + }) - it( "reports true for a binary spreadsheet object", function(){ + it( "reports true for a binary spreadsheet object", ()=>{ var path = getTestFilePath( "test.xls" ); var objectToTest = s.read( path ); expect( s.isSpreadsheetObject( objectToTest ) ).toBeTrue(); - }); + }) - it( "reports true for an xml spreadsheet object", function(){ + it( "reports true for an xml spreadsheet object", ()=>{ var path = getTestFilePath( "test.xlsx" ); var objectToTest = s.read( path ); expect( s.isSpreadsheetObject( objectToTest ) ).toBeTrue(); - }); + }) -}); +}) diff --git a/test/specs/isXmlOrBinaryFormat.cfm b/test/specs/isXmlOrBinaryFormat.cfm index d1ad812..d23b401 100644 --- a/test/specs/isXmlOrBinaryFormat.cfm +++ b/test/specs/isXmlOrBinaryFormat.cfm @@ -1,28 +1,28 @@ -describe( "isXmlOrBinaryFormat", function(){ +describe( "isXmlOrBinaryFormat", ()=>{ - it( "Reports a binary file's format correctly", function(){ + it( "Reports a binary file's format correctly", ()=>{ var path = getTestFilePath( "test.xls" );//binary file var workbook = s.read( src=path ); expect( s.isBinaryFormat( workbook ) ).toBeTrue(); expect( s.isXmlFormat( workbook ) ).toBeFalse(); expect( s.isStreamingXmlFormat( workbook ) ).toBeFalse(); - }); + }) - it( "Reports an XML file's format correctly", function(){ + it( "Reports an XML file's format correctly", ()=>{ var path = getTestFilePath( "test.xlsx" );//binary file var workbook = s.read( src=path ); expect( s.isXmlFormat( workbook ) ).toBeTrue(); expect( s.isBinaryFormat( workbook ) ).toBeFalse(); expect( s.isStreamingXmlFormat( workbook ) ).toBeFalse(); - }); + }) - it( "Reports a streaming XML file's format correctly", function(){ + it( "Reports a streaming XML file's format correctly", ()=>{ var workbook = s.newStreamingXlsx(); expect( s.isStreamingXmlFormat( workbook ) ).toBeTrue(); expect( s.isXmlFormat( workbook ) ).toBeTrue(); expect( s.isBinaryFormat( workbook ) ).toBeFalse(); - }); + }) -}); +}) diff --git a/test/specs/javaClassLoading.cfm b/test/specs/javaClassLoading.cfm index 8d4d2e5..5cafd8a 100644 --- a/test/specs/javaClassLoading.cfm +++ b/test/specs/javaClassLoading.cfm @@ -1,7 +1,7 @@ -describe( "java class loading", function(){ +describe( "java class loading", ()=>{ - it( "defaults to the appropriate method for the engine", function() { + it( "defaults to the appropriate method for the engine", ()=>{ s.getPoiVersion(); //defaults if( s.getIsACF() ){ @@ -12,9 +12,9 @@ describe( "java class loading", function(){ expect( s.getLoadJavaClassesUsing() ).toBe( "osgi" ); expect( s.getJavaClassesLastLoadedVia() ).toBe( "OSGi bundle" ); } - }); + }) - it( "can be configured at instance level", function() { + it( "can be configured at instance level", ()=>{ local.s = newSpreadsheetInstance( loadJavaClassesUsing="dynamicPath" ); expect( local.s.getLoadJavaClassesUsing() ).toBe( "dynamicPath" ); if( s.getIsLucee() ){ @@ -24,13 +24,13 @@ describe( "java class loading", function(){ local.s.getPoiVersion(); expect( local.s.getJavaClassesLastLoadedVia() ).toBe( "JavaLoader" ); } - }); + }) - it( "throws an exception if an invalid loading method is specified", function() { - expect( function(){ + it( "throws an exception if an invalid loading method is specified", ()=>{ + expect( ()=>{ local.s = newSpreadsheetInstance( loadJavaClassesUsing="invalid" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidJavaLoadingMethod" ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/mergeCells.cfm b/test/specs/mergeCells.cfm index 2ed5ccf..5c6b28a 100644 --- a/test/specs/mergeCells.cfm +++ b/test/specs/mergeCells.cfm @@ -1,7 +1,7 @@ -describe( "mergeCells", function(){ +describe( "mergeCells", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var data = querySim( "column1,column2 a|b @@ -9,63 +9,63 @@ describe( "mergeCells", function(){ var xls = s.workbookFromQuery( data, false ); var xlsx = s.workbookFromQuery( data=data, addHeaderRow=false, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "Retains merged cell data by default", function(){ - workbooks.Each( function( wb ){ + it( "Retains merged cell data by default", ()=>{ + workbooks.Each( ( wb )=>{ s.mergeCells( wb, 1, 2, 1, 2 ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( "a" ); expect( s.getCellValue( wb, 1, 2 ) ).toBe( "b" ); expect( s.getCellValue( wb, 2, 1 ) ).toBe( "c" ); expect( s.getCellValue( wb, 2, 2 ) ).toBe( "d" ); - }); - }); + }) + }) - it( "Can empty all but the top-left-most cell of a merged region", function(){ - workbooks.Each( function( wb ){ + it( "Can empty all but the top-left-most cell of a merged region", ()=>{ + workbooks.Each( ( wb )=>{ s.mergeCells( wb, 1, 2, 1, 2, true ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( "a" ); expect( s.getCellValue( wb, 1, 2 ) ).toBe( "" ); expect( s.getCellValue( wb, 2, 1 ) ).toBe( "" ); expect( s.getCellValue( wb, 2, 2 ) ).toBe( "" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).mergeCells( 1, 2, 1, 2 ); expect( s.getCellValue( wb, 1, 1 ) ).toBe( "a" ); expect( s.getCellValue( wb, 1, 2 ) ).toBe( "b" ); expect( s.getCellValue( wb, 2, 1 ) ).toBe( "c" ); expect( s.getCellValue( wb, 2, 2 ) ).toBe( "d" ); - }); - }); + }) + }) - describe( "mergeCells throws an exception if", function(){ + describe( "mergeCells throws an exception if", ()=>{ - it( "startRow OR startColumn is less than 1", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "startRow OR startColumn is less than 1", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.mergeCells( wb, 0, 0, 1, 2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidStartOrEndRowArgument" ); - expect( function(){ + expect( ()=>{ s.mergeCells( wb, 1, 2, 0, 0 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidStartOrEndColumnArgument" ); - }); - }); + }) + }) - it( "endRow/endColumn is less than startRow/startColumn", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "endRow/endColumn is less than startRow/startColumn", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.mergeCells( wb, 2, 1, 1, 2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidStartOrEndRowArgument" ); - expect( function(){ + expect( ()=>{ s.mergeCells( wb, 1, 2, 2, 1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidStartOrEndColumnArgument" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/moveSheet.cfm b/test/specs/moveSheet.cfm index 4a837c7..2161599 100644 --- a/test/specs/moveSheet.cfm +++ b/test/specs/moveSheet.cfm @@ -1,49 +1,49 @@ -describe( "moveSheet", function(){ +describe( "moveSheet", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Moves the named sheet to the specified position", function(){ - workbooks.Each( function( wb ){ + it( "Moves the named sheet to the specified position", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "sheet2" ); s.setActiveSheet( wb, "sheet2" ); expect( s.sheetInfo( wb ).position ).toBe( 2 ); s.moveSheet( wb, "sheet2", 1 ); expect( s.sheetInfo( wb ).position ).toBe( 1 ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .createSheet("sheet2" ) .setActiveSheet( "sheet2" ) .moveSheet( "sheet2", 1 ); expect( s.sheetInfo( wb ).position ).toBe( 1 ); - }); - }); + }) + }) - describe( "moveSheet throws an exception if", function(){ + describe( "moveSheet throws an exception if", ()=>{ - it( "the sheet name doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet name doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.moveSheet( wb, "test", 1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); - }); + }) + }) - it( "the new position is invalid", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the new position is invalid", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.moveSheet( wb, "sheet1", 10 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/new.cfm b/test/specs/new.cfm index bc1383c..58e58ec 100644 --- a/test/specs/new.cfm +++ b/test/specs/new.cfm @@ -1,17 +1,17 @@ -describe( "new", function(){ +describe( "new", ()=>{ - it( "Returns an HSSF workbook by default", function(){ + it( "Returns an HSSF workbook by default", ()=>{ var workbook = s.new(); expect( s.isBinaryFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Returns an XSSF workbook if xmlFormat is true", function(){ + it( "Returns an XSSF workbook if xmlFormat is true", ()=>{ var workbook = s.new( xmlFormat=true ); expect( s.isXmlFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Returns an XSSF workbook if global defaultWorkbookFormat is 'xml' or 'xlsx'", function(){ + it( "Returns an XSSF workbook if global defaultWorkbookFormat is 'xml' or 'xlsx'", ()=>{ var s = newSpreadsheetInstance().setDefaultWorkbookFormat( "xml" ); var workbook = s.new(); expect( s.isXmlFormat( workbook ) ).toBeTrue(); @@ -21,36 +21,36 @@ describe( "new", function(){ s.setDefaultWorkbookFormat( "xlsx" ); workbook = s.new(); expect( s.isXmlFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Returns a streaming XSSF workbook if streamingXml is true", function(){ + it( "Returns a streaming XSSF workbook if streamingXml is true", ()=>{ var workbook = s.new( streamingXml=true ); expect( s.isStreamingXmlFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Creates a workbook with the specified sheet name", function(){ + it( "Creates a workbook with the specified sheet name", ()=>{ var workbook = s.new( "test" ); expect( s.getSheetHelper().getActiveSheetName( workbook ) ).toBe( "test" ); - }); + }) - describe( "new throws an exception if", function(){ + describe( "new throws an exception if", ()=>{ - it( "the sheet name contains invalid characters", function(){ - expect( function(){ + it( "the sheet name contains invalid characters", ()=>{ + expect( ()=>{ s.new( "[]?*\/:" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidCharacters" ); - }); + }) - it( "streaming XML is specified with an invalid streamingWindowSize", function(){ - expect( function(){ + it( "streaming XML is specified with an invalid streamingWindowSize", ()=>{ + expect( ()=>{ s.new( xmlFormat=true, streamingXml=true, streamingWindowSize=1.2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidStreamingWindowSizeArgument" ); - expect( function(){ + expect( ()=>{ s.new( xmlFormat=true, streamingXml=true, streamingWindowSize=-1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidStreamingWindowSizeArgument" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/newXls.cfm b/test/specs/newXls.cfm index d988091..20bf997 100644 --- a/test/specs/newXls.cfm +++ b/test/specs/newXls.cfm @@ -1,15 +1,15 @@ -describe( "newXls", function(){ +describe( "newXls", ()=>{ - it( "Returns an HSSF workbook", function(){ + it( "Returns an HSSF workbook", ()=>{ var workbook = s.newXls(); expect( s.isBinaryFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Creates a workbook with the specified sheet name", function(){ + it( "Creates a workbook with the specified sheet name", ()=>{ var workbook = s.newXls( "test" ); expect( s.getSheetHelper().getActiveSheetName( workbook ) ).toBe( "test" ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/newXlsx.cfm b/test/specs/newXlsx.cfm index 765ff69..39d48ad 100644 --- a/test/specs/newXlsx.cfm +++ b/test/specs/newXlsx.cfm @@ -1,15 +1,15 @@ -describe( "newXlsx", function(){ +describe( "newXlsx", ()=>{ - it( "Returns an XSSF workbook", function(){ + it( "Returns an XSSF workbook", ()=>{ var workbook = s.newXlsx(); expect( s.isXmlFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Creates a workbook with the specified sheet name", function(){ + it( "Creates a workbook with the specified sheet name", ()=>{ var workbook = s.newXlsx( "test" ); expect( s.getSheetHelper().getActiveSheetName( workbook ) ).toBe( "test" ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/printGridLines.cfm b/test/specs/printGridLines.cfm index 8cddd73..bb018f4 100644 --- a/test/specs/printGridLines.cfm +++ b/test/specs/printGridLines.cfm @@ -1,38 +1,38 @@ -describe( "printGridLines", function(){ +describe( "printGridLines", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var columnData = [ "a", "b", "c" ]; var rowData = [ columnData, columnData, columnData ]; var data = QueryNew( "c1,c2,c3", "VarChar,VarChar,VarChar", rowData ); variables.xls = s.workbookFromQuery( data, false ); variables.xlsx = s.workbookFromQuery( data=data, addHeaderRow=false, xmlformat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "can be added", function(){ - workbooks.Each( function( wb ){ + it( "can be added", ()=>{ + workbooks.Each( ( wb )=>{ s.addPrintGridLines( wb ); expect( s.getSheetHelper().getActiveSheet( wb ).isPrintGridlines() ).toBeTrue(); - }); - }); + }) + }) - it( "can be removed", function(){ - workbooks.Each( function( wb ){ + it( "can be removed", ()=>{ + workbooks.Each( ( wb )=>{ s.addPrintGridLines( wb ) .removePrintGridLines( wb ); expect( s.getSheetHelper().getActiveSheet( wb ).isPrintGridlines() ).toBeFalse(); - }); - }); + }) + }) - it( "addPrintGridLines and removePrintGridLines are chainable", function(){ - workbooks.Each( function( wb ){ + it( "addPrintGridLines and removePrintGridLines are chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).addPrintGridLines(); expect( s.getSheetHelper().getActiveSheet( wb ).isPrintGridlines() ).toBeTrue(); s.newChainable( wb ).removePrintGridLines(); expect( s.getSheetHelper().getActiveSheet( wb ).isPrintGridlines() ).toBeFalse(); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/queryToCsv.cfm b/test/specs/queryToCsv.cfm index 1a63a46..4f4bc3e 100644 --- a/test/specs/queryToCsv.cfm +++ b/test/specs/queryToCsv.cfm @@ -1,64 +1,64 @@ -describe( "queryToCsv", function(){ +describe( "queryToCsv", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); - }); + }) - it( "converts a basic query to csv without a header row by default", function(){ + it( "converts a basic query to csv without a header row by default", ()=>{ var expected = 'a,b#newline#c,d#newline#'; expect( s.queryToCsv( data ) ).toBe( expected ); - }); + }) - it( "uses the query columns as the header row if specified", function(){ + it( "uses the query columns as the header row if specified", ()=>{ var expected = 'column1,column2#newline#a,b#newline#c,d#newline#'; expect( s.queryToCsv( data, true ) ).toBe( expected ); - }); + }) - it( "allows an alternative to the default comma delimiter", function(){ + it( "allows an alternative to the default comma delimiter", ()=>{ var expected = 'a|b#newline#c|d#newline#'; expect( s.queryToCsv( query=data, delimiter="|" ) ).toBe( expected ); - }); + }) - it( "allows tabs to be specified as the delimiter in a number of ways", function(){ + it( "allows tabs to be specified as the delimiter in a number of ways", ()=>{ var expected = 'a#Chr( 9 )#b#newline#c#Chr( 9 )#d#newline#'; var validTabValues = [ "#Chr( 9 )#", "\t", "tab", "TAB" ]; for( var value in validTabValues ){ expect( s.queryToCsv( query=data, delimiter=value ) ).toBe( expected ); } - }); + }) - it( "can handle an embedded delimiter", function(){ + it( "can handle an embedded delimiter", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a,a", "b" ], [ "c", "d" ] ] ); var expected = '"a,a",b#newline#c,d#newline#'; expect( s.queryToCsv( data ) ).toBe( expected ); - }); + }) - it( "can handle an embedded double-quote", function(){ + it( "can handle an embedded double-quote", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a""a", "b" ], [ "c", "d" ] ] ); var expected = '"a""a",b#newline#c,d#newline#'; expect( s.queryToCsv( data ) ).toBe( expected ); - }); + }) - it( "can handle an embedded carriage return", function(){ + it( "can handle an embedded carriage return", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a#newline#a", "b" ], [ "c", "d" ] ] ); var expected = '"a#newline#a",b#newline#c,d#newline#'; expect( s.queryToCsv( data ) ).toBe( expected ); - }); + }) - it( "outputs date objects using the instance's specified DATETIME format", function(){ + it( "outputs date objects using the instance's specified DATETIME format", ()=>{ var nowAsText = DateTimeFormat( Now(), s.getDateFormats().DATETIME ); var data = QueryNew( "column1", "Timestamp", [ [ ParseDateTime( nowAsText ) ] ] ); var expected = '#nowAsText##newline#'; expect( s.queryToCsv( data ) ).toBe( expected ); - }); + }) - it( "does NOT treat date strings as date objects to be formatted using the DATETIME format", function(){ + it( "does NOT treat date strings as date objects to be formatted using the DATETIME format", ()=>{ var dateString = "2022-12-18"; var data = QueryNew( "column1", "VarChar", [ [ dateString ] ] ); var expected = '#dateString##newline#'; expect( s.queryToCsv( data ) ).toBe( expected ); - }); + }) it( title="can process rows in parallel if the engine supports it" @@ -75,19 +75,19 @@ describe( "queryToCsv", function(){ } ); - describe( "queryToCsv throws an exception if", function(){ + describe( "queryToCsv throws an exception if", ()=>{ it( title="parallel threads are specified and the engine does not support it" ,body=function(){ - expect( function(){ + expect( ()=>{ s.queryToCsv( query=data, threads=2 ); }).toThrow( type="cfsimplicity.spreadsheet.parallelOptionNotSupported" ); } ,skip=s.engineSupportsParallelLoopProcessing() ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/read.cfm b/test/specs/read.cfm index 4387001..55a79b5 100644 --- a/test/specs/read.cfm +++ b/test/specs/read.cfm @@ -1,23 +1,23 @@ -describe( "read", function(){ +describe( "read", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ Sleep( 5 );// allow time for file operations to complete - }); + }) - it( "Can read a traditional XLS file", function(){ + it( "Can read a traditional XLS file", ()=>{ var path = getTestFilePath( "test.xls" ); var workbook = s.read( src=path ); expect( s.isBinaryFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Can read an OOXML file", function(){ + it( "Can read an OOXML file", ()=>{ var path = getTestFilePath( "test.xlsx" ); var workbook = s.read( src=path ); expect( s.isXmlFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Is chainable", function(){ + it( "Is chainable", ()=>{ var path = getTestFilePath( "test.xls" ); var workbook = s.newChainable() .read( path ) @@ -28,17 +28,17 @@ describe( "read", function(){ .read( path ) .getWorkbook(); expect( s.isXmlFormat( workbook ) ).toBeTrue(); - }); + }) - it( "Ends the chain and returns the import result if format is specified", function(){ - variables.spreadsheetTypes.Each( function( type ){ + it( "Ends the chain and returns the import result if format is specified", ()=>{ + variables.spreadsheetTypes.Each( ( type )=>{ var path = getTestFilePath( "test.#type#" ); var data = s.newChainable().read( path, "query" ); expect( IsQuery( data ) ).toBeTrue(); - }); - }); + }) + }) - it( "Can read a traditional XLS file into a query", function(){ + it( "Can read a traditional XLS file into a query", ()=>{ var path = getTestFilePath( "test.xls" ); var expected = querySim( "column1,column2 @@ -48,9 +48,9 @@ describe( "read", function(){ var actual = s.read( src=path,format="query" ); expect( actual ).toBe( expected ); - }); + }) - it( "Can read an OOXML file into a query", function(){ + it( "Can read an OOXML file into a query", ()=>{ var path = getTestFilePath( "test.xlsx" ); var expected = querySim( "column1,column2 @@ -59,10 +59,10 @@ describe( "read", function(){ c|g I am|ooxml"); var actual = s.read( src=path, format="query" ); - }); + }) - it( "Uses the first *visible* sheet if format=query and no sheet specified", function(){ - spreadsheetTypes.Each( function( type ){ + it( "Uses the first *visible* sheet if format=query and no sheet specified", ()=>{ + spreadsheetTypes.Each( ( type )=>{ var path = variables[ "temp" & type & "Path" ]; var wb = s.newChainable( type ) .renameSheet( "hidden sheet", 1 ) @@ -76,11 +76,11 @@ describe( "read", function(){ var expected = QueryNew( "column1", "VarChar", [ [ "I'm in a visible sheet" ] ] ); var actual = s.read( src=path, format="query" ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Returns a blank query if format=query and there are no visible sheets", function(){ - spreadsheetTypes.Each( function( type ){ + it( "Returns a blank query if format=query and there are no visible sheets", ()=>{ + spreadsheetTypes.Each( ( type )=>{ var path = variables[ "temp" & type & "Path" ]; var wb = s.newChainable( type ) .renameSheet( "hidden sheet", 1 ) @@ -91,28 +91,28 @@ describe( "read", function(){ var expected = QueryNew( "" ); var actual = s.read( src=path, format="query" ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Reads from the specified sheet name", function(){ + it( "Reads from the specified sheet name", ()=>{ var path = getTestFilePath( "test.xls" );// has 2 sheets var expected = querySim( "column1,column2 x|y"); var actual = s.read( src=path, format="query", sheetName="sheet2" ); expect( actual ).toBe( expected ); - }); + }) - it( "Reads from the specified sheet number", function(){ + it( "Reads from the specified sheet number", ()=>{ var path = getTestFilePath( "test.xls" );// has 2 sheets var expected = querySim( "column1,column2 x|y"); var actual = s.read( src=path, format="query", sheetNumber=2 ); expect( actual ).toBe( expected ); - }); + }) - it( "Uses the specified header row for column names", function(){ + it( "Uses the specified header row for column names", ()=>{ var path = getTestFilePath( "test.xls" ); var expected = querySim( "a,b @@ -120,9 +120,9 @@ describe( "read", function(){ #CreateDateTime( 2015, 4, 1, 1, 1, 1 )#|2"); var actual = s.read( src=path, format="query", headerRow=1 ); expect( actual ).toBe( expected ); - }); + }) - it( "Generates default column names if the data has more columns than the specifed header row", function(){ + it( "Generates default column names if the data has more columns than the specifed header row", ()=>{ var headerRow = [ "firstColumn" ]; var dataRow1 = [ "row 1 col 1 value" ]; var dataRow2 = [ "row 2 col 1 value", "row 2 col 2 value" ]; @@ -138,9 +138,9 @@ describe( "read", function(){ .write( tempXlsPath, true ); var actual = s.read( src=tempXlsPath, format="query", headerRow=1 ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes the specified header row in query if includeHeader is true", function(){ + it( "Includes the specified header row in query if includeHeader is true", ()=>{ var path = getTestFilePath( "test.xls" ); var expected = querySim( "a,b @@ -149,9 +149,9 @@ describe( "read", function(){ #CreateDateTime( 2015, 4, 1, 1, 1, 1 )#|2"); var actual = s.read( src=path, format="query", headerRow=1, includeHeaderRow=true ); expect( actual ).toBe( expected ); - }); + }) - it( "Excludes null and blank rows in query by default", function(){ + it( "Excludes null and blank rows in query by default", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "" ], [ "a", "b" ] ] ); var workbook = s.new(); s.addRows( workbook, data ) @@ -159,9 +159,9 @@ describe( "read", function(){ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ] ] ); var actual = s.read( src=tempXlsPath, format="query" ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes null and blank rows in query if includeBlankRows is true", function(){ + it( "Includes null and blank rows in query if includeBlankRows is true", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "" ], [ "a", "b" ] ] ); var workbook = s.new(); s.addRows( workbook, data ) @@ -169,20 +169,20 @@ describe( "read", function(){ var expected = data; var actual = s.read( src=tempXlsPath, format="query", includeBlankRows=true ); expect( actual ).toBe( expected ); - }); + }) - it( "Can handle null/empty cells", function(){ + it( "Can handle null/empty cells", ()=>{ var path = getTestFilePath( "nullCell.xls" ); var actual = s.read( src=path, format="query", headerRow=1 ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "a" ] ] ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes trailing empty columns when using a header row", function(){ + it( "Includes trailing empty columns when using a header row", ()=>{ var paths = [ tempXlsPath, tempXlsxPath ]; var expected = QuerySim( "col1,col2,emptyCol value|value|"); - paths.Each( function( path ){ + paths.Each( ( path )=>{ var type = ( path == tempXlsPath )? "xls": "xlsx"; var workbook = s.newChainable( type ) .addRow( "col1,col2,emptyCol" ) @@ -190,17 +190,17 @@ describe( "read", function(){ .write( path, true ); var actual = s.read( src=path, format="query", headerRow=1 ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Reads values of different types correctly, by default returning the raw values", function(){ + it( "Reads values of different types correctly, by default returning the raw values", ()=>{ var numericValue = 2; var dateValue = CreateDate( 2015, 04, 12 ); var rawDecimalValue = 0.000011; var leadingZeroValue = "01"; var columnNames = [ "numeric", "zero", "decimal", "boolean", "date", "leadingZero" ]; var data = QueryNew( columnNames.ToList(), "Integer,Integer,Decimal,Bit,Date,VarChar", [ [ numericValue, 0, rawDecimalValue, true, dateValue, leadingZeroValue ] ] ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var path = ( type == "xls" )? tempXlsPath: tempXlsxPath; s.newChainable( type ) .addRows( data ) @@ -208,11 +208,11 @@ describe( "read", function(){ .write( path ); var actual = s.read( src=path, format="query", columnNames=columnNames ); expect( actual ).toBe( data ); - }); - }); + }) + }) - it( "Can return the visible/formatted values rather than raw values", function(){ + it( "Can return the visible/formatted values rather than raw values", ()=>{ var numericValue = 2; var dateValue = CreateDate( 2015, 04, 12 ); var rawDecimalValue = 0.000011; @@ -220,7 +220,7 @@ describe( "read", function(){ var leadingZeroValue = "01"; var columnNames = [ "numeric", "zero", "decimal", "boolean", "date", "leadingZero" ]; var data = QueryNew( columnNames.ToList(), "Integer,Integer,Decimal,Bit,Date,VarChar", [ [ numericValue, 0, rawDecimalValue, true, dateValue, leadingZeroValue ] ] ); - variables.spreadsheetTypes.Each( function( type ){ + variables.spreadsheetTypes.Each( ( type )=>{ var path = ( type == "xls" )? tempXlsPath: tempXlsxPath; s.newChainable( type ) .addRows( data ) @@ -235,11 +235,11 @@ describe( "read", function(){ expect( actual.leadingZero ).toBe( leadingZeroValue ); var decimalHasBeenOutputInScientificNotation = ( Trim( actual.decimal ).FindNoCase( "E" ) > 0 ); expect( decimalHasBeenOutputInScientificNotation ).toBeFalse(); - }); - }); + }) + }) - it( "Can fill each of the empty cells in merged regions with the visible merged cell value without conflicting with includeBlankRows=true", function(){ + it( "Can fill each of the empty cells in merged regions with the visible merged cell value without conflicting with includeBlankRows=true", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ], [ "", "" ] ] ); var workbook = s.workbookFromQuery( data, false ); s.mergeCells( workbook, 1, 2, 1, 2, true )//force empty merged cells @@ -251,9 +251,9 @@ describe( "read", function(){ expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "a" ], [ "a", "a" ], [ "", "" ] ] ); actual = s.read( src=tempXlsPath, format="query", fillMergedCellsWithVisibleValue=true, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); + }) - it( "Can read specified rows only into a query", function(){ + it( "Can read specified rows only into a query", ()=>{ var data = QuerySim( "A A1 A2 @@ -283,9 +283,9 @@ describe( "read", function(){ A4 A5"); expect( actual ).toBe( expected ); - }); + }) - it( "Can read specified column numbers only into a query", function(){ + it( "Can read specified column numbers only into a query", ()=>{ var data = QuerySim( "A,B,C,D,E A1|B1|C1|D1|E1"); //With no header row, so no column names specified @@ -310,9 +310,9 @@ describe( "read", function(){ B|D|E B1|D1|E1"); expect( actual ).toBe( expected ); - }); + }) - it( "Can read specific rows and columns only into a query", function(){ + it( "Can read specific rows and columns only into a query", ()=>{ var data = QuerySim( "A1,B1,C1,D1,E1 A2|B2|C2|D2|E2 A3|B3|C3|D3|E3 @@ -327,9 +327,9 @@ describe( "read", function(){ B4|D4|E4 B5|D5|E5"); expect( actual ).toBe( expected ); - }); + }) - it( "Can read data starting at specific rows and/or columns into a query", function(){ + it( "Can read data starting at specific rows and/or columns into a query", ()=>{ var data = QuerySim( "A1,B1,C1,D1,E1,F1 A2|B2|C2|D2|E2|F2 A3|B3|C3|D3|E3|F3 @@ -341,7 +341,7 @@ describe( "read", function(){ workbook = s.workbookFromQuery( data=data, addHeaderRow=true, xmlFormat=true ); s.write( workbook, tempXlsxPath, true ); var paths = [ tempXlsPath, tempXlsxPath ]; - paths.Each( function( path ){ + paths.Each( ( path )=>{ var actual = s.read( src=path, format="query", columns="2,4-", rows="2,4-", headerRow=1 ); var expected = QuerySim( "B1,D1,E1,F1 B2|D2|E2|F2 @@ -349,10 +349,10 @@ describe( "read", function(){ B5|D5|E5|F5 B6|D6|E6|F6"); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Can return HTML table rows from an Excel file", function(){ + it( "Can return HTML table rows from an Excel file", ()=>{ var path = getTestFilePath( "test.xls" ); var actual = s.read( src=path, format="html" ); var expected = "ab12015-04-01 00:00:002015-04-01 01:01:012"; @@ -363,9 +363,9 @@ describe( "read", function(){ actual = s.read( src=path, format="html", headerRow=1, includeHeaderRow=true ); expected="abab12015-04-01 00:00:002015-04-01 01:01:012"; expect( actual ).toBe( expected ); - }); + }) - it( "Can return a CSV string from an Excel file", function(){ + it( "Can return a CSV string from an Excel file", ()=>{ var path = getTestFilePath( "test.xls" ); var expected = 'a,b#newline#1,2015-04-01 00:00:00#newline#2015-04-01 01:01:01,2#newline#'; var actual = s.read( src=path, format="csv" ); @@ -373,9 +373,9 @@ describe( "read", function(){ expected = 'a,b#newline#a,b#newline#1,2015-04-01 00:00:00#newline#2015-04-01 01:01:01,2#newline#'; actual = s.read( src=path, format="csv", headerRow=1, includeHeaderRow=true ); expect( actual ).toBe( expected ); - }); + }) - it( "Escapes double-quotes in string values when reading to CSV", function(){ + it( "Escapes double-quotes in string values when reading to CSV", ()=>{ var data = QueryNew( "column1", "VarChar", [ [ 'a "so-called" test' ] ] ); var workbook = s.new(); s.addRows( workbook, data ) @@ -383,17 +383,17 @@ describe( "read", function(){ var expected = '"a ""so-called"" test"#newline#'; var actual = s.read( src=tempXlsPath, format="csv" ); expect( actual ).toBe( expected ); - }); + }) - it( "Accepts a custom delimiter when generating CSV", function(){ + it( "Accepts a custom delimiter when generating CSV", ()=>{ var path = getTestFilePath( "test.xls" ); var expected = 'a|b#newline#1|2015-04-01 00:00:00#newline#2015-04-01 01:01:01|2#newline#'; var actual = s.read( src=path, format="csv", csvDelimiter="|" ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes columns formatted as 'hidden' by default", function(){ - spreadsheetTypes.Each( function( type ){ + it( "Includes columns formatted as 'hidden' by default", ()=>{ + spreadsheetTypes.Each( ( type )=>{ var path = variables[ "temp" & type & "Path" ]; s.newChainable( type ) .addColumn( "a1" ) @@ -403,10 +403,10 @@ describe( "read", function(){ var actual = s.read( src=path, format="query" ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a1", "b1" ] ] ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Can exclude columns formatted as 'hidden'", function(){ + it( "Can exclude columns formatted as 'hidden'", ()=>{ var workbook = s.new(); s.addColumn( workbook, "a1" ) .addColumn( workbook, "b1" ) @@ -416,11 +416,11 @@ describe( "read", function(){ var expected = QuerySim( "column2 b1"); expect( actual ).toBe( expected ); - }); + }) - it( "Includes rows formatted as 'hidden' by default", function(){ + it( "Includes rows formatted as 'hidden' by default", ()=>{ var data = QueryNew( "column1", "VarChar", [ [ "Apple" ], [ "Banana" ], [ "Carrot" ], [ "Doughnut" ] ] ); - spreadsheetTypes.Each( function( type ){ + spreadsheetTypes.Each( ( type )=>{ var path = variables[ "temp" & type & "Path" ]; s.newChainable( type ) .addRows( data ) @@ -429,10 +429,10 @@ describe( "read", function(){ var actual = s.read( src=path, format="query" ); var expected = data; expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Can exclude rows formatted as 'hidden'", function(){ + it( "Can exclude rows formatted as 'hidden'", ()=>{ var data = QueryNew( "column1", "VarChar", [ [ "Apple" ], [ "Banana" ], [ "Carrot" ], [ "Doughnut" ] ] ); var workbook = s.new(); s.addRows( workbook, data ); @@ -442,20 +442,20 @@ describe( "read", function(){ var actual = s.read( src=tempXlsPath, format="query", includeHiddenRows=false ); var expected = QueryNew( "column1", "VarChar", [ [ "Banana" ], [ "Doughnut" ] ] ); expect( actual ).toBe( expected ); - }); + }) - it( "Returns an empty query if the spreadsheet is empty even if headerRow is specified", function(){ + it( "Returns an empty query if the spreadsheet is empty even if headerRow is specified", ()=>{ var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var path = s.isXmlFormat( wb )? tempXlsxPath: tempXlsPath; s.write( wb, path, true ); var actual = s.read( src=path, format="query", headerRow=1 ); var expected = QueryNew( "" ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Returns an empty query if excluding hidden columns and ALL columns are hidden", function(){ + it( "Returns an empty query if excluding hidden columns and ALL columns are hidden", ()=>{ var workbook = s.new(); s.addColumn( workbook, "a1" ) .addColumn( workbook, "b1" ) @@ -465,34 +465,34 @@ describe( "read", function(){ var actual = s.read( src=tempXlsPath, format="query", includeHiddenColumns=false ); var expected = QueryNew( "" ); expect( actual ).toBe( expected ); - }); + }) - it( "Returns a query with column names but no rows if column names are specified but spreadsheet is empty", function(){ + it( "Returns a query with column names but no rows if column names are specified but spreadsheet is empty", ()=>{ var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var path = s.isXmlFormat( wb )? tempXlsxPath: tempXlsPath; s.write( wb, path, true ); var actual = s.read( src=path, format="query", columnNames="One,Two" ); var expected = QueryNew( "One,Two","Varchar,Varchar", [] ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Can read an encrypted XLSX file", function(){ + it( "Can read an encrypted XLSX file", ()=>{ var path = getTestFilePath( "passworded.xlsx" ); var expected = QueryNew( "column1", "VarChar", [ [ "secret" ] ] ); var actual = s.read( src=path, format="query", password="pass" ); expect( actual ).toBe( expected ); - }); + }) - it( "Can read an encrypted binary file", function(){ + it( "Can read an encrypted binary file", ()=>{ var path = getTestFilePath( "passworded.xls" ); var expected = QueryNew( "column1", "VarChar", [ [ "secret" ] ] ); var actual = s.read( src=path, format="query", password="pass" ); expect( actual ).toBe( expected ); - }); + }) - it( "Can read a spreadsheet containing a formula", function(){ + it( "Can read a spreadsheet containing a formula", ()=>{ var workbook = s.new(); s.addColumn( workbook, "1,1" ); var theFormula = "SUM(A1:A2)"; @@ -501,11 +501,11 @@ describe( "read", function(){ var expected = QueryNew( "column1","Integer", [ [ 1 ], [ 1 ], [ 2 ] ] ); var actual = s.read( src=tempXlsPath, format="query" ); expect( actual ).toBe( expected ); - }); + }) - describe( "query column name setting", function() { + describe( "query column name setting", ()=>{ - it( "Allows column names to be specified as a list when reading a sheet into a query", function(){ + it( "Allows column names to be specified as a list when reading a sheet into a query", ()=>{ var path = getTestFilePath( "test.xls" ); actual = s.read( src=path, format="query", columnNames="One,Two" ); expected = QuerySim( "One,Two @@ -513,9 +513,9 @@ describe( "read", function(){ 1|#CreateDateTime( 2015, 4, 1, 0, 0, 0 )# #CreateDateTime( 2015, 4, 1, 1, 1, 1 )#|2"); expect( actual ).toBe( expected ); - }); + }) - it( "Allows column names to be specified as an array when reading a sheet into a query", function(){ + it( "Allows column names to be specified as an array when reading a sheet into a query", ()=>{ var path = getTestFilePath( "test.xls" ); actual = s.read( src=path, format="query", columnNames=[ "One", "Two" ] ); expected = QuerySim( "One,Two @@ -523,26 +523,26 @@ describe( "read", function(){ 1|#CreateDateTime( 2015, 4, 1, 0, 0, 0 )# #CreateDateTime( 2015, 4, 1, 1, 1, 1 )#|2"); expect( actual ).toBe( expected ); - }); + }) - it( "ColumnNames list overrides headerRow: none of the header row values will be used", function(){ + it( "ColumnNames list overrides headerRow: none of the header row values will be used", ()=>{ var path = getTestFilePath( "test.xls" ); var actual = s.read( src=path, format="query", columnNames="One,Two", headerRow=1 ); var expected = QuerySim( "One,Two 1|#CreateDateTime( 2015, 4, 1, 0, 0, 0 )# #CreateDateTime( 2015, 4, 1, 1, 1, 1 )#|2"); expect( actual ).toBe( expected ); - }); + }) - it( "can handle column names containing commas or spaces", function(){ + it( "can handle column names containing commas or spaces", ()=>{ var path = getTestFilePath( "commaAndSpaceInColumnHeaders.xls" ); var actual = s.read( src=path, format="query", headerRow=1 ); var columnNames = [ "first name", "surname,comma" ];// these are the file column headers expect( actual.getColumnNames()[ 1 ] ).toBe( columnNames[ 1 ] ); expect( actual.getColumnNames()[ 2 ] ).toBe( columnNames[ 2 ] ); - }); + }) - it( "Accepts 'queryColumnNames' as an alias of 'columnNames'", function(){ + it( "Accepts 'queryColumnNames' as an alias of 'columnNames'", ()=>{ var path = getTestFilePath( "test.xls" ); actual = s.read( src=path, format="query", queryColumnNames="One,Two" ); expected = QuerySim( "One,Two @@ -550,9 +550,9 @@ describe( "read", function(){ 1|#CreateDateTime( 2015, 4, 1, 0, 0, 0 )# #CreateDateTime( 2015, 4, 1, 1, 1, 1 )#|2"); expect( actual ).toBe( expected ); - }); + }) - it( "Allows header names to be made safe for query column names", function(){ + it( "Allows header names to be made safe for query column names", ()=>{ var data = [ [ "id","id","A B","x/?y","(a)"," A","##1","1a" ], [ 1,2,3,4,5,6,7,8 ] ]; var wb = s.newXlsx(); s.addRows( wb, data ) @@ -570,9 +570,9 @@ describe( "read", function(){ cfloop( from=1, to=expected.Len(), index="i" ){ expect( q.getColumnNames()[ i ] ).toBe( expected[ i ] ); } - }); + }) - it( "Generates default column names if the data has more columns than the specifed column names", function(){ + it( "Generates default column names if the data has more columns than the specifed column names", ()=>{ var columnNames = [ "firstColumn" ]; var dataRow1 = [ "row 1 col 1 value" ]; var dataRow2 = [ "row 2 col 1 value", "row 2 col 2 value" ]; @@ -587,13 +587,13 @@ describe( "read", function(){ .write( tempXlsPath, true ); var actual = s.read( src=tempXlsPath, format="query", columnNames=columnNames ); expect( actual ).toBe( expected ); - }); + }) - }); + }) - describe( "query column type setting", function(){ + describe( "query column type setting", ()=>{ - it( "allows the query column types to be manually set using list", function(){ + it( "allows the query column types to be manually set using list", ()=>{ var workbook = s.new(); s.addRow( workbook, [ 1, 1.1, "string", _CreateTime( 1, 0, 0 ) ] ) .write( workbook, tempXlsPath, true ); @@ -603,9 +603,9 @@ describe( "read", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be manually set where the column order isn't known, but the header row values are", function(){ + it( "allows the query column types to be manually set where the column order isn't known, but the header row values are", ()=>{ var workbook = s.new(); s.addRows( workbook, [ [ "integer", "double", "string column", "time" ], [ 1, 1.1, "text", _CreateTime( 1, 0, 0 ) ] ] ) .write( workbook, tempXlsPath, true ); @@ -616,9 +616,9 @@ describe( "read", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be manually set where the column order isn't known, but the column names are", function(){ + it( "allows the query column types to be manually set where the column order isn't known, but the column names are", ()=>{ var workbook = s.new(); s.addRows( workbook, [ [ 1, 1.1, "text", _CreateTime( 1, 0, 0 ) ] ] ) .write( workbook, tempXlsPath, true ); @@ -630,9 +630,9 @@ describe( "read", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be automatically set", function(){ + it( "allows the query column types to be automatically set", ()=>{ var workbook = s.new(); s.addRow( workbook, [ 1, 1.1, "string", Now() ] ) .write( workbook, tempXlsPath, true ); @@ -642,9 +642,9 @@ describe( "read", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIMESTAMP" ); - }); + }) - it( "automatic detecting of query column types ignores blank cells", function(){ + it( "automatic detecting of query column types ignores blank cells", ()=>{ var workbook = s.new(); var data = [ [ "", "", "", "" ], @@ -660,9 +660,9 @@ describe( "read", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIMESTAMP" ); - }); + }) - it( "allows a default type to be set for all query columns", function(){ + it( "allows a default type to be set for all query columns", ()=>{ var workbook = s.new(); s.addRow( workbook, [ 1, 1.1, "string", Now() ] ) .write( workbook, tempXlsPath, true ); @@ -672,18 +672,18 @@ describe( "read", function(){ expect( columns[ 2 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "VARCHAR" ); - }); + }) - }); + }) describe( title="Lucee only timezone tests", body=function(){ - it( "Doesn't offset a date value even if the Lucee timezone doesn't match the system", function(){ + it( "Doesn't offset a date value even if the Lucee timezone doesn't match the system", ()=>{ variables.currentTZ = GetTimeZone(); variables.tempTZ = "US/Eastern"; - spreadsheetTypes.Each( function( type ){ + spreadsheetTypes.Each( ( type )=>{ SetTimeZone( tempTZ ); var path = variables[ "temp" & type & "Path" ]; local.s = newSpreadsheetInstance();//timezone mismatch detection cached is per instance @@ -692,25 +692,25 @@ describe( "read", function(){ var expected = CreateDate( 2022, 01, 01 ); expect( actual ).toBe( expected ); SetTimeZone( currentTZ ); - }); + }) - }); + }) }, skip=( !s.getIsLucee() || ( s.getDateHelper().getPoiTimeZone() != "Europe/London" ) )// only valid if system timezone is ahead of temporary test timezone ); - describe( "read throws an exception if", function(){ + describe( "read throws an exception if", ()=>{ - it( "queryColumnTypes is specified as a 'columnName/type' struct, but headerRow and columnNames arguments are missing", function(){ - expect( function(){ + it( "queryColumnTypes is specified as a 'columnName/type' struct, but headerRow and columnNames arguments are missing", ()=>{ + expect( ()=>{ var columnTypes = { col1: "Integer" }; s.read( src=getTestFilePath( "test.xlsx" ), format="query", queryColumnTypes=columnTypes ); }).toThrow( type="cfsimplicity.spreadsheet.invalidQueryColumnTypesArgument" ); - }); + }) - it( "a formula can't be evaluated", function(){ - expect( function(){ + it( "a formula can't be evaluated", ()=>{ + expect( ()=>{ var workbook = s.new(); s.addColumn( workbook, "1,1" ); var theFormula="SUS(A1:A2)";//invalid formula @@ -718,95 +718,95 @@ describe( "read", function(){ .write( workbook=workbook, filepath=tempXlsPath, overwrite=true ) .read( src=tempXlsPath, format="query" ); }).toThrow( type="cfsimplicity.spreadsheet.failedFormula" ); - }); + }) - it( "the 'query' argument is passed", function(){ - expect( function(){ + it( "the 'query' argument is passed", ()=>{ + expect( ()=>{ s.read( src=tempXlsPath, query="q" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidQueryArgument" ); - }); + }) - it( "the format argument is invalid", function(){ - expect( function(){ + it( "the format argument is invalid", ()=>{ + expect( ()=>{ s.read( src=tempXlsPath, format="wrong" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidReadFormat" ); - }); + }) - it( "the file doesn't exist", function(){ - expect( function(){ + it( "the file doesn't exist", ()=>{ + expect( ()=>{ var path = getTestFilePath( "nonexistent.xls" ); s.read( src=path ); }).toThrow( type="cfsimplicity.spreadsheet.nonExistentFile" ); - }); + }) - it( "the sheet name doesn't exist", function(){ - expect( function(){ + it( "the sheet name doesn't exist", ()=>{ + expect( ()=>{ var path = getTestFilePath( "test.xls" ); s.read( src=path, format="query", sheetName="nonexistent" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); + }) - it( "the sheet number doesn't exist", function(){ - expect( function(){ + it( "the sheet number doesn't exist", ()=>{ + expect( ()=>{ var path = getTestFilePath( "test.xls" ); s.read( src=path, format="query", sheetNumber=20 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - }); + }) - it( "both sheetName and sheetNumber arguments are specified", function(){ - expect( function(){ + it( "both sheetName and sheetNumber arguments are specified", ()=>{ + expect( ()=>{ var path = getTestFilePath( "test.xls" ); s.read( src=path, sheetName="sheet1", sheetNumber=2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArguments" ); - }); + }) - it( "the password for an encrypted XML file is incorrect", function(){ - expect( function(){ + it( "the password for an encrypted XML file is incorrect", ()=>{ + expect( ()=>{ var tempXlsxPath = getTestFilePath( "passworded.xlsx" ); s.read( src=tempXlsxPath, format="query", password="parse" ); }).toThrow( regex="(Invalid password|Password incorrect|password is invalid)" ); - }); + }) - it( "the password for an encrypted binary file is incorrect", function(){ - expect( function(){ + it( "the password for an encrypted binary file is incorrect", ()=>{ + expect( ()=>{ var xlsPath = getTestFilePath( "passworded.xls" ); s.read( src=xlsPath, format="query", password="parse" ); }).toThrow( regex="(Invalid password|Password incorrect|password is invalid)" ); - }); + }) - it( "the source file is not a spreadsheet", function(){ - expect( function(){ + it( "the source file is not a spreadsheet", ()=>{ + expect( ()=>{ var path = getTestFilePath( "notaspreadsheet.txt" ); s.read( src=path ); }).toThrow( type="cfsimplicity.spreadsheet.invalidFile" ); - }); + }) - it( "the source file appears to contain CSV or TSV, and suggests using 'csvToQuery'", function(){ - expect( function(){ + it( "the source file appears to contain CSV or TSV, and suggests using 'csvToQuery'", ()=>{ + expect( ()=>{ var path = getTestFilePath( "csv.xls" ); s.read( src=path ); }).toThrow( type="cfsimplicity.spreadsheet.invalidFile" ); - expect( function(){ + expect( ()=>{ var path = getTestFilePath( "test.tsv" ); s.read( src=path ); }).toThrow( type="cfsimplicity.spreadsheet.invalidFile" ); - }); + }) - it( "the source file is in an old format not supported by POI", function(){ - expect( function(){ + it( "the source file is in an old format not supported by POI", ()=>{ + expect( ()=>{ var path = getTestFilePath( "oldformat.xls" ); s.read( src=path ); }).toThrow( type="cfsimplicity.spreadsheet.oldExcelFormatException" ); - }); + }) - }); + }) - afterEach( function(){ + afterEach( ()=>{ if( FileExists( variables.tempXlsPath ) ) FileDelete( variables.tempXlsPath ); if( FileExists( variables.tempXlsxPath ) ) FileDelete( variables.tempXlsxPath ); - }); + }) -}); +}) diff --git a/test/specs/readBinary.cfm b/test/specs/readBinary.cfm index cd7bc91..76728cd 100644 --- a/test/specs/readBinary.cfm +++ b/test/specs/readBinary.cfm @@ -1,20 +1,20 @@ -describe( "readBinary", function(){ +describe( "readBinary", ()=>{ - it( "Returns a binary object", function(){ + it( "Returns a binary object", ()=>{ var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ expect( IsBinary( s.readBinary( wb ) ) ).toBeTrue(); - }); - }); + }) + }) - it( "Is chainable", function(){ + it( "Is chainable", ()=>{ var workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ var actual = s.newChainable( wb ).readBinary(); expect( IsBinary( actual ) ).toBeTrue(); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/readCsv.cfm b/test/specs/readCsv.cfm index 0fd6745..1732e72 100644 --- a/test/specs/readCsv.cfm +++ b/test/specs/readCsv.cfm @@ -1,16 +1,16 @@ -describe( "readCsv", function(){ +describe( "readCsv", ()=>{ - it( "can read a basic csv file into an array", function(){ + it( "can read a basic csv file into an array", ()=>{ var path = getTestFilePath( "test.csv" ); var expected = { columns: [], data: [ [ "Frumpo McNugget", "12345" ] ] }; var actual = s.readCsv( path ) .intoAnArray() .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "allows predefined formats to be specified", function(){ + it( "allows predefined formats to be specified", ()=>{ var csv = '"Frumpo McNugget"#Chr( 9 )#12345'; FileWrite( tempCsvPath, csv ); var expected = { columns: [], data: [ [ "Frumpo McNugget", "12345" ] ] }; @@ -19,9 +19,9 @@ describe( "readCsv", function(){ .withPredefinedFormat( "TDF" ) .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "has special handling when specifying tab as the delimiter", function(){ + it( "has special handling when specifying tab as the delimiter", ()=>{ var csv = '"Frumpo McNugget"#Chr( 9 )#12345'; FileWrite( tempCsvPath, csv ); var validTabValues = [ "#Chr( 9 )#", "\t", "tab", "TAB" ]; @@ -33,9 +33,9 @@ describe( "readCsv", function(){ .execute(); expect( actual ).toBe( expected ); } - }); + }) - it( "allows N rows to be skipped at the start of the file", function(){ + it( "allows N rows to be skipped at the start of the file", ()=>{ var csv = 'Skip this line#newline#skip this line too#newline#"Frumpo McNugget",12345'; var expected = { columns: [], data: [ [ "Frumpo McNugget", "12345" ] ] }; FileWrite( tempCsvPath, csv ); @@ -44,11 +44,11 @@ describe( "readCsv", function(){ .withSkipFirstRows( 2 ) .execute(); expect( actual ).toBe( expected ); - }); + }) - describe( "auto header/column handling", function(){ + describe( "auto header/column handling", ()=>{ - it( "can auto extract the column names from first row if specified", function(){ + it( "can auto extract the column names from first row if specified", ()=>{ var csv = 'name,number#newline#"Frumpo McNugget",12345'; var expected = { columns: [ "name", "number" ], data: [ [ "Frumpo McNugget", "12345" ] ] }; FileWrite( tempCsvPath, csv ); @@ -57,9 +57,9 @@ describe( "readCsv", function(){ .withFirstRowIsHeader( true ) .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "auto extraction treats the first non-skipped row as the header", function(){ + it( "auto extraction treats the first non-skipped row as the header", ()=>{ var csv = 'Skip this line#newline#name,number#newline#"Frumpo McNugget",12345'; var expected = { columns: [ "name", "number" ], data: [ [ "Frumpo McNugget", "12345" ] ] }; FileWrite( tempCsvPath, csv ); @@ -69,9 +69,9 @@ describe( "readCsv", function(){ .withFirstRowIsHeader( true ) .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "adds a manually specified header row to the columns result", function(){ + it( "adds a manually specified header row to the columns result", ()=>{ var csv = 'name,number#newline#"Frumpo McNugget",12345'; var expected = { columns: [ "name", "number" ], data: [ [ "Frumpo McNugget", "12345" ] ] }; FileWrite( tempCsvPath, csv ); @@ -81,17 +81,17 @@ describe( "readCsv", function(){ .withSkipHeaderRecord( true ) .execute(); expect( actual ).toBe( expected ); - }); + }) - }); + }) - describe( "passing UDFs to readCsv", function(){ + describe( "passing UDFs to readCsv", ()=>{ - it( "allows rows to be filtered out of processing using a passed filter UDF", function(){ + it( "allows rows to be filtered out of processing using a passed filter UDF", ()=>{ var csv = '"Frumpo McNugget",12345#newline#"Skip",12345#newline#"Susi Sorglos",67890'; var expected = { columns: [], data: [ [ "Frumpo McNugget", "12345" ], [ "Susi Sorglos", "67890" ] ] }; FileWrite( tempCsvPath, csv ); - var filter = function( rowValues ){ + var filter = ( rowValues )=>{ return !ArrayFindNoCase( rowValues, "skip" ); }; var actual = s.readCsv( tempCsvPath ) @@ -99,58 +99,58 @@ describe( "readCsv", function(){ .withRowFilter( filter ) .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "allows rows to be processed using a passed UDF and the processed values returned", function(){ + it( "allows rows to be processed using a passed UDF and the processed values returned", ()=>{ var csv = '"Frumpo McNugget",12345#newline#"Susi Sorglos",67890'; var expected = { columns: [], data: [ [ "XFrumpo McNugget", "X12345" ], [ "XSusi Sorglos", "X67890" ] ] }; FileWrite( tempCsvPath, csv ); - var processor = function( rowValues ){ + var processor = ( rowValues )=>{ //NB: rowValues is a java native array. Array member functions won't work therefore. - return ArrayMap( rowValues, function( value ){ + return ArrayMap( rowValues, ( value )=>{ return "X" & value; - }); + }) }; var actual = s.readCsv( tempCsvPath ) .intoAnArray() .withRowProcessor( processor ) .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "allows rows to be processed using a passed UDF without returning any data", function(){ + it( "allows rows to be processed using a passed UDF without returning any data", ()=>{ var csv = '10#newline#10'; var expected = 20; FileWrite( tempCsvPath, csv ); variables.tempTotal = 0; - var processor = function( rowValues ){ - ArrayEach( rowValues, function( value ){ + var processor = ( rowValues )=>{ + ArrayEach( rowValues, ( value )=>{ tempTotal = ( tempTotal + value ); - }); + }) }; s.readCsv( tempCsvPath ) .withRowProcessor( processor ) .execute(); expect( tempTotal ).toBe( expected ); - }); + }) - it( "passes the current record number to the processor UDF", function(){ + it( "passes the current record number to the processor UDF", ()=>{ var csv = '"Frumpo McNugget",12345#newline#"Susi Sorglos",67890'; var expected = [ 1, 2 ]; FileWrite( tempCsvPath, csv ); variables.temp = []; - var processor = function( rowValues, rowNumber ){ + var processor = ( rowValues, rowNumber )=>{ temp.Append( rowNumber ); }; s.readCsv( tempCsvPath ) .withRowProcessor( processor ) .execute(); expect( temp ).toBe( expected ); - }); + }) - }); + }) - it( "allows Commons CSV format options to be applied", function(){ + it( "allows Commons CSV format options to be applied", ()=>{ var path = getTestFilePath( "test.csv" ); var object = s.readCsv( path ) .withAllowMissingColumnNames() @@ -205,22 +205,22 @@ describe( "readCsv", function(){ expect( object.getFormat().getSkipHeaderRecord() ).toBeFalse(); expect( object.getFormat().getTrailingDelimiter() ).toBeFalse(); expect( object.getFormat().getTrim() ).toBeFalse(); - }); + }) - afterEach( function(){ + afterEach( ()=>{ if( FileExists( tempCsvPath ) ) FileDelete( tempCsvPath ); - }); + }) - describe( "readCsv() throws an exception if", function(){ + describe( "readCsv() throws an exception if", ()=>{ - it( "a zero or positive integer is not passed to withSkipFirstRows()", function(){ - expect( function(){ + it( "a zero or positive integer is not passed to withSkipFirstRows()", ()=>{ + expect( ()=>{ var actual = s.readCsv( getTestFilePath( "test.csv" ) ).withSkipFirstRows( -1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArgument" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/readLargeFile.cfm b/test/specs/readLargeFile.cfm index 488233b..adb9bb2 100644 --- a/test/specs/readLargeFile.cfm +++ b/test/specs/readLargeFile.cfm @@ -1,42 +1,42 @@ -describe( "readLargeFile", function(){ +describe( "readLargeFile", ()=>{ - it( "Can read an XLSX file into a query", function(){ + it( "Can read an XLSX file into a query", ()=>{ var path = getTestFilePath( "large.xlsx" ); var expected = querySim( "column1,column2 FirstSheet A1|FirstSheet B1"); var actual = s.readLargeFile( src=path ); - }); + }) - it( "Reads from the specified sheet name", function(){ + it( "Reads from the specified sheet name", ()=>{ var path = getTestFilePath( "large.xlsx" );// has 2 sheets var expected = querySim( "column1,column2 SecondSheet A1|SecondSheet B1"); var actual = s.readLargeFile( src=path, sheetName="SecondSheet" ); expect( actual ).toBe( expected ); - }); + }) - it( "Reads from the specified sheet name", function(){ + it( "Reads from the specified sheet name", ()=>{ var path = getTestFilePath( "large.xlsx" );// has 2 sheets var expected = querySim( "column1,column2 SecondSheet A1|SecondSheet B1"); var actual = s.readLargeFile( src=path, sheetNumber=2 ); expect( actual ).toBe( expected ); - }); + }) - it( "Uses the specifed header row for column names", function(){ + it( "Uses the specifed header row for column names", ()=>{ var path = getTestFilePath( "large.xlsx" ); var expected = querySim( "heading1,heading2 A2 value|B2 value"); var actual = s.readLargeFile( src=path, headerRow=1, sheetName="HeaderRow" ); expect( actual ).toBe( expected ); - }); + }) - it( "Generates default column names if the data has more columns than the specifed header row", function(){ + it( "Generates default column names if the data has more columns than the specifed header row", ()=>{ var headerRow = [ "firstColumn" ]; var dataRow1 = [ "row 1 col 1 value" ]; var dataRow2 = [ "row 2 col 1 value", "row 2 col 2 value" ]; @@ -52,9 +52,9 @@ describe( "readLargeFile", function(){ .write( tempXlsxPath, true ); var actual = s.readLargeFile( src=tempXlsxPath, headerRow=1 ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes the specified header row in query if includeHeader is true", function(){ + it( "Includes the specified header row in query if includeHeader is true", ()=>{ var headerRow = [ "a", "b" ]; var dataRow = [ "c", "d" ]; s.newChainable( "xlsx" ) @@ -67,9 +67,9 @@ describe( "readLargeFile", function(){ c|d"); var actual = s.readLargeFile( src=tempXlsxPath, headerRow=1, includeHeaderRow=true ); expect( actual ).toBe( expected ); - }); + }) - it( "Excludes null and blank rows in query by default", function(){ + it( "Excludes null and blank rows in query by default", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "" ], [ "a", "b" ] ] ); var workbook = s.newXlsx(); s.addRows( workbook, data ) @@ -77,9 +77,9 @@ describe( "readLargeFile", function(){ var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ] ] ); var actual = s.readLargeFile( src=tempXlsxPath ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes null and blank rows in query if includeBlankRows is true", function(){ + it( "Includes null and blank rows in query if includeBlankRows is true", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "" ], [ "a", "b" ] ] ); var workbook = s.newXlsx(); s.addRows( workbook, data ) @@ -87,16 +87,16 @@ describe( "readLargeFile", function(){ var expected = data; var actual = s.readLargeFile( src=tempXlsxPath, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); + }) - it( "Can handle null/empty cells", function(){ + it( "Can handle null/empty cells", ()=>{ var path = getTestFilePath( "nullCell.xlsx" ); var actual = s.readLargeFile( src=path, headerRow=1 ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "a" ] ] ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes trailing empty columns when using a header row", function(){ + it( "Includes trailing empty columns when using a header row", ()=>{ var expected = QuerySim( "col1,col2,emptyCol value|value|"); var workbook = s.newChainable( "xlsx" ) @@ -105,9 +105,9 @@ describe( "readLargeFile", function(){ .write( tempXlsxPath, true ); var actual = s.readLargeFile( src=tempXlsxPath, headerRow=1 ); expect( actual ).toBe( expected ); - }); + }) - it( "Can return HTML table rows from an Excel file", function(){ + it( "Can return HTML table rows from an Excel file", ()=>{ var headerRow = [ "header1", "header2" ]; var dataRow = [ "a", CreateDate( 2015, 04, 01 ) ]; s.newChainable( "xlsx" ) @@ -123,9 +123,9 @@ describe( "readLargeFile", function(){ actual = s.read( src=tempXlsxPath, format="html", headerRow=1, includeHeaderRow=true ); expected = "header1header2header1header2a2015-04-01 00:00:00"; expect( actual ).toBe( expected ); - }); + }) - it( "Can return a CSV string from an Excel file", function(){ + it( "Can return a CSV string from an Excel file", ()=>{ var headerRow = [ "header1", "header2" ]; var dataRow = [ "a", CreateDate( 2015, 04, 01 ) ]; s.newChainable( "xlsx" ) @@ -138,9 +138,9 @@ describe( "readLargeFile", function(){ expected = 'header1,header2#newline#header1,header2#newline#a,2015-04-01 00:00:00#newline#'; actual = s.readLargeFile( src=tempXlsxPath, format="csv", headerRow=1, includeHeaderRow=true ); expect( actual ).toBe( expected ); - }); + }) - it( "Accepts a custom delimiter when generating CSV", function(){ + it( "Accepts a custom delimiter when generating CSV", ()=>{ var dataRow = [ "a", CreateDate( 2015, 04, 01 ) ]; s.newChainable( "xlsx" ) .addRow( dataRow ) @@ -148,9 +148,9 @@ describe( "readLargeFile", function(){ var expected = 'a|2015-04-01 00:00:00#newline#'; var actual = s.readLargeFile( src=tempXlsxPath, format="csv", csvDelimiter="|" ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes columns formatted as 'hidden' by default", function(){ + it( "Includes columns formatted as 'hidden' by default", ()=>{ s.newChainable( "xlsx" ) .addColumn( "a1" ) .addColumn( "b1" ) @@ -159,9 +159,9 @@ describe( "readLargeFile", function(){ var actual = s.readLargeFile( src=tempXlsPath ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a1", "b1" ] ] ); expect( actual ).toBe( expected ); - }); + }) - it( "Can exclude columns formatted as 'hidden'", function(){ + it( "Can exclude columns formatted as 'hidden'", ()=>{ s.newChainable( "xlsx" ) .addColumn( "a1" ) .addColumn( "b1" ) @@ -170,9 +170,9 @@ describe( "readLargeFile", function(){ var actual = s.readLargeFile( src=tempXlsPath, includeHiddenColumns=false ); var expected = QueryNew( "column2", "VarChar", [ [ "b1" ] ] ); expect( actual ).toBe( expected ); - }); + }) - it( "Includes rows formatted as 'hidden' by default", function(){ + it( "Includes rows formatted as 'hidden' by default", ()=>{ var data = QueryNew( "column1", "VarChar", [ [ "Apple" ], [ "Banana" ], [ "Carrot" ], [ "Doughnut" ] ] ); s.newChainable( "xlsx" ) .addRows( data ) @@ -181,9 +181,9 @@ describe( "readLargeFile", function(){ var actual = s.readLargeFile( src=tempXlsPath ); var expected = data; expect( actual ).toBe( expected ); - }); + }) - it( "Can exclude rows formatted as 'hidden'", function(){ + it( "Can exclude rows formatted as 'hidden'", ()=>{ var data = QueryNew( "column1", "VarChar", [ [ "Apple" ], [ "Banana" ], [ "Carrot" ], [ "Doughnut" ] ] ); s.newChainable( "xlsx" ) .addRows( data ) @@ -192,17 +192,17 @@ describe( "readLargeFile", function(){ var actual = s.readLargeFile( src=tempXlsPath, includeHiddenRows=false ); var expected = QueryNew( "column1", "VarChar", [ [ "Banana" ], [ "Carrot" ], [ "Doughnut" ] ] ); expect( actual ).toBe( expected ); - }); + }) - it( "Returns an empty query if the spreadsheet is empty even if headerRow is specified", function(){ + it( "Returns an empty query if the spreadsheet is empty even if headerRow is specified", ()=>{ s.newChainable( "xlsx" ) .write( tempXlsPath, true ); var actual = s.readLargeFile( src=tempXlsPath, headerRow=1 ); var expected = QueryNew( "" ); expect( actual ).toBe( expected ); - }); + }) - it( "Returns an empty query if excluding hidden columns and ALL columns are hidden", function(){ + it( "Returns an empty query if excluding hidden columns and ALL columns are hidden", ()=>{ s.newChainable( "xlsx" ) .addColumn( "a1" ) .addColumn( "b1" ) @@ -212,31 +212,31 @@ describe( "readLargeFile", function(){ var actual = s.readLargeFile( src=tempXlsPath, includeHiddenColumns=false ); var expected = QueryNew( "" ); expect( actual ).toBe( expected ); - }); + }) - it( "Returns a query with column names but no rows if column names are specified but spreadsheet is empty", function(){ + it( "Returns a query with column names but no rows if column names are specified but spreadsheet is empty", ()=>{ s.newChainable( "xlsx" ).write( tempXlsxPath, true ); var actual = s.readLargeFile( src=tempXlsxPath, queryColumnNames="One,Two" ); var expected = QueryNew( "One,Two","Varchar,Varchar", [] ); expect( actual ).toBe( expected ); - }); + }) - it( "Can read an encrypted XLSX file", function(){ + it( "Can read an encrypted XLSX file", ()=>{ var path = getTestFilePath( "passworded.xlsx" ); var expected = QueryNew( "column1", "VarChar", [ [ "secret" ] ] ); var actual = s.readLargeFile( src=path, password="pass" ); expect( actual ).toBe( expected ); - }); + }) - it( "Can read a spreadsheet containing a CACHED (i.e. pre-evaluated) formula", function(){ + it( "Can read a spreadsheet containing a CACHED (i.e. pre-evaluated) formula", ()=>{ /* NB: Setting a formula with POI does not cache its value. The Streaming Reader cannot evaluate formulas */ var path = getTestFilePath( "formula.xlsx" ); var expected = QueryNew( "column1","Integer", [ [ 1 ], [ 1 ], [ 2 ] ] ); var actual = s.readLargeFile( path ); expect( actual ).toBe( expected ); - }); + }) - it( "Returns raw cell values by default", function() { + it( "Returns raw cell values by default", ()=>{ var rawValue = 0.000011; s.newChainable( "xlsx" ) .setCellValue( rawValue, 1, 1, "numeric" ) @@ -244,9 +244,9 @@ describe( "readLargeFile", function(){ .write( tempXlsxPath, true ); var actual = s.readLargeFile( tempXlsxPath ); expect( actual.column1 ).toBe( rawValue ); - }); + }) - it( "Can return visible/formatted values rather than raw values", function() { + it( "Can return visible/formatted values rather than raw values", ()=>{ var rawValue = 0.000011; var visibleValue = 0.00001; s.newChainable( "xlsx" ) @@ -255,40 +255,40 @@ describe( "readLargeFile", function(){ .write( tempXlsxPath, true ); var actual = s.readLargeFile( src=tempXlsxPath, returnVisibleValues=true ); expect( actual.column1 ).toBe( visibleValue ); - }); + }) - describe( "query column name setting", function() { + describe( "query column name setting", ()=>{ - it( "Allows column names to be specified as a list when reading a sheet into a query", function(){ + it( "Allows column names to be specified as a list when reading a sheet into a query", ()=>{ s.newChainable( "xlsx" ).addRow( "a,b" ).write( tempXlsxPath, true ); var actual = s.readLargeFile( src=tempXlsxPath, queryColumnNames="One,Two" ); var expected = QueryNew( "One,Two","Varchar,Varchar", [ "a", "b" ] ); expect( actual ).toBe( expected ); - }); + }) - it( "Allows column names to be specified as an array when reading a sheet into a query", function(){ + it( "Allows column names to be specified as an array when reading a sheet into a query", ()=>{ s.newChainable( "xlsx" ).addRow( "a,b" ).write( tempXlsxPath, true ); var actual = s.readLargeFile( src=tempXlsxPath, queryColumnNames=[ "One", "Two" ] ); var expected = QueryNew( "One,Two","Varchar,Varchar", [ "a", "b" ] ); expect( actual ).toBe( expected ); - }); + }) - it( "ColumnNames list overrides headerRow: none of the header row values will be used", function(){ + it( "ColumnNames list overrides headerRow: none of the header row values will be used", ()=>{ s.newChainable( "xlsx" ).addRow( "a,b" ).addRow( "c,d" ).write( tempXlsxPath, true ); var actual = s.readLargeFile( src=tempXlsxPath, queryColumnNames="One,Two", headerRow=1 ); var expected = QueryNew( "One,Two","Varchar,Varchar", [ "c", "d" ] ); expect( actual ).toBe( expected ); - }); + }) - it( "can handle column names containing commas or spaces", function(){ + it( "can handle column names containing commas or spaces", ()=>{ var path = getTestFilePath( "commaAndSpaceInColumnHeaders.xlsx" ); var actual = s.readLargeFile( src=path, headerRow=1 ); var columnNames = [ "first name", "surname,comma" ];// these are the file column headers expect( actual.getColumnNames()[ 1 ] ).toBe( columnNames[ 1 ] ); expect( actual.getColumnNames()[ 2 ] ).toBe( columnNames[ 2 ] ); - }); + }) - it( "Allows header names to be made safe for query column names", function(){ + it( "Allows header names to be made safe for query column names", ()=>{ var data = [ [ "id","id","A B","x/?y","(a)"," A","##1","1a" ], [ 1,2,3,4,5,6,7,8 ] ]; s.newChainable( "xlsx" ).addRows( data ).write( tempXlsxPath, true ); var q = s.readLargeFile( src=tempXlsxPath, headerRow=1, makeColumnNamesSafe=true ); @@ -296,9 +296,9 @@ describe( "readLargeFile", function(){ cfloop( from=1, to=expected.Len(), index="i" ){ expect( q.getColumnNames()[ i ] ).toBe( expected[ i ] ); } - }); + }) - it( "Generates default column names if the data has more columns than the specifed column names", function(){ + it( "Generates default column names if the data has more columns than the specifed column names", ()=>{ var columnNames = [ "firstColumn" ]; var dataRow1 = [ "row 1 col 1 value" ]; var dataRow2 = [ "row 2 col 1 value", "row 2 col 2 value" ]; @@ -310,13 +310,13 @@ describe( "readLargeFile", function(){ s.newChainable( "xlsx" ).addRow( dataRow1 ).addRow( dataRow2 ).write( tempXlsxPath, true ); var actual = s.readLargeFile( src=tempXlsxPath, queryColumnNames=columnNames ); expect( actual ).toBe( expected ); - }); + }) - }); + }) - describe( "query column type setting", function(){ + describe( "query column type setting", ()=>{ - it( "allows the query column types to be manually set using list", function(){ + it( "allows the query column types to be manually set using list", ()=>{ s.newChainable( "xlsx" ).addRow( [ 1, 1.1, "string", _CreateTime( 1, 0, 0 ) ] ).write( tempXlsxPath, true ); var q = s.readLargeFile( src=tempXlsxPath, queryColumnTypes="Integer,Double,VarChar,Time" ); var columns = GetMetaData( q ); @@ -324,9 +324,9 @@ describe( "readLargeFile", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be manually set where the column order isn't known, but the header row values are", function(){ + it( "allows the query column types to be manually set where the column order isn't known, but the header row values are", ()=>{ s.newChainable( "xlsx" ) .addRows( [ [ "integer", "double", "string column", "time" ], [ 1, 1.1, "text", _CreateTime( 1, 0, 0 ) ] ] ) .write( tempXlsxPath, true ); @@ -337,9 +337,9 @@ describe( "readLargeFile", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be manually set where the column order isn't known, but the column names are", function(){ + it( "allows the query column types to be manually set where the column order isn't known, but the column names are", ()=>{ s.newChainable( "xlsx" ).addRows( [ [ 1, 1.1, "text", _CreateTime( 1, 0, 0 ) ] ] ).write( tempXlsxPath, true ); var columnNames = "integer,double,string column,time"; var columnTypes = { "string": "VARCHAR", "integer": "INTEGER", "time": "TIME", "double": "DOUBLE" };//not in order @@ -349,9 +349,9 @@ describe( "readLargeFile", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIME" ); - }); + }) - it( "allows the query column types to be automatically set", function(){ + it( "allows the query column types to be automatically set", ()=>{ s.newChainable( "xlsx" ).addRow( [ 1, 1.1, "string", Now() ] ).write( tempXlsxPath, true ); var q = s.readLargeFile( src=tempXlsxPath, queryColumnTypes="auto" ); var columns = GetMetaData( q ); @@ -359,9 +359,9 @@ describe( "readLargeFile", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIMESTAMP" ); - }); + }) - it( "automatic detecting of query column types ignores blank cells", function(){ + it( "automatic detecting of query column types ignores blank cells", ()=>{ var data = [ [ "", "", "", "" ], [ "", 2, "test", Now() ], @@ -375,9 +375,9 @@ describe( "readLargeFile", function(){ expect( columns[ 2 ].typeName ).toBe( "DOUBLE" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "TIMESTAMP" ); - }); + }) - it( "allows a default type to be set for all query columns", function(){ + it( "allows a default type to be set for all query columns", ()=>{ s.newChainable( "xlsx" ).addRow( [ 1, 1.1, "string", Now() ] ).write( tempXlsxPath, true ); var q = s.readLargeFile( src=tempXlsxPath, queryColumnTypes="VARCHAR" ); var columns = GetMetaData( q ); @@ -385,62 +385,62 @@ describe( "readLargeFile", function(){ expect( columns[ 2 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 3 ].typeName ).toBe( "VARCHAR" ); expect( columns[ 4 ].typeName ).toBe( "VARCHAR" ); - }); + }) - }); + }) - describe( "readLargeFile throws an exception if", function(){ + describe( "readLargeFile throws an exception if", ()=>{ - it( "the file doesn't exist", function(){ - expect( function(){ + it( "the file doesn't exist", ()=>{ + expect( ()=>{ var path = getTestFilePath( "nonexistent.xls" ); s.readLargeFile( src=path ); }).toThrow( type="cfsimplicity.spreadsheet.nonExistentFile" ); - }); + }) - it( "the file to be read is not an XLSX type", function(){ - expect( function(){ + it( "the file to be read is not an XLSX type", ()=>{ + expect( ()=>{ var path = getTestFilePath( "test.xls" ); s.readLargeFile( src=path ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSpreadsheetType" ); - }); + }) - it( "both sheetName and sheetNumber arguments are specified", function(){ - expect( function(){ + it( "both sheetName and sheetNumber arguments are specified", ()=>{ + expect( ()=>{ var path = getTestFilePath( "large.xlsx" ); s.readLargeFile( src=path, sheetName="sheet1", sheetNumber=2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArguments" ); - }); + }) - it( "the format argument is invalid", function(){ - expect( function(){ + it( "the format argument is invalid", ()=>{ + expect( ()=>{ s.readLargeFile( src=getTestFilePath( "large.xlsx" ), format="wrong" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidReadFormat" ); - }); + }) - it( "the sheet name doesn't exist", function(){ - expect( function(){ + it( "the sheet name doesn't exist", ()=>{ + expect( ()=>{ s.readLargeFile( src=getTestFilePath( "large.xlsx" ), sheetName="nonexistent" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); + }) - it( "the sheet number doesn't exist", function(){ - expect( function(){ + it( "the sheet number doesn't exist", ()=>{ + expect( ()=>{ s.readLargeFile( src=getTestFilePath( "large.xlsx" ), sheetNumber=20 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - }); + }) - it( "the source file is not a spreadsheet", function(){ - expect( function(){ + it( "the source file is not a spreadsheet", ()=>{ + expect( ()=>{ s.readLargeFile( src=getTestFilePath( "notaspreadsheet.txt" ) ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSpreadsheetType" ); - }); + }) - }); + }) - describe( "the streaming reader", function(){ + describe( "the streaming reader", ()=>{ - it( "allows options to be passed", function(){ + it( "allows options to be passed", ()=>{ var options = { bufferSize: 512 ,rowCacheSize: 5 @@ -448,14 +448,14 @@ describe( "readLargeFile", function(){ var builder = s.getStreamingReaderHelper().getBuilder( options ); expect( builder.getBufferSize() ).toBe( options.bufferSize ); expect( builder.getRowCacheSize() ).toBe( options.rowCacheSize ); - }); + }) - }); + }) - afterEach( function(){ + afterEach( ()=>{ if( FileExists( variables.tempXlsxPath ) ) FileDelete( variables.tempXlsxPath ); - }); + }) } ); diff --git a/test/specs/removeSheet.cfm b/test/specs/removeSheet.cfm index 29bfe68..818b098 100644 --- a/test/specs/removeSheet.cfm +++ b/test/specs/removeSheet.cfm @@ -1,46 +1,46 @@ -describe( "removeSheet", function(){ +describe( "removeSheet", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Deletes the sheet name specified", function(){ - workbooks.Each( function( wb ){ + it( "Deletes the sheet name specified", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .removeSheet( wb, "test" ); expect( wb.getNumberOfSheets() ).toBe( 1 ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .createSheet( "test" ) .removeSheet( "test" ); expect( wb.getNumberOfSheets() ).toBe( 1 ); - }); - }); + }) + }) - describe( "removeSheet throws an exception if", function(){ + describe( "removeSheet throws an exception if", ()=>{ - it( "the sheet name contains invalid characters", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet name contains invalid characters", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.removeSheet( wb, "[]?*\/:" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidCharacters" ); - }); - }); + }) + }) - it( "the sheet name doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet name doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.removeSheet( wb, "test" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/removeSheetNumber.cfm b/test/specs/removeSheetNumber.cfm index d096638..eefa9ee 100644 --- a/test/specs/removeSheetNumber.cfm +++ b/test/specs/removeSheetNumber.cfm @@ -1,38 +1,38 @@ -describe( "removeSheetNumber", function(){ +describe( "removeSheetNumber", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Deletes the sheet number specified", function(){ - workbooks.Each( function( wb ){ + it( "Deletes the sheet number specified", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .removeSheetNumber( wb, 2 ); expect( wb.getNumberOfSheets() ).toBe( 1 ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .createSheet( "test" ) .removeSheetNumber( 2 ); expect( wb.getNumberOfSheets() ).toBe( 1 ); - }); - }); + }) + }) - describe( "removeSheetNumber throws an exception if", function(){ + describe( "removeSheetNumber throws an exception if", ()=>{ - it( "the sheet number doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet number doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.removeSheetNumber( wb, 20 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/renameSheet.cfm b/test/specs/renameSheet.cfm index bd88753..dd47dfb 100644 --- a/test/specs/renameSheet.cfm +++ b/test/specs/renameSheet.cfm @@ -1,37 +1,37 @@ -describe( "renameSheet", function(){ +describe( "renameSheet", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Renames the specified sheet", function(){ - workbooks.Each( function( wb ){ + it( "Renames the specified sheet", ()=>{ + workbooks.Each( ( wb )=>{ s.renameSheet( wb, "test", 1 ); expect( s.getSheetHelper().sheetExists( wb, "test" ) ).toBeTrue(); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).renameSheet( "test", 1 ); expect( s.getSheetHelper().sheetExists( wb, "test" ) ).toBeTrue(); - }); - }); + }) + }) - describe( "renameSheet throws an exception if", function(){ + describe( "renameSheet throws an exception if", ()=>{ - it( "the new sheet name already exists", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the new sheet name already exists", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.createSheet( wb, "test" ) .createSheet( wb, "test2" ) .renameSheet( wb, "test2", 2 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/richText.cfm b/test/specs/richText.cfm index 19dc6ac..773b165 100644 --- a/test/specs/richText.cfm +++ b/test/specs/richText.cfm @@ -1,90 +1,90 @@ -describe( "rich text formatting", function(){ +describe( "rich text formatting", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.path = getTestFilePath( "formatting.xls" ); actual = s.read( src=path, format="query", includeRichTextFormatting="true" ); - }); + }) - it( "parses line 1: whole cell unformatted", function(){ + it( "parses line 1: whole cell unformatted", ()=>{ var expected = "unformatted"; expect( actual.column1[ 1 ] ).toBe( expected ); - }); + }) - it( "parses line 2: whole cell bold", function(){ + it( "parses line 2: whole cell bold", ()=>{ var expected = 'bold'; expect( actual.column1[ 2 ] ).toBe( expected ); - }); + }) - it( "parses line 3: whole cell red", function(){ + it( "parses line 3: whole cell red", ()=>{ var expected = 'red'; expect( actual.column1[ 3 ] ).toBe( expected ); - }); + }) - it( "parses line 4: whole cell italic", function(){ + it( "parses line 4: whole cell italic", ()=>{ var expected = 'italic'; expect( actual.column1[ 4 ] ).toBe( expected ); - }); + }) - it( "parses line 5: whole cell strike", function(){ + it( "parses line 5: whole cell strike", ()=>{ var expected = 'strike'; expect( actual.column1[ 5 ] ).toBe( expected ); - }); + }) - it( "parses line 6: whole cell underline", function(){ + it( "parses line 6: whole cell underline", ()=>{ var expected = 'underline'; expect( actual.column1[ 6 ] ).toBe( expected ); - }); + }) - it( "parses line 7: whole cell bold red italic strike underline", function(){ + it( "parses line 7: whole cell bold red italic strike underline", ()=>{ var expected = 'bold red italic strike underline'; expect( actual.column1[ 7 ] ).toBe( expected ); - }); + }) - it( "parses line 8: unformatted + bold", function(){ + it( "parses line 8: unformatted + bold", ()=>{ var expected = 'unformattedbold'; expect( actual.column1[ 8 ] ).toBe( expected ); - }); + }) - it( "parses line 9: unformatted + red", function(){ + it( "parses line 9: unformatted + red", ()=>{ var expected = 'unformattedred'; expect( actual.column1[ 9 ] ).toBe( expected ); - }); + }) - it( "parses line 10: unformatted + italic", function(){ + it( "parses line 10: unformatted + italic", ()=>{ var expected = 'unformatteditalic'; expect( actual.column1[ 10 ] ).toBe( expected ); - }); + }) - it( "parses line 11: unformatted + strike", function(){ + it( "parses line 11: unformatted + strike", ()=>{ var expected = 'unformattedstrike'; expect( actual.column1[ 11 ] ).toBe( expected ); - }); + }) - it( "parses line 12: unformatted underline", function(){ + it( "parses line 12: unformatted underline", ()=>{ var expected = 'unformattedunderline'; expect( actual.column1[ 12 ] ).toBe( expected ); - }); + }) - it( "parses line 13: unformatted + bold red italic strike underline", function(){ + it( "parses line 13: unformatted + bold red italic strike underline", ()=>{ var expected = 'unformattedbold red italic strike underline'; expect( actual.column1[ 13 ] ).toBe( expected ); - }); + }) - it( "parses line 14: unformatted + shadow (= unsupported style)", function(){ + it( "parses line 14: unformatted + shadow (= unsupported style)", ()=>{ var expected = 'unformattedShadow'; expect( actual.column1[ 14 ] ).toBe( expected ); - }); + }) - it( "parses line 15: bold + unformatted", function(){ + it( "parses line 15: bold + unformatted", ()=>{ var expected = 'boldunformatted'; expect( actual.column1[ 15 ] ).toBe( expected ); - }); + }) - it( "parses line 16: bold + red + italic + strike + underline", function(){ + it( "parses line 16: bold + red + italic + strike + underline", ()=>{ var expected = 'boldreditalicstrikeunderline'; expect( actual.column1[ 16 ] ).toBe( expected ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setActiveCell.cfm b/test/specs/setActiveCell.cfm index 5d26dc8..4bef616 100644 --- a/test/specs/setActiveCell.cfm +++ b/test/specs/setActiveCell.cfm @@ -1,26 +1,26 @@ -describe( "setActiveCell", function(){ +describe( "setActiveCell", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "1,1" ); - }); - }); + }) + }) - it( "Sets the active cell on the current active sheet by default", function(){ - workbooks.Each( function( wb ){ + it( "Sets the active cell on the current active sheet by default", ()=>{ + workbooks.Each( ( wb )=>{ s.setActiveCell( wb, 2, 1 ); expect( s.getSheetHelper().getActiveSheet( wb ).getActiveCell().toString() ).toBe( "A2" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).setActiveCell( 2, 1 ); expect( s.getSheetHelper().getActiveSheet( wb ).getActiveCell().toString() ).toBe( "A2" ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setActiveSheet.cfm b/test/specs/setActiveSheet.cfm index 5599ffb..06a3b45 100644 --- a/test/specs/setActiveSheet.cfm +++ b/test/specs/setActiveSheet.cfm @@ -1,54 +1,54 @@ -describe( "setActiveSheet", function(){ +describe( "setActiveSheet", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Sets the specified sheet number to be active", function(){ - workbooks.Each( function( wb ){ + it( "Sets the specified sheet number to be active", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .setActiveSheet( workbook=wb, sheetNumber=2 ); expect( s.getSheetHelper().getActiveSheetName( wb ) ).toBe( "test" ); - }); - }); + }) + }) - it( "Sets the specified sheet name to be active", function(){ - workbooks.Each( function( wb ){ + it( "Sets the specified sheet name to be active", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .setActiveSheet( workbook=wb, sheetName="test" ); expect( s.getSheetHelper().getActiveSheetName( wb ) ).toBe( "test" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .createSheet( "test" ) .setActiveSheet( sheetName="test" ); expect( s.getSheetHelper().getActiveSheetName( wb ) ).toBe( "test" ); - }); - }); + }) + }) - describe( "setActiveSheet throws an exception if", function(){ + describe( "setActiveSheet throws an exception if", ()=>{ - it( "the sheet name doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet name doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.setActiveSheet( workbook=wb, sheetName="test" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); - }); - }); + }) + }) - it( "the sheet number doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet number doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.setActiveSheet( workbook=wb, sheetNumber=20 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setActiveSheetNumber.cfm b/test/specs/setActiveSheetNumber.cfm index 692fa94..0336bf2 100644 --- a/test/specs/setActiveSheetNumber.cfm +++ b/test/specs/setActiveSheetNumber.cfm @@ -1,38 +1,38 @@ -describe( "setActiveSheetNumber", function(){ +describe( "setActiveSheetNumber", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "Sets the specified sheet number to be active", function(){ - workbooks.Each( function( wb ){ + it( "Sets the specified sheet number to be active", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .setActiveSheetNumber( wb, 2 ); expect( s.getSheetHelper().getActiveSheetName( wb ) ).toBe( "test" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .createSheet( "test" ) .setActiveSheetNumber( 2 ); expect( s.getSheetHelper().getActiveSheetName( wb ) ).toBe( "test" ); - }); - }); + }) + }) - describe( "setActiveSheetNumber throws an exception if", function(){ + describe( "setActiveSheetNumber throws an exception if", ()=>{ - it( "the sheet number doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the sheet number doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.setActiveSheetNumber( wb, 20 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setFitToPage.cfm b/test/specs/setFitToPage.cfm index f41b966..07a5654 100644 --- a/test/specs/setFitToPage.cfm +++ b/test/specs/setFitToPage.cfm @@ -1,12 +1,12 @@ -describe( "setFitToPage", function(){ +describe( "setFitToPage", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "sets the active sheet's print setup to fit everything in one page by default", function(){ - workbooks.Each( function( wb ){ + it( "sets the active sheet's print setup to fit everything in one page by default", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); s.setFitToPage( wb, false ); expect( sheet.getFitToPage() ).toBeFalse(); @@ -14,21 +14,21 @@ describe( "setFitToPage", function(){ expect( sheet.getFitToPage() ).toBeTrue(); expect( sheet.getPrintSetup().getFitWidth() ).toBe( 1 ); expect( sheet.getPrintSetup().getFitHeight() ).toBe( 1 ); - }); - }); + }) + }) - it( "allows the number of pages wide and high to be specified", function(){ - workbooks.Each( function( wb ){ + it( "allows the number of pages wide and high to be specified", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); s.setFitToPage( wb, true, 2, 0 ); expect( sheet.getFitToPage() ).toBeTrue(); expect( sheet.getPrintSetup().getFitWidth() ).toBe( 2 ); expect( sheet.getPrintSetup().getFitHeight() ).toBe( 0 ); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); s.newChainable( wb ).setFitToPage( false ); expect( sheet.getFitToPage() ).toBeFalse(); @@ -36,8 +36,8 @@ describe( "setFitToPage", function(){ expect( sheet.getFitToPage() ).toBeTrue(); expect( sheet.getPrintSetup().getFitWidth() ).toBe( 1 ); expect( sheet.getPrintSetup().getFitHeight() ).toBe( 1 ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setFooter.cfm b/test/specs/setFooter.cfm index fd28986..278951f 100644 --- a/test/specs/setFooter.cfm +++ b/test/specs/setFooter.cfm @@ -1,12 +1,12 @@ -describe( "setFooter", function(){ +describe( "setFooter", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "adds text to the left, centre or right footer", function() { - workbooks.Each( function( wb ) { + it( "adds text to the left, centre or right footer", ()=>{ + workbooks.Each( ( wb )=>{ var leftText = "I'm on the left"; var centerText = "I'm in the middle"; var rightText = "I'm on the right"; @@ -15,11 +15,11 @@ describe( "setFooter", function(){ expect( footer.getLeft() ).toBe( leftText ); expect( footer.getCenter() ).toBe( centerText ); expect( footer.getRight() ).toBe( rightText ); - }); - }); + }) + }) - it( "is chainable", function() { - workbooks.Each( function( wb ) { + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var leftText = "I'm on the left"; var centerText = "I'm in the middle"; var rightText = "I'm on the right"; @@ -29,8 +29,8 @@ describe( "setFooter", function(){ expect( footer.getLeft() ).toBe( leftText ); expect( footer.getCenter() ).toBe( centerText ); expect( footer.getRight() ).toBe( rightText ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setFooterImage.cfm b/test/specs/setFooterImage.cfm index 4afbd62..5af563e 100644 --- a/test/specs/setFooterImage.cfm +++ b/test/specs/setFooterImage.cfm @@ -1,7 +1,7 @@ -describe( "setFooterImage", function(){ +describe( "setFooterImage", ()=>{ - it( "adds an image to the left, centre or right footer from a file path", function() { + it( "adds an image to the left, centre or right footer from a file path", ()=>{ var imagePath = getTestFilePath( "test.png" ); var wb = s.newXlsx(); s.setFooterImage( wb, "left", imagePath ); @@ -15,17 +15,17 @@ describe( "setFooterImage", function(){ s.setFooterImage( wb, "right", imagePath ); footer = s.getSheetHelper().getActiveSheetFooter( wb ); expect( footer.getRight() ).toBe( "&G" ); - }); + }) - it( "is chainable", function() { + it( "is chainable", ()=>{ var imagePath = getTestFilePath( "test.png" ); var wb = s.newXlsx(); s.newChainable( wb ).setFooterImage( "left", imagePath ); var footer = s.getSheetHelper().getActiveSheetFooter( wb ); expect( footer.getLeft() ).toBe( "&G" );//Graphic - }); + }) - it( "adds an image to the left, centre or right footer from a cfml image object", function() { + it( "adds an image to the left, centre or right footer from a cfml image object", ()=>{ var imageData = ImageNew( "", 10, 10, "rgb", "blue" ); var wb = s.newXlsx(); s.setFooterImage( wb, "left", imageData, "png" ); @@ -39,30 +39,30 @@ describe( "setFooterImage", function(){ s.setFooterImage( wb, "right", imageData, "png" ); footer = s.getSheetHelper().getActiveSheetFooter( wb ); expect( footer.getRight() ).toBe( "&G" ); - }); + }) - describe( "throws an exception if", function(){ + describe( "throws an exception if", ()=>{ - it( "the workbook is not XLSX", function(){ - expect( function(){ + it( "the workbook is not XLSX", ()=>{ + expect( ()=>{ s.setFooterImage( s.newXls(), "left", getTestFilePath( "test.png" ) ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSpreadsheetType" ); - }); + }) - it( "the position argument is invalid", function(){ - expect( function(){ + it( "the position argument is invalid", ()=>{ + expect( ()=>{ s.setFooterImage( s.newXlsx(), "wrong", getTestFilePath( "test.png" ) ); }).toThrow( type="cfsimplicity.spreadsheet.invalidPositionArgument" ); - }); + }) - it( "the spreadsheet already has a header or footer image", function(){ - expect( function(){ + it( "the spreadsheet already has a header or footer image", ()=>{ + expect( ()=>{ var wb = s.read( getTestFilePath( "hasHeaderImage.xlsx" ) ); s.setFooterImage( wb, "left", getTestFilePath( "test.png" ) ); }).toThrow( type="cfsimplicity.spreadsheet.existingHeaderOrFooter" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setHeader.cfm b/test/specs/setHeader.cfm index bb8cb81..a4bcd49 100644 --- a/test/specs/setHeader.cfm +++ b/test/specs/setHeader.cfm @@ -1,12 +1,12 @@ -describe( "setHeader", function(){ +describe( "setHeader", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "adds text to the left, centre or right header", function() { - workbooks.Each( function( wb ) { + it( "adds text to the left, centre or right header", ()=>{ + workbooks.Each( ( wb )=>{ var leftText = "I'm on the left"; var centerText = "I'm in the middle"; var rightText = "I'm on the right"; @@ -15,11 +15,11 @@ describe( "setHeader", function(){ expect( header.getLeft() ).toBe( leftText ); expect( header.getCenter() ).toBe( centerText ); expect( header.getRight() ).toBe( rightText ); - }); - }); + }) + }) - it( "is chainable", function() { - workbooks.Each( function( wb ) { + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var leftText = "I'm on the left"; var centerText = "I'm in the middle"; var rightText = "I'm on the right"; @@ -29,8 +29,8 @@ describe( "setHeader", function(){ expect( header.getLeft() ).toBe( leftText ); expect( header.getCenter() ).toBe( centerText ); expect( header.getRight() ).toBe( rightText ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setHeaderImage.cfm b/test/specs/setHeaderImage.cfm index 7f6a3f0..f413d35 100644 --- a/test/specs/setHeaderImage.cfm +++ b/test/specs/setHeaderImage.cfm @@ -1,7 +1,7 @@ -describe( "setHeaderImage", function(){ +describe( "setHeaderImage", ()=>{ - it( "adds an image to the left, centre or right header from a file path", function() { + it( "adds an image to the left, centre or right header from a file path", ()=>{ var imagePath = getTestFilePath( "test.png" ); var wb = s.newXlsx(); s.setHeaderImage( wb, "left", imagePath ); @@ -15,17 +15,17 @@ describe( "setHeaderImage", function(){ s.setHeaderImage( wb, "right", imagePath ); header = s.getSheetHelper().getActiveSheetHeader( wb ); expect( header.getRight() ).toBe( "&G" ); - }); + }) - it( "is chainable", function() { + it( "is chainable", ()=>{ var imagePath = getTestFilePath( "test.png" ); var wb = s.newXlsx(); s.newChainable( wb ).setHeaderImage( "left", imagePath ); var header = s.getSheetHelper().getActiveSheetHeader( wb ); expect( header.getLeft() ).toBe( "&G" );//Graphic - }); + }) - it( "adds an image to the left, centre or right header from a cfml image object", function() { + it( "adds an image to the left, centre or right header from a cfml image object", ()=>{ var imageData = ImageNew( "", 10, 10, "rgb", "blue" ); var wb = s.newXlsx(); s.setHeaderImage( wb, "left", imageData, "png" ); @@ -39,30 +39,30 @@ describe( "setHeaderImage", function(){ s.setHeaderImage( wb, "right", imageData, "png" ); header = s.getSheetHelper().getActiveSheetHeader( wb ); expect( header.getRight() ).toBe( "&G" ); - }); + }) - describe( "throws an exception if", function(){ + describe( "throws an exception if", ()=>{ - it( "the workbook is not XLSX", function(){ - expect( function(){ + it( "the workbook is not XLSX", ()=>{ + expect( ()=>{ s.setHeaderImage( s.newXls(), "left", getTestFilePath( "test.png" ) ); }).toThrow( type="cfsimplicity.spreadsheet.invalidSpreadsheetType" ); - }); + }) - it( "the position argument is invalid", function(){ - expect( function(){ + it( "the position argument is invalid", ()=>{ + expect( ()=>{ s.setHeaderImage( s.newXlsx(), "wrong", getTestFilePath( "test.png" ) ); }).toThrow( type="cfsimplicity.spreadsheet.invalidPositionArgument" ); - }); + }) - it( "the spreadsheet already has a header or footer image", function(){ - expect( function(){ + it( "the spreadsheet already has a header or footer image", ()=>{ + expect( ()=>{ var wb = s.read( getTestFilePath( "hasHeaderImage.xlsx" ) ); s.setHeaderImage( wb, "left", getTestFilePath( "test.png" ) ); }).toThrow( type="cfsimplicity.spreadsheet.existingHeaderOrFooter" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setRepeatingColumns.cfm b/test/specs/setRepeatingColumns.cfm index c8c8e95..ab89db1 100644 --- a/test/specs/setRepeatingColumns.cfm +++ b/test/specs/setRepeatingColumns.cfm @@ -1,30 +1,30 @@ -describe( "setRepeatingColumns", function(){ +describe( "setRepeatingColumns", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var query = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var xls = s.workbookFromQuery( query ); var xlsx = s.workbookFromQuery( data=query, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "Specifies columns that should appear on every page when the current sheet is printed.", function(){ - workbooks.Each( function( wb ){ + it( "Specifies columns that should appear on every page when the current sheet is printed.", ()=>{ + workbooks.Each( ( wb )=>{ // Make column1 repeat on every page s.setRepeatingColumns( wb, "A:A" ); var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getRepeatingColumns().formatAsString() ).toBe( "A:A" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ // Make column1 repeat on every page s.newChainable( wb ).setRepeatingColumns( "A:A" ); var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getRepeatingColumns().formatAsString() ).toBe( "A:A" ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setRepeatingRows.cfm b/test/specs/setRepeatingRows.cfm index 96e2756..4ee8e39 100644 --- a/test/specs/setRepeatingRows.cfm +++ b/test/specs/setRepeatingRows.cfm @@ -1,29 +1,29 @@ -describe( "setRepeatingRows", function(){ +describe( "setRepeatingRows", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var query = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var xls = s.workbookFromQuery( query ); var xlsx = s.workbookFromQuery( data=query, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "Specifies rows that should appear on every page when the current sheet is printed.", function(){ - workbooks.Each( function( wb ){ + it( "Specifies rows that should appear on every page when the current sheet is printed.", ()=>{ + workbooks.Each( ( wb )=>{ // Make header repeat on every page s.setRepeatingRows( wb, "1:1" ); var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getRepeatingRows().formatAsString() ).toBe( "1:1" ); - }); - }); + }) + }) - it( "Is chainable", function(){ - workbooks.Each( function( wb ){ + it( "Is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).setRepeatingRows( "1:1" ); var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getRepeatingRows().formatAsString() ).toBe( "1:1" ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setRowHeight.cfm b/test/specs/setRowHeight.cfm index b3e185b..8021d09 100644 --- a/test/specs/setRowHeight.cfm +++ b/test/specs/setRowHeight.cfm @@ -1,41 +1,41 @@ -describe( "setRowHeight", function(){ +describe( "setRowHeight", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var query = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var xls = s.workbookFromQuery( query ); var xlsx = s.workbookFromQuery( data=query, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; variables.newHeight = 30; - }); + }) - it( "Sets the height of a row in points.", function(){ - workbooks.Each( function( wb ){ + it( "Sets the height of a row in points.", ()=>{ + workbooks.Each( ( wb )=>{ s.setRowHeight( wb, 2, newHeight ); var row = s.getRowHelper().getRowFromActiveSheet( wb, 2 ); expect( row.getHeightInPoints() ).toBe( newHeight ); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).setRowHeight( 2, newHeight ); var row = s.getRowHelper().getRowFromActiveSheet( wb, 2 ); expect( row.getHeightInPoints() ).toBe( newHeight ); - }); - }); + }) + }) - describe( "setRowHeight throws an exception if", function(){ + describe( "setRowHeight throws an exception if", ()=>{ - it( "the specified row doesn't exist", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the specified row doesn't exist", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.setRowHeight( wb, 10, newHeight ); }).toThrow( type="cfsimplicity.spreadsheet.nonExistentRow" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setSheetMargins.cfm b/test/specs/setSheetMargins.cfm index 3f1b699..e04e5a7 100644 --- a/test/specs/setSheetMargins.cfm +++ b/test/specs/setSheetMargins.cfm @@ -1,12 +1,12 @@ -describe( "setSheetMargin methods", function(){ +describe( "setSheetMargin methods", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "by default set the active sheet margins", function(){ - workbooks.Each( function( wb ){ + it( "by default set the active sheet margins", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); s.setSheetTopMargin( wb, 3 ); expect( sheet.getMargin( sheet.TopMargin ) ).toBe( 3 ); @@ -20,11 +20,11 @@ describe( "setSheetMargin methods", function(){ expect( sheet.getMargin( sheet.HeaderMargin ) ).toBe( 3 ); s.setSheetFooterMargin( wb, 3 ); expect( sheet.getMargin( sheet.FooterMargin ) ).toBe( 3 ); - }); - }); + }) + }) - it( "are chainable", function(){ - workbooks.Each( function( wb ){ + it( "are chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .setSheetTopMargin( 3 ) .setSheetBottomMargin( 3 ) @@ -39,20 +39,20 @@ describe( "setSheetMargin methods", function(){ expect( sheet.getMargin( sheet.RightMargin ) ).toBe( 3 ); expect( sheet.getMargin( sheet.HeaderMargin ) ).toBe( 3 ); expect( sheet.getMargin( sheet.FooterMargin ) ).toBe( 3 ); - }); - }); + }) + }) - it( "set a margin of the named sheet", function(){ - workbooks.Each( function( wb ){ + it( "set a margin of the named sheet", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .setSheetTopMargin( wb, 3, "test" ); var sheet = s.getSheetHelper().getSheetByName( wb, "test" ); expect( sheet.getMargin( sheet.TopMargin ) ).toBe( 3 ); - }); - }); + }) + }) - it( "set a margin of the specified sheet number", function(){ - workbooks.Each( function( wb ){ + it( "set a margin of the specified sheet number", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ); var sheet = s.getSheetHelper().getSheetByNumber( wb, 2 ); // named arguments @@ -61,28 +61,28 @@ describe( "setSheetMargin methods", function(){ //positional s.setSheetTopMargin( wb, 4, "", 2 ); expect( sheet.getMargin( sheet.TopMargin ) ).toBe( 4 ); - }); - }); + }) + }) - it( "can set margins to floating point values", function(){ - workbooks.Each( function( wb ){ + it( "can set margins to floating point values", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); s.setSheetTopMargin( wb, 3.5 ); expect( sheet.getMargin( sheet.TopMargin ) ).toBe( 3.5 ); - }); - }); + }) + }) - describe( "setting sheet margins throws an exception if", function(){ + describe( "setting sheet margins throws an exception if", ()=>{ - it( "both sheet name and number are specified", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "both sheet name and number are specified", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.setSheetTopMargin( wb, 3, "test", 1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArguments" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/setSheetPrintOrientation.cfm b/test/specs/setSheetPrintOrientation.cfm index d1e06ea..4f0cd3a 100644 --- a/test/specs/setSheetPrintOrientation.cfm +++ b/test/specs/setSheetPrintOrientation.cfm @@ -1,41 +1,41 @@ -describe( "setSheetPrintOrientation", function(){ +describe( "setSheetPrintOrientation", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; - }); + }) - it( "by default sets the active sheet to the specified orientation", function(){ - workbooks.Each( function( wb ){ + it( "by default sets the active sheet to the specified orientation", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getPrintSetup().getLandscape() ).toBeFalse(); s.setSheetPrintOrientation( wb, "landscape" ); expect( sheet.getPrintSetup().getLandscape() ).toBeTrue(); s.setSheetPrintOrientation( wb, "portrait" ); expect( sheet.getPrintSetup().getLandscape() ).toBeFalse(); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ var sheet = s.getSheetHelper().getActiveSheet( wb ); expect( sheet.getPrintSetup().getLandscape() ).toBeFalse(); s.newChainable( wb ).setSheetPrintOrientation( "landscape" ); expect( sheet.getPrintSetup().getLandscape() ).toBeTrue(); - }); - }); + }) + }) - it( "sets the named sheet to the specified orientation", function(){ - workbooks.Each( function( wb ){ + it( "sets the named sheet to the specified orientation", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ) .setSheetPrintOrientation( wb, "landscape", "test" ); var sheet = s.getSheetHelper().getSheetByName( wb, "test" ); expect( sheet.getPrintSetup().getLandscape() ).toBeTrue(); - }); - }); + }) + }) - it( "sets the specified sheet number to the specified orientation", function(){ - workbooks.Each( function( wb ){ + it( "sets the specified sheet number to the specified orientation", ()=>{ + workbooks.Each( ( wb )=>{ s.createSheet( wb, "test" ); var sheet = s.getSheetHelper().getSheetByNumber( wb, 2 ); expect( sheet.getPrintSetup().getLandscape() ).toBeFalse(); @@ -45,28 +45,28 @@ describe( "setSheetPrintOrientation", function(){ //positional s.setSheetPrintOrientation( wb, "portrait", "", 2 ); expect( sheet.getPrintSetup().getLandscape() ).toBeFalse(); - }); - }); + }) + }) - describe( "setSheetPrintOrientation throws an exception if", function(){ + describe( "setSheetPrintOrientation throws an exception if", ()=>{ - it( "the mode is invalid", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "the mode is invalid", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.setSheetPrintOrientation( wb, "blah" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidModeArgument" ); - }); - }); + }) + }) - it( "both sheet name and number are specified", function(){ - workbooks.Each( function( wb ){ - expect( function(){ + it( "both sheet name and number are specified", ()=>{ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.setSheetPrintOrientation( wb, "landscape", "test", 1 ); }).toThrow( type="cfsimplicity.spreadsheet.invalidArguments" ); - }); - }); + }) + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/sheetInfo.cfm b/test/specs/sheetInfo.cfm index 37e8d9c..032b2fa 100644 --- a/test/specs/sheetInfo.cfm +++ b/test/specs/sheetInfo.cfm @@ -1,8 +1,8 @@ -describe( "sheetInfo", function(){ +describe( "sheetInfo", ()=>{ - it( "can get info about a specific sheet within a workbook", function(){ - variables.spreadsheetTypes.Each( function( type ){ + it( "can get info about a specific sheet within a workbook", ()=>{ + variables.spreadsheetTypes.Each( ( type )=>{ var defaults = { displaysAutomaticPageBreaks: ( type == "xlsx" )//xls=false xlsx=true ,displaysFormulas: false @@ -109,16 +109,16 @@ describe( "sheetInfo", function(){ expect( hiddenSheetInfo.isHidden ).toBeTrue(); expect( hiddenSheetInfo.name ).toBe( "hidden sheet" ); expect( hiddenSheetInfo.isCurrentActiveSheet ).toBeFalse; - }); - }); + }) + }) - it( "Returns info from the current active sheet by default", function(){ - variables.spreadsheetTypes.Each( function( type ){ + it( "Returns info from the current active sheet by default", ()=>{ + variables.spreadsheetTypes.Each( ( type )=>{ var chainable = s.newChainable( type ).createSheet( "Sheet2" ).setActiveSheet( "Sheet2" ); var actual = chainable.sheetInfo(); expect( actual.name ).toBe( "Sheet2" ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/shiftColumns.cfm b/test/specs/shiftColumns.cfm index 0fbcfc5..3d7b120 100644 --- a/test/specs/shiftColumns.cfm +++ b/test/specs/shiftColumns.cfm @@ -1,15 +1,15 @@ -describe( "shiftColumns", function(){ +describe( "shiftColumns", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var data = QueryNew( "column1,column2,column3", "VarChar,VarChar,VarChar", [ [ "a", "c", "e" ], [ "b", "d", "f" ] ] ); var xls = s.workbookFromQuery( data, false ); var xlsx = s.workbookFromQuery( xmlFormat=true, data=data, addHeaderRow=false ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "Shifts columns right if offset is positive", function(){ - workbooks.Each( function( wb ){ + it( "Shifts columns right if offset is positive", ()=>{ + workbooks.Each( ( wb )=>{ s.shiftColumns( wb, 1, 2, 1 ); var expected = querySim( "column1,column2,column3 |a|c @@ -17,11 +17,11 @@ describe( "shiftColumns", function(){ "); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Shifts columns left if offset is negative", function(){ - workbooks.Each( function( wb ){ + it( "Shifts columns left if offset is negative", ()=>{ + workbooks.Each( ( wb )=>{ s.addColumn( wb, "g,h" )//4th column to remain untouched .shiftColumns( wb, 2, 3, -1 ); var expected = querySim( "column1,column2,column3,column4 @@ -29,11 +29,11 @@ describe( "shiftColumns", function(){ d|f||h"); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).shiftColumns( 1, 2, 1 ); var expected = querySim( "column1,column2,column3 |a|c @@ -41,8 +41,8 @@ describe( "shiftColumns", function(){ "); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/shiftRows.cfm b/test/specs/shiftRows.cfm index 0546775..6ee8058 100644 --- a/test/specs/shiftRows.cfm +++ b/test/specs/shiftRows.cfm @@ -1,41 +1,41 @@ -describe( "shiftRows", function(){ +describe( "shiftRows", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.workbooks = [ s.newXls(), s.newXlsx() ]; variables.rowData = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); - }); + }) - it( "Shifts rows down if offset is positive", function(){ - workbooks.Each( function( wb ){ + it( "Shifts rows down if offset is positive", ()=>{ + workbooks.Each( ( wb )=>{ s.addRows( wb, rowData ) .shiftRows( wb, 1, 1, 1 ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "" ], [ "a", "b" ] ] ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "Shifts rows up if offset is negative", function(){ - workbooks.Each( function( wb ){ + it( "Shifts rows up if offset is negative", ()=>{ + workbooks.Each( ( wb )=>{ s.addRows( wb, rowData ) .shiftRows( wb, 2, 2, -1 ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "c", "d" ] ] ); var actual = s.getSheetHelper().sheetToQuery( wb ); expect( actual ).toBe( expected ); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ) .addRows( rowData ) .shiftRows( 1, 1, 1 ); var expected = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "", "" ], [ "a", "b" ] ] ); var actual = s.getSheetHelper().sheetToQuery( workbook=wb, includeBlankRows=true ); expect( actual ).toBe( expected ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/showColumn.cfm b/test/specs/showColumn.cfm index e7ee5f0..3334e84 100644 --- a/test/specs/showColumn.cfm +++ b/test/specs/showColumn.cfm @@ -1,30 +1,30 @@ -describe( "showColumn", function(){ +describe( "showColumn", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var query = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a","b" ], [ "c","d" ] ] ); var xls = s.workbookFromQuery( query ); var xlsx = s.workbookFromQuery( data=query, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "can show a column", function(){ - workbooks.Each( function( wb ){ + it( "can show a column", ()=>{ + workbooks.Each( ( wb )=>{ s.hideColumn( wb, 1 ); expect( s.isColumnHidden( wb, 1 ) ).toBeTrue(); s.showColumn( wb, 1 ); expect( s.isColumnHidden( wb, 1 ) ).toBeFalse(); - }); - }); + }) + }) - it( "is chainable", function(){ - workbooks.Each( function( wb ){ + it( "is chainable", ()=>{ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).hideColumn( 1 ); expect( s.isColumnHidden( wb, 1 ) ).toBeTrue(); s.newChainable( wb ).showColumn( 1 ); expect( s.isColumnHidden( wb, 1 ) ).toBeFalse(); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/showRow.cfm b/test/specs/showRow.cfm index 51f5e1d..37018b9 100644 --- a/test/specs/showRow.cfm +++ b/test/specs/showRow.cfm @@ -1,30 +1,30 @@ -describe( "showRow", function(){ +describe( "showRow", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ var query = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a","b" ], [ "c","d" ] ] ); var xls = s.workbookFromQuery( query ); var xlsx = s.workbookFromQuery( data=query, xmlFormat=true ); variables.workbooks = [ xls, xlsx ]; - }); + }) - it( "can show a row", function(){ + it( "can show a row", ()=>{ workbooks.Each( function( wb ){ s.hideRow( wb, 1 ); expect( s.isRowHidden( wb, 1 ) ).toBeTrue(); s.showRow( wb, 1 ); expect( s.isRowHidden( wb, 1 ) ).toBeFalse(); - }); - }); + }) + }) - it( "is chainable", function(){ + it( "is chainable", ()=>{ workbooks.Each( function( wb ){ s.newChainable( wb ).hideRow( 1 ); expect( s.isRowHidden( wb, 1 ) ).toBeTrue(); s.newChainable( wb ).showRow( 1 ); expect( s.isRowHidden( wb, 1 ) ).toBeFalse(); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/workbookFromCsv.cfm b/test/specs/workbookFromCsv.cfm index cdfc791..fd7e0e1 100644 --- a/test/specs/workbookFromCsv.cfm +++ b/test/specs/workbookFromCsv.cfm @@ -1,22 +1,22 @@ -describe( "workbookFromCsv", function(){ +describe( "workbookFromCsv", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.csv = 'column1,column2#newline#"Frumpo McNugget",12345'; variables.basicExpectedQuery = QueryNew( "column1,column2", "", [ [ "Frumpo McNugget", "12345" ] ] ); - }); + }) - it( "Returns a workbook from a csv", function(){ + it( "Returns a workbook from a csv", ()=>{ var xls = s.workbookFromCsv( csv=csv, firstRowIsHeader=true ); var xlsx = s.workbookFromCsv( csv=csv, firstRowIsHeader=true, xmlFormat=true ); var workbooks = [ xls, xlsx ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ actual = s.getSheetHelper().sheetToQuery( workbook=wb, headerRow=1 ); expect( actual ).toBe( basicExpectedQuery ); - }); - }); + }) + }) - it( "is chainable", function(){ + it( "is chainable", ()=>{ var xls = s.newChainable() .fromCsv( csv=csv, firstRowIsHeader=true ) .getWorkbook(); @@ -24,11 +24,11 @@ describe( "workbookFromCsv", function(){ .fromCsv( csv=csv, firstRowIsHeader=true, xmlFormat=true ) .getWorkbook(); var workbooks = [ xls, xlsx ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ actual = s.getSheetHelper().sheetToQuery( workbook=wb, headerRow=1 ); expect( actual ).toBe( basicExpectedQuery ); - }); - }); + }) + }) -}); +}) \ No newline at end of file diff --git a/test/specs/workbookFromQuery.cfm b/test/specs/workbookFromQuery.cfm index 6c41e1d..78c1bb9 100644 --- a/test/specs/workbookFromQuery.cfm +++ b/test/specs/workbookFromQuery.cfm @@ -1,36 +1,36 @@ -describe( "workbookFromQuery", function(){ +describe( "workbookFromQuery", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ variables.query = QueryNew( "Header1,Header2", "VarChar,VarChar",[ [ "a", "b" ],[ "c", "d" ] ] ); - }); + }) - it( "Returns a workbook from a query", function(){ + it( "Returns a workbook from a query", ()=>{ var workbook = s.workbookFromQuery( query ); expected = query; actual = s.getSheetHelper().sheetToQuery( workbook=workbook, headerRow=1 ); expect( actual ).toBe( expected ); - }); + }) - it( "Returns an XSSF workbook if xmlFormat is true", function(){ + it( "Returns an XSSF workbook if xmlFormat is true", ()=>{ var workbook = s.workbookFromQuery( data=query, xmlformat=true ); expect( workbook.getClass().name ).toBe( "org.apache.poi.xssf.usermodel.XSSFWorkbook" ); - }); + }) - it( "Adds the header row in the same case and order as the query columns", function(){ + it( "Adds the header row in the same case and order as the query columns", ()=>{ var query = QueryNew( "Header2,Header1", "VarChar,VarChar", [ [ "b", "a" ], [ "d", "c" ] ] ); var workbook = s.workbookFromQuery( data=local.query, addHeaderRow=true ); expect( s.getCellValue( workbook, 1, 1 ) ).toBeWithCase( "Header2" ); local.workbook = s.workbookFromQuery( data=query, xmlformat=true ); expect( s.getCellValue( workbook, 1, 1 ) ).toBeWithCase( "Header2" ); - }); + }) - it( "is chainable", function(){ + it( "is chainable", ()=>{ var workbook = s.newChainable().fromQuery( query ).getWorkbook(); expected = query; actual = s.getSheetHelper().sheetToQuery( workbook=workbook, headerRow=1 ); expect( actual ).toBe( expected ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/write.cfm b/test/specs/write.cfm index c24bd13..3b81395 100644 --- a/test/specs/write.cfm +++ b/test/specs/write.cfm @@ -1,11 +1,11 @@ -describe( "write", function(){ +describe( "write", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ Sleep( 5 );// allow time for file operations to complete - }); + }) - it( "Writes an XLS object correctly", function(){ + it( "Writes an XLS object correctly", ()=>{ data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a","b" ], [ "c","d" ] ] ); var workbook = s.newXls(); s.addRows( workbook, data ) @@ -13,9 +13,9 @@ describe( "write", function(){ var expected = data; var actual = s.read( src=tempXlsPath, format="query" ); expect( actual ).toBe( expected ); - }); + }) - it( "Writes an XLSX object correctly", function(){ + it( "Writes an XLSX object correctly", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var workbook = s.newXlsx(); s.addRows( workbook, data ) @@ -23,9 +23,9 @@ describe( "write", function(){ var expected = data; var actual = s.read( src=tempXlsxPath, format="query" ); expect( actual ).toBe( expected ); - }); + }) - it( "Writes a streaming XLSX object without error", function(){ + it( "Writes a streaming XLSX object without error", ()=>{ var rows = []; for( i=1; i <= 100; i++ ){ rows.append( { column1=i, column2="test" } ); @@ -37,9 +37,9 @@ describe( "write", function(){ var expected = data; var actual = s.read( src=tempXlsxPath, format="query" ); expect( actual ).toBe( expected ); - }); + }) - it( "is chainable", function(){ + it( "is chainable", ()=>{ data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a","b" ], [ "c","d" ] ] ); s.newChainable( "xls" ) .addRows( data ) @@ -47,9 +47,9 @@ describe( "write", function(){ var expected = data; var actual = s.read( src=tempXlsPath, format="query" ); expect( actual ).toBe( expected ); - }); + }) - it( "Writes a streaming XLSX object with a custom window size without error", function(){ + it( "Writes a streaming XLSX object with a custom window size without error", ()=>{ var rows = []; for( i=1; i <= 100; i++ ){ rows.append( { column1=i, column2="test" } ); @@ -61,9 +61,9 @@ describe( "write", function(){ var expected = data; var actual = s.read( src=tempXlsxPath, format="query" ); expect( actual ).toBe( expected ); - }); + }) - it( "Can write an XLSX file encrypted with a password", function(){ + it( "Can write an XLSX file encrypted with a password", ()=>{ var data = QueryNew( "column1", "VarChar", [ [ "secret" ] ] ); var workbook = s.newXlsx(); s.addRows( workbook,data ) @@ -71,35 +71,35 @@ describe( "write", function(){ var expected = data; var actual = s.read( src=tempXlsxPath, format="query", password="pass" ); expect( actual ).toBe( expected ); - }); + }) - describe( "write throws an exception if", function(){ + describe( "write throws an exception if", ()=>{ - it( "the path exists and overwrite is false", function(){ + it( "the path exists and overwrite is false", ()=>{ FileWrite( tempXlsPath, "" ); var workbook = s.new(); - expect( function(){ + expect( ()=>{ s.write( workbook, tempXlsPath, false ); }).toThrow( type="cfsimplicity.spreadsheet.fileAlreadyExists" ); - }); + }) - it( "the password encryption algorithm is not valid", function(){ + it( "the password encryption algorithm is not valid", ()=>{ var data = QueryNew( "column1", "VarChar", [ [ "secret" ] ] ); var workbook = s.newXlsx(); s.addRows( workbook,data ); - expect( function(){ + expect( ()=>{ s.write( workbook=workbook, filepath=tempXlsxPath, overwrite=true, password="pass", algorithm="blah" ); }).toThrow( type="cfsimplicity.spreadsheet.invalidAlgorithm" ); - }); + }) - }); + }) - afterEach( function(){ + afterEach( ()=>{ if( FileExists( variables.tempXlsPath ) ) FileDelete( variables.tempXlsPath ); if( FileExists( variables.tempXlsxPath ) ) FileDelete( variables.tempXlsxPath ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/writeCsv.cfm b/test/specs/writeCsv.cfm index 08a7577..aeba806 100644 --- a/test/specs/writeCsv.cfm +++ b/test/specs/writeCsv.cfm @@ -1,22 +1,22 @@ -describe( "writeCsv", function(){ +describe( "writeCsv", ()=>{ //Note: a trailing newline is always expected when printing from Commons CSV - it( "writeCsv defaults to the EXCEL predefined format", function(){ + it( "writeCsv defaults to the EXCEL predefined format", ()=>{ var object = s.writeCsv(); var format = object.getFormat(); expect( format.equals( format.EXCEL ) ).toBeTrue(); - }); + }) - describe( "writeCsv can write a csv file or return a csv string", function(){ + describe( "writeCsv can write a csv file or return a csv string", ()=>{ - afterEach( function(){ + afterEach( ()=>{ if( FileExists( tempCsvPath ) ) FileDelete( tempCsvPath ); - }); + }) - it( "from an array of arrays", function(){ + it( "from an array of arrays", ()=>{ var data = [ [ "a", "b" ], [ "c", "d" ] ]; var expected = "a,b#newline#c,d#newline#"; var actual = s.writeCsv() @@ -29,9 +29,9 @@ describe( "writeCsv", function(){ .execute(); actual = FileRead( tempCsvPath ); expect( actual ).toBe( expected ); - }); + }) - it( "from an array of structs", function(){ + it( "from an array of structs", ()=>{ var data = [ [ first: "Frumpo", last: "McNugget" ] ]; var expected = "Frumpo,McNugget#newline#"; var actual = s.writeCsv() @@ -44,9 +44,9 @@ describe( "writeCsv", function(){ .execute(); actual = FileRead( tempCsvPath ); expect( actual ).toBe( expected ); - }); + }) - it( "from a query", function(){ + it( "from a query", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var expected = "a,b#newline#c,d#newline#"; var actual = s.writeCsv() @@ -59,11 +59,11 @@ describe( "writeCsv", function(){ .execute(); actual = FileRead( tempCsvPath ); expect( actual ).toBe( expected ); - }); + }) - }); + }) - it( "allows an alternative to the default comma delimiter", function(){ + it( "allows an alternative to the default comma delimiter", ()=>{ var data = [ [ "a", "b" ], [ "c", "d" ] ]; var expected = "a|b#newline#c|d#newline#"; var actual = s.writeCsv() @@ -71,9 +71,9 @@ describe( "writeCsv", function(){ .withDelimiter( "|" ) .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "has special handling when specifying tab as the delimiter", function(){ + it( "has special handling when specifying tab as the delimiter", ()=>{ var data = [ [ "a", "b" ], [ "c", "d" ] ]; var validTabValues = [ "#Chr( 9 )#", "\t", "tab", "TAB" ]; var expected = "a#Chr( 9 )#b#newline#c#Chr( 9 )#d#newline#"; @@ -84,9 +84,9 @@ describe( "writeCsv", function(){ .execute(); expect( actual ).toBe( expected ); } - }); + }) - it( "can use the query columns as the header row", function(){ + it( "can use the query columns as the header row", ()=>{ var data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); var expected = "column1,column2#newline#a,b#newline#c,d#newline#"; var actual = s.writeCsv() @@ -94,9 +94,9 @@ describe( "writeCsv", function(){ .withQueryColumnsAsHeader() .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "can use the row struct keys as the header row", function(){ + it( "can use the row struct keys as the header row", ()=>{ var data = [ [ first: "Frumpo", last: "McNugget" ] ]; var expected = "first,last#newline#Frumpo,McNugget#newline#"; var actual = s.writeCsv() @@ -104,49 +104,49 @@ describe( "writeCsv", function(){ .withStructKeysAsHeader() .execute(); expect( actual ).toBe( expected ); - }); + }) - it( "outputs integers correctly with no decimal point", function(){ + it( "outputs integers correctly with no decimal point", ()=>{ var arrayData = [ [ 123 ] ]; var queryData = QueryNew( "column1", "Integer", arrayData ); var expected = "123#newline#"; expect( s.writeCsv().fromData( arrayData ).execute() ).toBe( expected ); expect( s.writeCsv().fromData( queryData ).execute() ).toBe( expected ); - }); + }) - it( "outputs date objects using the instance's specified DATETIME format", function(){ + it( "outputs date objects using the instance's specified DATETIME format", ()=>{ var nowAsText = DateTimeFormat( Now(), s.getDateFormats().DATETIME ); var arrayData = [ [ ParseDateTime( nowAsText ) ] ]; var queryData = QueryNew( "column1", "Timestamp", arrayData ); var expected = "#nowAsText##newline#"; expect( s.writeCsv().fromData( arrayData ).execute() ).toBe( expected ); expect( s.writeCsv().fromData( queryData ).execute() ).toBe( expected ); - }); + }) - it( "does NOT treat date strings as date objects to be formatted using the DATETIME format", function(){ + it( "does NOT treat date strings as date objects to be formatted using the DATETIME format", ()=>{ var dateString = "2022-12-18"; var data = [ [ dateString ] ]; var expected = '#dateString##newline#'; expect( s.writeCsv().fromData( data ).execute() ).toBe( expected ); - }); + }) - it( "can handle an embedded delimiter", function(){ + it( "can handle an embedded delimiter", ()=>{ var data = [ [ "a,a", "b" ], [ "c", "d" ] ]; var expected = '"a,a",b#newline#c,d#newline#'; expect( s.writeCsv().fromData( data ).execute() ).toBe( expected ); - }); + }) - it( "can handle an embedded double-quote", function(){ + it( "can handle an embedded double-quote", ()=>{ var data = [ [ "a""a", "b" ], [ "c", "d" ] ]; var expected = '"a""a",b#newline#c,d#newline#'; expect( s.writeCsv().fromData( data ).execute() ).toBe( expected ); - }); + }) - it( "can handle an embedded carriage return", function(){ + it( "can handle an embedded carriage return", ()=>{ var data = [ [ "a#newline#a", "b" ], [ "c", "d" ] ]; var expected = '"a#newline#a",b#newline#c,d#newline#'; expect( s.writeCsv().fromData( data ).execute() ).toBe( expected ); - }); + }) it( title="can process rows in parallel if the engine supports it" @@ -165,7 +165,7 @@ describe( "writeCsv", function(){ ,skip=s.getIsACF() ); - it( "allows Commons CSV format options to be applied", function(){ + it( "allows Commons CSV format options to be applied", ()=>{ var path = getTestFilePath( "test.csv" ); var object = s.writeCsv() .withAutoFlush() @@ -220,35 +220,35 @@ describe( "writeCsv", function(){ expect( object.getFormat().getSkipHeaderRecord() ).toBeFalse(); expect( object.getFormat().getTrailingDelimiter() ).toBeFalse(); expect( object.getFormat().getTrim() ).toBeFalse(); - }); + }) - describe( "writeCsv() throws an exception if", function(){ + describe( "writeCsv() throws an exception if", ()=>{ - it( "executed with no data", function(){ - expect( function(){ + it( "executed with no data", ()=>{ + expect( ()=>{ s.writeCsv().execute(); }).toThrow( type="cfsimplicity.spreadsheet.missingDataForCsv" ); - }); + }) - it( "the data is not an array or query", function(){ - expect( function(){ + it( "the data is not an array or query", ()=>{ + expect( ()=>{ var data = "string"; s.writeCsv().fromData( data ).execute(); }).toThrow( type="cfsimplicity.spreadsheet.invalidDataForCsv" ); - }); + }) - it( "the data contains complex values", function(){ - expect( function(){ + it( "the data contains complex values", ()=>{ + expect( ()=>{ var complexValue = []; var data = [ [ complexValue ] ]; s.writeCsv().fromData( data ).execute(); }).toThrow( type="cfsimplicity.spreadsheet.invalidDataForCsv" ); - }); + }) it( title="parallel threads are specified and the engine does not support it" ,body=function(){ - expect( function(){ + expect( ()=>{ s.writeCsv().withParallelThreads(); }).toThrow( type="cfsimplicity.spreadsheet.parallelOptionNotSupported" ); } @@ -257,15 +257,15 @@ describe( "writeCsv", function(){ } ); - it( "the file path specified is VFS", function(){ - expect( function(){ + it( "the file path specified is VFS", ()=>{ + expect( ()=>{ var data = [ [ "a", "b" ], [ "c", "d" ] ]; var path = "ram://temp.csv"; s.writeCsv().fromData( data ).toFile( path ).execute(); }).toThrow( type="cfsimplicity.spreadsheet.vfsNotSupported" ); - }); + }) - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/writeFileFromQuery.cfm b/test/specs/writeFileFromQuery.cfm index 43cfc30..f65d3f3 100644 --- a/test/specs/writeFileFromQuery.cfm +++ b/test/specs/writeFileFromQuery.cfm @@ -1,40 +1,40 @@ -describe( "writeFileFromQuery", function(){ +describe( "writeFileFromQuery", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ Sleep( 5 );// allow time for file operations to complete variables.query = QueryNew( "Header1,Header2","VarChar,VarChar",[ [ "a","b" ],[ "c","d" ] ] ); - }); + }) - it( "Writes a file from a query", function(){ + it( "Writes a file from a query", ()=>{ s.writeFileFromQuery( query, tempXlsPath, true ); var expected = query; var actual = s.read( src=tempXlsPath, format="query", headerRow=1 ); expect( actual ).toBe( expected ); - }); + }) - it( "Writes an XLSX file if extension is .xlsx", function(){ + it( "Writes an XLSX file if extension is .xlsx", ()=>{ var path = tempXlsxPath; s.writeFileFromQuery( query, path, true ); var workbook = s.read( path ); expect( workbook.getClass().name ).toBe( "org.apache.poi.xssf.usermodel.XSSFWorkbook" ); - }); + }) - it( "Writes an XLSX file if extension is .xls but xmlFormat is true", function(){ + it( "Writes an XLSX file if extension is .xls but xmlFormat is true", ()=>{ var convertedPath = tempXlsPath & "x"; s.writeFileFromQuery( data=query, filepath=tempXlsPath, overwrite=true, xmlFormat=true ); var workbook = s.read( convertedPath ); expect( workbook.getClass().name ).toBe( "org.apache.poi.xssf.usermodel.XSSFWorkbook" ); if( FileExists( convertedPath ) ) FileDelete( convertedPath ); - }); + }) - afterEach( function(){ + afterEach( ()=>{ if( FileExists( variables.tempXlsPath ) ) FileDelete( variables.tempXlsPath ); if( FileExists( variables.tempXlsxPath ) ) FileDelete( variables.tempXlsxPath ); - }); + }) -}); +}) \ No newline at end of file diff --git a/test/specs/writeToCsv.cfm b/test/specs/writeToCsv.cfm index 4965852..b1353f5 100644 --- a/test/specs/writeToCsv.cfm +++ b/test/specs/writeToCsv.cfm @@ -1,42 +1,42 @@ -describe( "writeToCsv", function(){ +describe( "writeToCsv", ()=>{ - beforeEach( function(){ + beforeEach( ()=>{ Sleep( 5 );// allow time for file operations to complete var data = [ [ "a", "b" ], [ "c", "d" ] ]; variables.workbooks = [ s.newXls(), s.newXlsx() ]; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRows( wb, data ); - }); - }); + }) + }) - it( "writes a csv file from a spreadsheet object", function(){ + it( "writes a csv file from a spreadsheet object", ()=>{ var expectedCsv = 'a,b#newline#c,d#newline#'; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.writeToCsv( wb, tempCsvPath, true ); expect( FileRead( tempCsvPath ) ).toBe( expectedCsv ); - }); - }); + }) + }) - it( "is chainable", function(){ + it( "is chainable", ()=>{ var expectedCsv = 'a,b#newline#c,d#newline#'; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.newChainable( wb ).writeToCsv( tempCsvPath, true ); expect( FileRead( tempCsvPath ) ).toBe( expectedCsv ); - }); - }); + }) + }) - it( "allows an alternative delimiter", function(){ + it( "allows an alternative delimiter", ()=>{ var expectedCsv = 'a|b#newline#c|d#newline#'; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.writeToCsv( wb, tempCsvPath, true, "|" ); expect( FileRead( tempCsvPath ) ).toBe( expectedCsv ); - }); - }); + }) + }) - it( "allows the sheet's header row to be excluded", function(){ + it( "allows the sheet's header row to be excluded", ()=>{ var expectedCsv = 'a,b#newline#c,d#newline#'; - workbooks.Each( function( wb ){ + workbooks.Each( ( wb )=>{ s.addRow( wb, [ "column1", "column2" ], 1 ) .writeToCsv( workbook=wb, filepath=tempCsvPath, overwrite=true, includeHeaderRow=false ); expect( FileRead( tempCsvPath ) ).toBe( expectedCsv ); @@ -44,26 +44,26 @@ describe( "writeToCsv", function(){ s.shiftRows( wb, 1, 3, 1 ) .writeToCsv( workbook=wb, filepath=tempCsvPath, overwrite=true, includeHeaderRow=false, headerRow=2 ); expect( FileRead( tempCsvPath ) ).toBe( expectedCsv ); - }); - }); + }) + }) - describe( "writeToCsv throws an exception if", function(){ + describe( "writeToCsv throws an exception if", ()=>{ - it( "the path exists and overwrite is false", function(){ + it( "the path exists and overwrite is false", ()=>{ FileWrite( tempCsvPath, "" ); - workbooks.Each( function( wb ){ - expect( function(){ + workbooks.Each( ( wb )=>{ + expect( ()=>{ s.writeToCsv( wb, tempCsvPath, false ); }).toThrow( type="cfsimplicity.spreadsheet.fileAlreadyExists" ); - }); - }); + }) + }) - }); + }) - afterEach( function(){ + afterEach( ()=>{ if( FileExists( tempCsvPath ) ) FileDelete( tempCsvPath ); - }); + }) -}); +}) \ No newline at end of file From e82c79ebcbf949403688524ef8371068e699b3ff Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Mon, 10 Feb 2025 11:52:04 +0000 Subject: [PATCH 04/11] Ensure temp files are deleted post test run --- test/suite.cfc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/suite.cfc b/test/suite.cfc index 520c9f4..470726b 100644 --- a/test/suite.cfc +++ b/test/suite.cfc @@ -30,6 +30,12 @@ component extends="testbox.system.BaseSpec"{ function afterAll(){ WriteDump( var=s.getEnvironment(), label="Environment and settings" ); + if( FileExists( variables.tempXlsPath ) ) + FileDelete( variables.tempXlsPath ); + if( FileExists( variables.tempXlsxPath ) ) + FileDelete( variables.tempXlsxPath ); + if( FileExists( variables.tempCsvPath ) ) + FileDelete( variables.tempCsvPath ); } function run( testResults, testBox ){ From 9d5343e212ec16bc56aa71ecd1288d1ec323e2f1 Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Mon, 10 Feb 2025 15:07:51 +0000 Subject: [PATCH 05/11] Remove unneeded test file operations --- test/specs/readLargeFile.cfm | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/specs/readLargeFile.cfm b/test/specs/readLargeFile.cfm index adb9bb2..8949cf1 100644 --- a/test/specs/readLargeFile.cfm +++ b/test/specs/readLargeFile.cfm @@ -452,11 +452,5 @@ describe( "readLargeFile", ()=>{ }) - afterEach( ()=>{ - if( FileExists( variables.tempXlsxPath ) ) - FileDelete( variables.tempXlsxPath ); - }) - - } -); +}) \ No newline at end of file From f624a3bd8499353fd65c9c03a9164e47c13e1cf2 Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Mon, 10 Feb 2025 15:08:20 +0000 Subject: [PATCH 06/11] Fix typo in test name --- test/specs/readLargeFile.cfm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/specs/readLargeFile.cfm b/test/specs/readLargeFile.cfm index 8949cf1..ccb4191 100644 --- a/test/specs/readLargeFile.cfm +++ b/test/specs/readLargeFile.cfm @@ -18,7 +18,7 @@ describe( "readLargeFile", ()=>{ expect( actual ).toBe( expected ); }) - it( "Reads from the specified sheet name", ()=>{ + it( "Reads from the specified sheet number", ()=>{ var path = getTestFilePath( "large.xlsx" );// has 2 sheets var expected = querySim( "column1,column2 From 36de0548891cce2de6db22983278f62206aff737 Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Mon, 10 Feb 2025 16:05:54 +0000 Subject: [PATCH 07/11] Use engine assigned temp directory for tests --- test/suite.cfc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/suite.cfc b/test/suite.cfc index 470726b..d9d2b6d 100644 --- a/test/suite.cfc +++ b/test/suite.cfc @@ -12,9 +12,9 @@ component extends="testbox.system.BaseSpec"{ s.flushOsgiBundle(); if( server.KeyExists( s.getJavaLoaderName() ) ) server.delete( s.getJavaLoaderName() ); - variables.tempXlsPath = ExpandPath( "temp.xls" ); - variables.tempXlsxPath = ExpandPath( "temp.xlsx" ); - variables.tempCsvPath = ExpandPath( "temp.csv" ); + variables.tempXlsPath = GetTempDirectory() & "temp.xls"; + variables.tempXlsxPath = GetTempDirectory() & "temp.xlsx"; + variables.tempCsvPath = GetTempDirectory() & "temp.csv"; variables.newline = Chr( 13 ) & Chr( 10 ); variables.spreadsheetTypes = [ "xls", "xlsx" ]; } From 634599d108e142e46e8e87937d06b39fd8f3184b Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Tue, 18 Feb 2025 15:09:58 +0000 Subject: [PATCH 08/11] Add processLargeFile() method to process large XLSX files without reading the entire data into memory Fixes #392 --- Spreadsheet.cfc | 4 + helpers/exception.cfc | 9 +- helpers/streamingReader.cfc | 7 +- objects/ProcessLargeFile.cfc | 123 ++++++++++++++++++++++ test/specs/processLargeFile.cfm | 179 ++++++++++++++++++++++++++++++++ 5 files changed, 314 insertions(+), 8 deletions(-) create mode 100644 objects/ProcessLargeFile.cfc create mode 100644 test/specs/processLargeFile.cfm diff --git a/Spreadsheet.cfc b/Spreadsheet.cfc index 31bd276..0ce4e4f 100644 --- a/Spreadsheet.cfc +++ b/Spreadsheet.cfc @@ -1184,6 +1184,10 @@ component accessors="true"{ return new( sheetName=arguments.sheetName, xmlFormat=true ); } + public any function processLargeFile( required string filepath ){ + return New objects.ProcessLargeFile( this, arguments.filepath ); + } + /* row order is not guaranteed if using more than one thread */ public string function queryToCsv( required query query, boolean includeHeaderRow=false, string delimiter=",", numeric threads=0 ){ return writeCsv() diff --git a/helpers/exception.cfc b/helpers/exception.cfc index a54293e..dadb255 100644 --- a/helpers/exception.cfc +++ b/helpers/exception.cfc @@ -22,8 +22,13 @@ component extends="base"{ Throw( type=library().getExceptionType() & ".invalidReadFormat", message="Invalid format", detail="Supported formats are: 'query', 'html' and 'csv'" ); } - void function throwInvalidFileForReadLargeFileException(){ - Throw( type=library().getExceptionType() & ".invalidSpreadsheetType", message="Invalid spreadsheet file", detail="readLargeFile() can only be used with XLSX files. The file you are trying to read does not appear to be an XLSX file." ); + void function throwExceptionIfFileIsInvalidForStreamingReader( required exception ){ + /* + for some reason ACF won't match the exception type as a catch() arg here, i.e. + catch( com.github.pjfanning.xlsx.exceptions.ReadException exception ){} hence using an if-test + */ + if( arguments.exception.type == "com.github.pjfanning.xlsx.exceptions.ReadException" ) + Throw( type=library().getExceptionType() & ".invalidSpreadsheetType", message="Invalid spreadsheet file", detail="readLargeFile() and processLargeFile() can only be used with XLSX files. The file you are trying to read does not appear to be an XLSX file." ); } void function throwNonExistentRowException( required numeric rowNumber ){ diff --git a/helpers/streamingReader.cfc b/helpers/streamingReader.cfc index 38f9285..56f57d2 100644 --- a/helpers/streamingReader.cfc +++ b/helpers/streamingReader.cfc @@ -12,12 +12,7 @@ component extends="base"{ return getSheetHelper().sheetToQuery( argumentCollection=arguments.sheetToQueryArgs ); } catch( any exception ){ - /* - for some reason ACF won't match the exception type as a catch() arg here, i.e. - catch( com.github.pjfanning.xlsx.exceptions.ReadException exception ){} - */ - if( exception.type == "com.github.pjfanning.xlsx.exceptions.ReadException" ) - getExceptionHelper().throwInvalidFileForReadLargeFileException(); + getExceptionHelper().throwExceptionIfFileIsInvalidForStreamingReader( exception ); rethrow; } finally{ diff --git a/objects/ProcessLargeFile.cfc b/objects/ProcessLargeFile.cfc new file mode 100644 index 0000000..02046d2 --- /dev/null +++ b/objects/ProcessLargeFile.cfc @@ -0,0 +1,123 @@ +component accessors="true"{ + + property name="filepath"; + property name="firstRowIsHeader" type="boolean" default="false"; + property name="numberOfRowsToSkip" default=0; + property name="rowProcessor"; + property name="sheetName"; + property name="sheetNumber" default=1; + property name="streamingOptions"; + property name="useVisibleValues" type="boolean" default="false"; + /* Internal */ + property name="library" setter="false"; + + public ProcessLargeFile function init( required spreadsheetLibrary, required string filepath ){ + variables.library = arguments.spreadsheetLibrary; + variables.library.getFileHelper().throwErrorIFfileNotExists( arguments.filepath ); + variables.filepath = arguments.filepath; + variables.streamingOptions = {}; + return this; + } + + /* Public builder API */ + + public ProcessLargeFile function withFirstRowIsHeader( boolean state=true ){ + variables.firstRowIsHeader = arguments.state; + return this; + } + + public ProcessLargeFile function withRowProcessor( required function rowProcessor ){ + variables.rowProcessor = arguments.rowProcessor; + return this; + } + + public ProcessLargeFile function withPassword( required string password ){ + variables.streamingOptions.password = arguments.password; + return this; + } + + public ProcessLargeFile function withSheetName( required string sheetName ){ + variables.sheetName = arguments.sheetName; + return this; + } + + public ProcessLargeFile function withSheetNumber( required numeric sheetNumber ){ + variables.sheetNumber = arguments.sheetNumber; + return this; + } + + public ProcessLargeFile function withSkipFirstRows( required numeric numberOfRowsToSkip ){ + if( !IsValid( "integer", arguments.numberOfRowsToSkip ) || ( arguments.numberOfRowsToSkip < 0 ) ) + Throw( type=variables.library.getExceptionType() & ".invalidArgument", message="Invalid argument to method withSkipFirstRows()", detail="'#arguments.numberOfRowsToSkip#' is not a valid argument to withSkipFirstRows(). Please specify zero or a positive integer" ); + variables.numberOfRowsToSkip = arguments.numberOfRowsToSkip; + return this; + } + + public ProcessLargeFile function withStreamingOptions( required struct options ){ + if( arguments.options.KeyExists( "bufferSize" ) ) + variables.streamingOptions.bufferSize = Val( arguments.options.bufferSize ); + if( arguments.options.KeyExists( "rowCacheSize" ) ) + variables.streamingOptions.rowCacheSize = Val( arguments.options.rowCacheSize ); + return this; + } + + public ProcessLargeFile function withUseVisibleValues( boolean state=true ){ + variables.useVisibleValues = arguments.state; + return this; + } + + // final execution + public ProcessLargeFile function execute(){ + lock name="#getFilepath()#" timeout=5 { + try{ + var file = CreateObject( "java", "java.io.FileInputStream" ).init( getFilepath() ); + var workbook = getLibrary().getStreamingReaderHelper().getBuilder( getStreamingOptions() ).open( file ); + var rowIterator = getSheetToProcess( workbook ).rowIterator(); + var currentRecordNumber = 0; + var headerRowSkipped = false; + var skippedRecords = 0; + var rowProcessor = getRowProcessor() + var rowDataArgs = { + workbook: workbook + }; + if( getUseVisibleValues() ) + rowDataArgs.returnVisibleValues = true; + while( rowIterator.hasNext() ){ + rowDataArgs.row = rowIterator.next(); + if( skipThisRecord( skippedRecords ) ){ + skippedRecords++; + continue; + } + if( getFirstRowIsHeader() && !headerRowSkipped ){ + headerRowSkipped = true; + continue; + } + var data = getLibrary().getRowHelper().getRowData( argumentCollection=rowDataArgs ); + if( !IsNull( rowProcessor ) ) + rowProcessor( data, ++currentRecordNumber ); + } + } + catch( any exception ){ + getLibrary().getExceptionHelper().throwExceptionIfFileIsInvalidForStreamingReader( exception ); + rethrow; + } + finally{ + getLibrary().getFileHelper().closeLocalFileOrStream( local, "file" ); + getLibrary().getFileHelper().closeLocalFileOrStream( local, "workbook" ); + } + } + return this; + } + + /* Private */ + private any function getSheetToProcess( required workbook ){ + if( !IsNull( getSheetName() ) ) + return getLibrary().getSheetHelper().getSheetByName( arguments.workbook, getSheetName() ); + return getLibrary().getSheetHelper().getSheetByNumber( arguments.workbook, getSheetNumber() ); + } + + private boolean function skipThisRecord( required numeric skippedRecords ){ + return variables.numberOfRowsToSkip && ( arguments.skippedRecords < variables.numberOfRowsToSkip ); + } + +} \ No newline at end of file diff --git a/test/specs/processLargeFile.cfm b/test/specs/processLargeFile.cfm new file mode 100644 index 0000000..b759863 --- /dev/null +++ b/test/specs/processLargeFile.cfm @@ -0,0 +1,179 @@ + +describe( "processLargeFile", ()=>{ + + it( "can read and process an xlsx file one row at a time using a passed UDF", ()=>{ + s.newChainable( "xlsx" ).addRows( [ [ 1, 2 ], [ 3, 4 ] ] ).write( tempXlsxPath, true ); + variables.tempTotal = 0; + var sumOfValues = 10; + var processor = ( rowValues )=>{ + rowValues.Each( ( value )=>{ + tempTotal = ( tempTotal + value ); + }) + }; + s.processLargeFile( tempXlsxPath ) + .withRowProcessor( processor ) + .execute(); + expect( tempTotal ).toBe( sumOfValues ); + }) + + it( "passes the current record number to the processor UDF", ()=>{ + s.newChainable( "xlsx" ).addRows( [ [ 1, 2 ], [ 3, 4 ] ] ).write( tempXlsxPath, true ); + var result = []; + var processor = ( rowValues, rowNumber )=> result.Append( rowNumber ); + s.processLargeFile( tempXlsxPath ) + .withRowProcessor( processor ) + .execute(); + var expected = [ 1, 2 ]; + expect( result ).toBe( expected ); + }) + + it( "allows streaming reader tuning options to be set", ()=> { + var options = { + bufferSize: 2048 + ,rowCacheSize: 20 + }; + var processObject = s.processLargeFile( tempXlsxPath ).withStreamingOptions( options ); + expect( processObject.getStreamingOptions() ).toBe( options ); + }) + + it( "can process an encrypted XLSX file", ()=>{ + var path = getTestFilePath( "passworded.xlsx" ); + var result = ""; + var processor = ( rowValues )=> { result = rowValues }; + s.processLargeFile( path ) + .withPassword( "pass" ) + .withRowProcessor( processor ) + .execute(); + var expected = [ "secret" ]; + expect( result ).toBe( expected ); + }) + + it( "processes the specified sheet number", ()=>{ + s.newChainable( "xlsx" ) + .createSheet( "SecondSheet" ) + .setActiveSheet( "SecondSheet" ) + .addRow( [ "test" ] ) + .write( tempXlsxPath, true ); + var result = []; + var processor = ( rowValues )=> { result = rowValues }; + x = s.processLargeFile( tempXlsxPath ) + .withSheetNumber( 2 ) + .withRowProcessor( processor ) + .execute(); + var expected = [ "test" ]; + expect( result ).toBe( expected ); + }) + + it( "processes the specified sheet name", ()=>{ + s.newChainable( "xlsx" ) + .createSheet( "SecondSheet" ) + .setActiveSheet( "SecondSheet" ) + .addRow( [ "test" ] ) + .write( tempXlsxPath, true ); + var result = []; + var processor = ( rowValues )=>{ result = rowValues; }; + s.processLargeFile( tempXlsxPath ) + .withSheetName( "SecondSheet" ) + .withRowProcessor( processor ) + .execute(); + var expected = [ "test" ]; + expect( result ).toBe( expected ); + }) + + it( "can process visible/formatted values rather than raw values", ()=>{ + var rawValue = 0.000011; + var visibleValue = 0.00001; + s.newChainable( "xlsx" ) + .setCellValue( rawValue, 1, 1, "numeric" ) + .formatCell( { dataformat: "0.00000" }, 1, 1 ) + .write( tempXlsxPath, true ); + var result = []; + var processor = ( rowValues )=>{ result = rowValues; }; + s.processLargeFile( tempXlsxPath ) + .withRowProcessor( processor ) + .withUseVisibleValues( true ) + .execute(); + expect( result[ 1 ] ).toBe( visibleValue ); + }) + + it( "can skip the first N rows", ()=> { + s.newChainable( "xlsx" ) + .addRows( [ [ "skip me" ], [ "skip me too" ], [ "data" ] ] ) + .write( tempXlsxPath, true ); + var result = []; + var processor = ( rowValues )=> result.Append( rowValues ); + s.processLargeFile( tempXlsxPath ) + .withRowProcessor( processor ) + .withSkipFirstRows( 2 ) + .execute(); + var expected = [ [ "data" ] ]; + expect( result ).toBe( expected ); + }) + + it( "can ignore the first row if it contains the headers", ()=> { + s.newChainable( "xlsx" ) + .addRows( [ [ "heading" ], [ "data" ] ] ) + .write( tempXlsxPath, true ); + var result = []; + var processor = ( rowValues )=> result.Append( rowValues ); + s.processLargeFile( tempXlsxPath ) + .withRowProcessor( processor ) + .withFirstRowIsHeader() + .execute(); + var expected = [ [ "data" ] ]; + expect( result ).toBe( expected ); + }) + + it( "will treat the first non-skipped row as the header if both options specified", ()=> { + s.newChainable( "xlsx" ) + .addRows( [ [ "skip me" ], [ "header" ], [ "data" ] ] ) + .write( tempXlsxPath, true ); + var result = []; + var processor = ( rowValues )=> result.Append( rowValues ); + s.processLargeFile( tempXlsxPath ) + .withRowProcessor( processor ) + .withFirstRowIsHeader() + .withSkipFirstRows( 1 ) + .execute(); + var expected = [ [ "data" ] ]; + expect( result ).toBe( expected ); + }) + + describe( "processLargeFile throws an exception if", ()=>{ + + it( "the file doesn't exist", ()=>{ + expect( ()=>{ + var path = getTestFilePath( "nonexistent.xls" ); + s.processLargeFile( path ).execute(); + }).toThrow( type="cfsimplicity.spreadsheet.nonExistentFile" ); + }) + + it( "the file to be read is not an XLSX type", ()=>{ + expect( ()=>{ + var path = getTestFilePath( "test.xls" ); + s.processLargeFile( path ).execute(); + }).toThrow( type="cfsimplicity.spreadsheet.invalidSpreadsheetType" ); + }) + + it( "the source file is not a spreadsheet", ()=>{ + expect( ()=>{ + s.processLargeFile( getTestFilePath( "notaspreadsheet.txt" ) ).execute(); + }).toThrow( type="cfsimplicity.spreadsheet.invalidSpreadsheetType" ); + }) + + it( "the sheet name doesn't exist", ()=>{ + expect( ()=>{ + s.processLargeFile( getTestFilePath( "large.xlsx" ) ).withSheetName( "nonexistent" ).execute(); + }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" ); + }) + + it( "the sheet number doesn't exist", ()=>{ + expect( ()=>{ + s.processLargeFile( getTestFilePath( "large.xlsx" ) ).withSheetNumber( 20 ).execute(); + }).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" ); + }) + + }) + +}) + \ No newline at end of file From d97ba5e2b40fdb485d00aad2d2755132d7e7d8a0 Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Wed, 19 Feb 2025 12:02:18 +0000 Subject: [PATCH 09/11] Remove unneeded test file operations --- test/specs/csvToQuery.cfm | 5 ----- test/specs/info.cfm | 7 ------- test/specs/read.cfm | 11 ++--------- test/specs/readCsv.cfm | 5 ----- test/specs/write.cfm | 7 ------- test/specs/writeCsv.cfm | 5 ----- test/specs/writeFileFromQuery.cfm | 7 ------- test/specs/writeToCsv.cfm | 5 ----- 8 files changed, 2 insertions(+), 50 deletions(-) diff --git a/test/specs/csvToQuery.cfm b/test/specs/csvToQuery.cfm index 4de9761..6d40ac2 100644 --- a/test/specs/csvToQuery.cfm +++ b/test/specs/csvToQuery.cfm @@ -133,11 +133,6 @@ describe( "csvToQuery", ()=>{ expect( actual ).toBe( expected ); }) - afterEach( ()=>{ - if( FileExists( tempCsvPath ) ) - FileDelete( tempCsvPath ); - }) - }) describe( "delimiter handling", ()=>{ diff --git a/test/specs/info.cfm b/test/specs/info.cfm index f64d156..92bfaf9 100644 --- a/test/specs/info.cfm +++ b/test/specs/info.cfm @@ -77,12 +77,5 @@ describe( "info", ()=>{ }) }) - afterEach( ()=>{ - if( FileExists( variables.tempXlsPath ) ) - FileDelete( variables.tempXlsPath ); - if( FileExists( variables.tempXlsxPath ) ) - FileDelete( variables.tempXlsxPath ); - }) - }) diff --git a/test/specs/read.cfm b/test/specs/read.cfm index 55a79b5..24c6208 100644 --- a/test/specs/read.cfm +++ b/test/specs/read.cfm @@ -205,7 +205,7 @@ describe( "read", ()=>{ s.newChainable( type ) .addRows( data ) .formatCell( { dataformat: "0.00000" }, 1, 3 ) - .write( path ); + .write( path, true ); var actual = s.read( src=path, format="query", columnNames=columnNames ); expect( actual ).toBe( data ); }) @@ -225,7 +225,7 @@ describe( "read", ()=>{ s.newChainable( type ) .addRows( data ) .formatCell( { dataformat: "0.00000" }, 1, 3 ) - .write( path ); + .write( path, true ); var actual = s.read( src=path, format="query", columnNames=columnNames, returnVisibleValues=true ); expect( actual.numeric ).toBe( numericValue ); expect( actual.zero ).toBe( 0 ); @@ -801,12 +801,5 @@ describe( "read", ()=>{ }) - afterEach( ()=>{ - if( FileExists( variables.tempXlsPath ) ) - FileDelete( variables.tempXlsPath ); - if( FileExists( variables.tempXlsxPath ) ) - FileDelete( variables.tempXlsxPath ); - }) - }) diff --git a/test/specs/readCsv.cfm b/test/specs/readCsv.cfm index 1732e72..3c4dee6 100644 --- a/test/specs/readCsv.cfm +++ b/test/specs/readCsv.cfm @@ -207,11 +207,6 @@ describe( "readCsv", ()=>{ expect( object.getFormat().getTrim() ).toBeFalse(); }) - afterEach( ()=>{ - if( FileExists( tempCsvPath ) ) - FileDelete( tempCsvPath ); - }) - describe( "readCsv() throws an exception if", ()=>{ it( "a zero or positive integer is not passed to withSkipFirstRows()", ()=>{ diff --git a/test/specs/write.cfm b/test/specs/write.cfm index 3b81395..05769db 100644 --- a/test/specs/write.cfm +++ b/test/specs/write.cfm @@ -92,13 +92,6 @@ describe( "write", ()=>{ }).toThrow( type="cfsimplicity.spreadsheet.invalidAlgorithm" ); }) - }) - - afterEach( ()=>{ - if( FileExists( variables.tempXlsPath ) ) - FileDelete( variables.tempXlsPath ); - if( FileExists( variables.tempXlsxPath ) ) - FileDelete( variables.tempXlsxPath ); }) }) diff --git a/test/specs/writeCsv.cfm b/test/specs/writeCsv.cfm index aeba806..ac30412 100644 --- a/test/specs/writeCsv.cfm +++ b/test/specs/writeCsv.cfm @@ -11,11 +11,6 @@ describe( "writeCsv", ()=>{ describe( "writeCsv can write a csv file or return a csv string", ()=>{ - afterEach( ()=>{ - if( FileExists( tempCsvPath ) ) - FileDelete( tempCsvPath ); - }) - it( "from an array of arrays", ()=>{ var data = [ [ "a", "b" ], [ "c", "d" ] ]; var expected = "a,b#newline#c,d#newline#"; diff --git a/test/specs/writeFileFromQuery.cfm b/test/specs/writeFileFromQuery.cfm index f65d3f3..059f78b 100644 --- a/test/specs/writeFileFromQuery.cfm +++ b/test/specs/writeFileFromQuery.cfm @@ -29,12 +29,5 @@ describe( "writeFileFromQuery", ()=>{ FileDelete( convertedPath ); }) - afterEach( ()=>{ - if( FileExists( variables.tempXlsPath ) ) - FileDelete( variables.tempXlsPath ); - if( FileExists( variables.tempXlsxPath ) ) - FileDelete( variables.tempXlsxPath ); - }) - }) \ No newline at end of file diff --git a/test/specs/writeToCsv.cfm b/test/specs/writeToCsv.cfm index b1353f5..186c5f8 100644 --- a/test/specs/writeToCsv.cfm +++ b/test/specs/writeToCsv.cfm @@ -58,11 +58,6 @@ describe( "writeToCsv", ()=>{ }) }) - }) - - afterEach( ()=>{ - if( FileExists( tempCsvPath ) ) - FileDelete( tempCsvPath ); }) }) From ea79e1acdaeeed952ebb14251f139faed210bdbb Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Wed, 19 Feb 2025 12:14:58 +0000 Subject: [PATCH 10/11] Remove unneeded sleep()s from tests --- test/specs/read.cfm | 4 ---- test/specs/write.cfm | 4 ---- test/specs/writeFileFromQuery.cfm | 1 - test/specs/writeToCsv.cfm | 1 - 4 files changed, 10 deletions(-) diff --git a/test/specs/read.cfm b/test/specs/read.cfm index 24c6208..58a0218 100644 --- a/test/specs/read.cfm +++ b/test/specs/read.cfm @@ -1,10 +1,6 @@ describe( "read", ()=>{ - beforeEach( ()=>{ - Sleep( 5 );// allow time for file operations to complete - }) - it( "Can read a traditional XLS file", ()=>{ var path = getTestFilePath( "test.xls" ); var workbook = s.read( src=path ); diff --git a/test/specs/write.cfm b/test/specs/write.cfm index 05769db..5d73450 100644 --- a/test/specs/write.cfm +++ b/test/specs/write.cfm @@ -1,10 +1,6 @@ describe( "write", ()=>{ - beforeEach( ()=>{ - Sleep( 5 );// allow time for file operations to complete - }) - it( "Writes an XLS object correctly", ()=>{ data = QueryNew( "column1,column2", "VarChar,VarChar", [ [ "a","b" ], [ "c","d" ] ] ); var workbook = s.newXls(); diff --git a/test/specs/writeFileFromQuery.cfm b/test/specs/writeFileFromQuery.cfm index 059f78b..f34154c 100644 --- a/test/specs/writeFileFromQuery.cfm +++ b/test/specs/writeFileFromQuery.cfm @@ -2,7 +2,6 @@ describe( "writeFileFromQuery", ()=>{ beforeEach( ()=>{ - Sleep( 5 );// allow time for file operations to complete variables.query = QueryNew( "Header1,Header2","VarChar,VarChar",[ [ "a","b" ],[ "c","d" ] ] ); }) diff --git a/test/specs/writeToCsv.cfm b/test/specs/writeToCsv.cfm index 186c5f8..02d83fd 100644 --- a/test/specs/writeToCsv.cfm +++ b/test/specs/writeToCsv.cfm @@ -2,7 +2,6 @@ describe( "writeToCsv", ()=>{ beforeEach( ()=>{ - Sleep( 5 );// allow time for file operations to complete var data = [ [ "a", "b" ], [ "c", "d" ] ]; variables.workbooks = [ s.newXls(), s.newXlsx() ]; workbooks.Each( ( wb )=>{ From 07a3215f1e14a4a34ca7c221b4fbcc76cf6e5c50 Mon Sep 17 00:00:00 2001 From: cfsimplicity Date: Wed, 19 Feb 2025 12:27:33 +0000 Subject: [PATCH 11/11] v4.5.0 --- CHANGELOG.md | 8 +++++++- ModuleConfig.cfc | 2 +- README.md | 1 + Spreadsheet.cfc | 2 +- box.json | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4faeea2..b3f8054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ +## 4.5.0 - 19 February 2025 + +- Enhancements + - \#392 Add processLargeFile() method to process large XLSX files without reading the entire data into memory + ## 4.4.0 - 8 February 2025 -- \#297 readLargeFile() now works on ACF +- Enhancements + - \#297 readLargeFile() now works on ACF ## 4.3.1 - 29 January 2025 diff --git a/ModuleConfig.cfc b/ModuleConfig.cfc index 24e6ecd..3daaf6e 100644 --- a/ModuleConfig.cfc +++ b/ModuleConfig.cfc @@ -4,7 +4,7 @@ component{ this.author = "Julian Halliwell"; this.webURL = "https://github.com/cfsimplicity/spreadsheet-cfml"; this.description = "CFML Spreadsheet Library"; - this.version = "4.4.0"; + this.version = "4.5.0"; this.autoMapModels = false; function configure(){ diff --git a/README.md b/README.md index 3a49aa9..25aa0c6 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ You may wish to place the spreadsheet library files in a central location with a * [newStreamingXlsx](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/newStreamingXlsx) * [newXls](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/newXls) * [newXlsx](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/newXlsx) +* [processLargeFile](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/processLargeFile) * [queryToCsv](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/queryToCsv) * [readCsv](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/readCsv) * [readLargeFile](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/readLargeFile) diff --git a/Spreadsheet.cfc b/Spreadsheet.cfc index 0ce4e4f..191d7aa 100644 --- a/Spreadsheet.cfc +++ b/Spreadsheet.cfc @@ -1,7 +1,7 @@ component accessors="true"{ //"static" - property name="version" default="4.4.0-develop" setter="false"; + property name="version" default="4.5.0" setter="false"; property name="osgiLibBundleVersion" default="5.4.0.0" setter="false"; //first 3 octets = POI version; increment 4th with other jar updates property name="osgiLibBundleSymbolicName" default="spreadsheet-cfml" setter="false"; property name="exceptionType" default="cfsimplicity.spreadsheet" setter="false"; diff --git a/box.json b/box.json index 36ae20b..271b5b8 100644 --- a/box.json +++ b/box.json @@ -1,7 +1,7 @@ { "name" : "Spreadsheet CFML", "slug" : "spreadsheet-cfml", - "version" : "4.4.0", + "version" : "4.5.0", "shortDescription" : "CFML spreadsheet library", "author" : "Julian Halliwell", "location" : "forgeboxStorage",